STRATEGY FOR A 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ớ: 256M
Input: stdin
Output: stdout

Nguồn bài:
Hà Minh Ngọc
Dạng bài
Ngôn ngữ cho phép
C, C++, Java, Kotlin, Pascal, PyPy, Python, Scratch

Consider a row of ~N~ coins of values ~V_1 . . . V_n~. We play a game against an opponent by alternating turns. In each turn, a player selects either the first or last coin from the row, removes it from the row permanently, and receives the value of the coin. Determine the maximum possible amount of money we can definitely win if we move first.

Note: The opponent is as clever as the user.

Input

  • The first line contains an integer ~N~ - the number of coins ~(N \leq 10^3)~.
  • In the next line contains ~N~ numbers which are coin values.

    Output

  • Print the maximum amount of money.

Sample Input 1

4
5 3 7 10

Sample Output 1

15

Sample Input 2

4
8 15 3 7

Sample Output 2

22

Bình luận

Hãy đọc nội quy trước khi bình luận.


Không có bình luận tại thời điểm này.