Skip to content

Instantly share code, notes, and snippets.

@jaideepheer
Last active May 22, 2019 10:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaideepheer/af7fb223561b8075ebff07dbe16d3bc6 to your computer and use it in GitHub Desktop.
Save jaideepheer/af7fb223561b8075ebff07dbe16d3bc6 to your computer and use it in GitHub Desktop.
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int T;
cin>>T;
while(T--)
{
int N;
cin>>N;
int H[N], V[N];
for(int i=0;i<N;++i)cin>>V[i];
for(int i=0;i<N;++i)cin>>H[i];
// solve
make_heap(H, H+N);
make_heap(V, V+N);
for(int i=N-1;i>=0;--i)
{
pop_heap(H, H+i+1);
pop_heap(V, V+i+1);
//cout<<"Compare, H:"<<H[i]<<", V:"<<V[i]<<endl;
if(H[i]<V[i])
{
cout<<"LOSE"<<endl;
goto mainloop_end;
break;
}
}
cout<<"WIN"<<endl;
mainloop_end:;
}
}
def getSequence(A):
# max sum in array such that no 2 elements are adjacent
incl = 0
excl = 0
prevprev = None
prevIncl = False
ans = []
for i in A:
inclCur = excl + i
exclCur = max(excl, incl)
#print("i:",i, ", inclCur:",inclCur,", exclCur:",exclCur)
if(exclCur>=inclCur):
# exclude current element
#print(i,"excluded")
prevIncl = False
prevprev = None
else:
# include current element
#print(i,"included")
if(incl>excl):
# prev element was included
#print("prev was included, pop")
prevprev_t = ans.pop()
if(prevprev != None):
#print("prevprev was included:",prevprev)
# prevprev was included
ans.append(prevprev)
prevprev = prevprev_t
ans.append(i)
prevIncl = True
# i is now prev element
#print(ans)
excl = exclCur
incl = inclCur
return ans
T=int(input())
while(T>0):
T-=1
n = int(input())
A = [int(t) for t in input().split()]
ans_1 = getSequence(A)[::-1]
ans_2 = getSequence(A[::-1])
ans = ans_1
for i in range(len(ans_1)):
if(ans_1[i]>ans_2[i]):
ans = ans_1
break
elif(ans_2[i]>ans_1[i]):
ans = ans_2
break
print("".join(map(str,ans)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment