team split WA

why my code is giving wrong answer can any1 pls explain

http://www.codechef.com/viewsolution/3620191

You are printing the output of all the test cases in the same line.
Use “%lld\n” instead of “%lld”.
Also you need to initialize the K array you are using for every test case instead of just initializing it once in the beginning.

1 Like

instead of (k[i]>0) you have to check if (k[i]%2>0) and also the output formatting.

2 Likes

Got it but still am unable to understand the need for doing k[i]%2 operation pls help me with it …

suppose k[1]=2,k[3]=1,k[4]=1, rest are zero.
when you come to k[4] you will add 4 to max1
then on coming to k[3] you will add 3 to max2
then on coming to k[1] you will add 1 to max1
but since k[1] has 2 values one will go to max1 and the other will go to max2 hence they will cancel out each other.
but if k[1] would have been 3 then one of them would have got one more value than the other
in this case if k[1]=3 then
first max1 will get 1 then max2 will get 1 then again max1 will get 1
they both neutralize each other so max1 is left with an extra 1

1 Like

@qwerty1 got it thanx for the effort :slight_smile: