Optimal Game Strategy-I

https://hack.codingblocks.com/contests/c/537/428
https://ide.codingblocks.com/s/44588

I am unable to pass the 3rd test case. I can’t find any error in my code.

Hey, your code isn’t giving the max value for every case. Check for this case
input :
4
8 15 3 7
your code’s output : 15
but the correct output should be : 22

what is meant by " Both the players play optimally."
It is given that Piyush has to make move first, then how 22 is possible.

https://hack.codingblocks.com/app/contests/1108/p/428