why my code is giving wrong answer can any1 pls explain
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.
instead of (k[i]>0) you have to check if (k[i]%2>0) and also the output formatting.
Got it but still am unable to understand the need for doing k[i]%2 operation pls help me with it …
suppose k=2,k=1,k=1, rest are zero.
when you come to k you will add 4 to max1
then on coming to k you will add 3 to max2
then on coming to k you will add 1 to max1
but since k 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 would have been 3 then one of them would have got one more value than the other
in this case if k=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
@qwerty1 got it thanx for the effort