atcoder#ARC116F. [ARC116F] Deque Game
[ARC116F] Deque Game
Score : points
Problem Statement
We have sequences. The -th sequence has the length of .
Takahashi and Aoki will play a game using these. They will alternately do the following operation until the length of every sequence becomes :
- Choose a sequence of length at least , and delete its first or last element.
Takahashi goes first. Takahashi wants to maximize the sum of the elements remaining in the end, while Aoki wants to minimize it.
Find the sum of the elements remaining in the end when both players play optimally.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
2
3 1 2 3
2 1 10
12
Here is one possible progression of the game:
- Takahashi deletes the first element of . Now we have .
- Aoki deletes the last element of . Now we have .
- Takahashi deletes the first element of . Now we have . The length of every sequence has become , so the game ends.
In this case, the sum of the elements remaining in the end is . Note that the players may have made suboptimal moves here.
8
1 2
2 1 2
3 1 2 1
4 1 1 1 2
5 1 1 2 2 1
6 2 2 2 2 1 1
7 1 2 1 1 2 2 2
8 2 2 2 1 1 1 1 2
12