AtCoder Regular Contest 116
翻译中…
Problem Statement
翻译中…
We have $K$ sequences. The $i$-th sequence $A_i$ has the length of $N_i$.
翻译中…
Takahashi and Aoki will play a game using these. They will alternately do the following operation until the length of every sequence becomes $1$:
翻译中…
- Choose a sequence of length at least
$2$, and delete its first or last element.
翻译中…
Takahashi goes first. Takahashi wants to maximize the sum of the $K$ elements remaining in the end, while Aoki wants to minimize it.
翻译中…
Find the sum of the $K$ elements remaining in the end when both players play optimally.
翻译中…
Constraints
翻译中…
- All values in input are integers.
$1 \leq K \leq 2 \times 10^5$$1 \leq N_i$$\sum_i N_i \leq 2 \times 10^5$$1 \leq A_{i, j} \leq 10^9$
翻译中…
Input
翻译中…
Input is given from Standard Input in the following format:
翻译中…
K
N_1 A_{1, 1} A_{1, 2} \cdots A_{1, N_1}
N_2 A_{2, 1} A_{2, 2} \cdots A_{2, N_2}
\vdots
N_K A_{K, 1} A_{K, 2} \cdots A_{K, N_K}
翻译中…
Output
翻译中…
Print the answer.
翻译中…
样例
Input #1
2
3 1 2 3
2 1 10
Output #1
12
Here is one possible progression of the game:
- Takahashi deletes the first element of $A_2$. Now we have $A_1 = \left(1, 2, 3\right), A_2 = \left(10\right)$.
- Aoki deletes the last element of $A_1$. Now we have $A_1 = \left(1, 2\right), A_2 = \left(10\right)$.
- Takahashi deletes the first element of $A_1$. Now we have $A_1 = \left(2\right), A_2 = \left(10\right)$. The length of every sequence has become $1$, so the game ends.
In this case, the sum of the $K$ elements remaining in the end is $12$. Note that the players may have made suboptimal moves here.
Input #2
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
Output #2
12
题目信息
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。