Need help in dementia question Wining strategy

i have written the code in java but logic is readable. can someone provide test case or otherwise tell how is the solution wrong.
https://www.codechef.com/viewsolution/36681809.

You need to sort it in non-increasing order. Then, select the maximum for each move.
My code

1 Like

simply convert your a[i] array to desecnding order and try

1 Like

Ok , I have tried the same thing, sort it(descending), add first element to score1, second and third to score2 and then loop through rest of the array alternating between both scores. But I got WA!

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

Can you help!!!

why is sorting needed?

The optimal choice to maximize the score is to choose the maximum possible element in each move.
After sorting, only thing left is to pick elements and add them.

1 Like

put a seperate if for n=1,2

1 Like

I was stuck at this too, re read the question they can pick numbers in ANY order, so the best no. to pick is highest one.

1 Like