Removal Game CSES DP Problem

Hi, could someone please explain how to solve this problem ?
Thanks in Advance !!

Removal Game

Let A_i denote the value of the ith number. Let dp_{i,j} denote the difference between the score of the first player and the second player S_{p1} - S_{p2} if they play the game between the indices i and j. Notice that
dp_{i,j} = max(A_j - dp_{i,j-1}, A_i - dp_{i+1,j}). You can choose A_i or A_j, and the negative sign is because player one becomes player two.

1 Like