You and your friend are playing a game. There is a number of treasure chests hidden under piles of stones. That is, the i-th chest has stones[i] stones piled on top of it. You take turns taking exactly one stone from the top of one of the chests. Whoever takes the last stone from the top of a chest takes the chest and the treasure inside. The inside of the i-th chest is worth treasure[i]. The game objective is to gather as much treasure as possible.
Unfortunately, your friend is a cyborg and always makes the best possible move (maximizing his final win). Given stones and treasure, return the maximum total amount you can get from the chests given that you move first. |