dp
to the last value of the prefix sum array, which represents the score difference if the game starts with only the last stone.dp
to be the maximum of the current dp
and the difference between the current prefix sum and dp
.dp
after the loop is the answer to the problem.