Dementia "Winning Strategy" problem (TOWIN)

in the question winning startegy…
here is my solution why i am getting tle…
please help me in this

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

?

https://www.codechef.com/viewsolution/36690584
this link to my solution please help me…

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

Consider the test input:

2
1
1000000000
1
1000000000
1 Like

Your solution runs when you remove

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

yes it gonna run i use sublime text thats why i am using for input and output
#ifndef ONLINE_JUDGE
freopen(“input.txt”, “r”, stdin);
freopen(“output.txt”, “w”, stdout);
#endif

and for fast input output
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
these line are use

Your code didn’t run until I removed these lines.

It does if you compile it with the ONLINE_JUDGE macro defined, as the Online Judge used by Codechef does :slight_smile:

3 Likes

after removing the code is running… but the same problem is happening

tle

https://www.codechef.com/viewsolution/36696407
Plzz,anyone help , whats wrong with above solution.

https://www.codechef.com/viewsolution/36697136
check my solution.
Move the (n==1) bit of code after taking input.

see as you have to maximize the sum of numbers that you choose you will always take the maximum element available so we can just sort the array then p1 takes the largest element and p2 takes the two largest elements left in the array then they can take alternatively largest elements left in the array. you count the sum of p1 and p2 if p1 > p2 p1 should go first , if p1 < p2 p1 should go second and if both are equal it will always be a tie either p1 goes first or second.

1 Like

I had WA verdict when I used an array but had AC when I changed it to vector. Strange

1 Like

solution link !

1 Like

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

after line 20 add
if(n == 1){
cout << "first\n";
continue;
}
if(n == 2){
if(a[0] == a[1])
cout << "tie\n";
else
cout << "first\n";
continue;
}

1 Like

Oh wow. Thank you very much. I didn’t realize that.

Thank you

1 Like

Surprisingly enough, without checking for these conditions, I had AC when I used a vector. Probably it didn’t add random values to p2
https://www.codechef.com/viewsolution/36673879