WA in TOWIN

I am solving [this] (CodeChef: Practical coding for everyone)
and my code is
#include
#include
#include
#define ll long long int
using namespace std;

int main(){
int t;
cin>>t;
while(t–){
ll P1=0,P2=0,n;
ll a;

bool flag=true;
vector v;
cin>>n;
for (ll i = 0; i < n; i++)
{
cin>>a;
v.push_back(a);

}
sort(v.begin(),v.end());
ll m=v.size()-1;
ll i=0;
while(i<v.size()){
P1+=*max_element(v.begin(),v.end()-(i++));

if(i==v.size())
break;
if(flag){
for(int j=0;j<2;j++)
P2+=*max_element(v.begin(),v.end()-(i++));

flag=false;

}
else{
P2+=*max_element(v.begin(),v.end()-(i++));

}

}

if(P1==P2)
cout<<“draw”<<endl;
else if(P1>P2)
cout<<“first”<<endl;
else
{
cout<<“second”<<endl;
}

}
return 0;
}

can you tell me where my code is failing

1 Like

Your program gives wrong output for n ==1 and n ==2.
Here is the correct code.

1 Like