AtCoder Grand Contest 073
B
Cyclic Jump
AtCoder
⌀ 3096
原题
← AC →
翻译中…

Problem Statement

翻译中…

You are given a length-$N$ positive integer sequence $A = (A_1, A_2, \ldots, A_N)$.

翻译中…

You are now standing at coordinate $0$ on the number line, and will perform the following operation any number of times:

翻译中…
  • Choose any element $A_i$ from $A$ freely. Also, choose either positive or negative direction freely. Then, jump distance $A_i$ in the chosen direction.
翻译中…

You are interested in operation sequences that satisfy the following conditions:

翻译中…
  • Perform the operation at least once and finally return to coordinate $0$.
  • Never enter the negative region during the process.
  • Never jump consecutively the same distance in different directions.
翻译中…

The cost of an operation sequence satisfying the conditions is the maximum value among the coordinates visited when moving according to that operation sequence. Find the minimum possible cost among operation sequences satisfying the conditions. Under the constraints of this problem, an operation sequence satisfying the conditions always exists.

翻译中…

Solve $T$ test cases for one input.

翻译中…

Constraints

翻译中…
  • $1 \leq T \leq 125000$
  • $2 \leq N \leq 250000$
  • $1 \leq A_1 < A_2 < \cdots < A_N \leq 10^{18}$
  • The sum of $N$ in one input does not exceed $250000$.
  • All input values are integers.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

T
case_1
case_2
\vdots
case_T

翻译中…

Each test case is given in the following format:

翻译中…

N
A_1 A_2 \cdots A_N

翻译中…

Output

翻译中…

For each test case, output the answer.

翻译中…

样例

Input #1
5
2
2 3
2
3 6
3
3 5 6
2
999999999999999999 1000000000000000000
3
999999999999999998 999999999999999999 1000000000000000000
Output #1
4
6
6
1999999999999999998
1000000000000000000
Consider the first test case. The movement method $0 \to 2 \to 4 \to 1 \to 3 \to 0$ satisfies the conditions, and the cost in this case is $4$. There is no operation sequence with cost less than $4$, so the answer is $4$.
题目信息
题号
agc073_b
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。