6740.Removal Game

Time Limit: 1s Memory Limit: 512MB

There is a list of $n$ numbers and two players who move alternately. On each move, a player removes either the first or last number from the list, and their score increases by that number. Both players try to maximize their scores.

What is the maximum possible score for the first player when both players play optimally?

Input Format(From the terminal/stdin)

The first input line contains an integer $n$ : the size of the list.

The next line has $n$ integers $x_1,x_2,\ldots,x_n$ : the contents of the list.

  • $1 \le n \le 5000$
  • $-10^9 \le x_i \le 10^9$

Output Format(To the terminal/stdout)

Print the maximum possible score for the first player.

Sample Input

Copy
4
4 5 1 3
 \n
 · · · \n

Sample Output

Copy
8
 \n
Source: CSES, Dynamic Programming, 1097

Submit

请先 登录

© 2025 FAQs