TOWIN - Editorial

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

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;

}


// your code goes here
return 0;

}

help please…

#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");
	}
}

Dont know whats wrong , please help
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
I dont understand which test case i am failing here Please help out

in first chance player1 will choose 2 and player2 will choose 1. Then the answer has to be first. Can u explain your point of view probably i haven’t undestood the question properly

we want to make 1st player win . and there is a condition that in second chance we can take 2 steps . so to make max profit we will let 1st person chose the second chance so that he gets more points and 2nd one take the first. thats the logic