CSES - Removal Game
Xem dạng PDF
Gửi bài giải
Điểm:
1,00 (OI)
Giới hạn thời gian:
1.0s
Giới hạn bộ nhớ:
512M
Input:
stdin
Output:
stdout
Nguồn bài:
Dạng bài
Ngôn ngữ cho phép
C, C++, Java, Kotlin, Pascal, PyPy, Python, Scratch
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
- 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.
Output
- Print the maximum possible score for the first player.
Constraints
- ~1 \le n \le 5000~
- ~-10^9 \le x\_i \le 10^9~
Example Input
4
4 5 1 3
Example Output
8
Bình luận