# TOWIN - Editorial

Thanks a lot for your help, I could succesfully debug my code.

1 Like

In the for loop starting with i=3 you have incremented cnt1 and cnt2 with 1 … you have to increment both these variables with the vector values like cnt1+=v[i] and cnt2+=v[i]

Thanks …

1 Like

#include
#include <bits/stdc++.h>

using namespace std;

int main() {
int test,n,p1=0,p2=0;
cin>>test;

``````while(test--){
cin>>n;
int a[n];
for(int i=0;i<n;i++)
cin>>a[i];
sort(a, a + n, greater<int>());

for(int i=0;i<n;i++){
if(i==1||i==2)
p2+=a[i];
else if(i==0||i%2!=0)
p1+=a[i];
else
p2+=a[i];

}
if(p1>p2)
cout<<"first"<<endl;
else if(p2==p1)
cout<<"draw"<<endl;
else if(p2>p1)
cout<<"second"<<endl;

}

return 0;
``````

}

``````#include <stdio.h>

void sort(long a[],int n){
int i,j;
long temp;
for(i=0;i<n-1;i++){
for(j=0;j<n-i-1;j++){
if(a[j]<a[j+1]){
temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
}
}
}
}

int main(void) {
int t,i;
int n;
long p1,p2;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
long a[10000];
for(i=0;i<n;i++){
scanf("%ld",&a[i]);
}
sort(a,n);
p1=0;
p2=0;
for(i=0;i<n;i++){
if(i%2!=0){
if(i==1)
p2+=a[i];
else
p1+=a[i];
}
else{
if(i==0)
p1+=a[i];
else
p2+=a[i];
}
}
if(p1>p2)
printf("first\n");
else if(p1==p2)
printf("draw\n");
else
printf("second\n");
}
}
``````

edit- i got it i made silly mistake in the sorting :fp:

hey you didnt checked the n <3
like for input

``````1
2
1 2
``````

the answer should be 2 but you code says 1

https://www.codechef.com/viewsolution/37842826
kindly help I cant understand which test case my code is failing.

https://www.codechef.com/viewsolution/37921105