Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Let's note that the only thing that matters is how many stones were removed so we can maintain dp[numberOfRemovedStones]
dp[x] = max(sum of all elements up to y - dp[y]) for all y > x