TESTCASE -optimal game strategy-I

i have written this code which is fulfilling 2 cases out of 3
i am not able to figure out what can be the 3rd case .
can you give a look to my code and see where it does fail

check for thus
5
2 4 6 2 5

hello!

though in ques it was mentioned written n is always even …but i bought changes so that it can work for odd n as well … still on submitting it is showing 3rd case:wrong answer.

check for this
6
3 2 4 2 2 3
actually u r using a greedy approach that will not work