Optimal game strategy


What is the error? My code is correct according to logic

@chiragbaid7,
The error is in the logic, for a players move, you are choosing greedily, the largest value yo pick, but that won’t give you the correct answer, it may be the case that at current move a player pick up a smaller value, but that profits him greatly in long run.
Before solving this, I recommend you to solve Wine problem. I don’t think you understand how and why dp works there.