鸭子盈余AI (CI翻译)
Ja the Ghost is playing with rubber ducks again! There are $n$ piles of rubber ducks arranged in a row from left to right. Initially, the $i$-th pile contains $a_i$ rubber ducks.
Ja 幽灵又在玩橡皮鸭了!有 $n$ 堆橡皮鸭,从左到右排成一行。最初,第 $i$ 堆有 $a_i$ 只橡皮鸭。AI (CI翻译)
While the sequence $a$ is not sorted in nondecreasing order, Ja must perform the following operation:
只要序列 $a$ 不是非递减的,Ja 必须执行以下操作:AI (CI翻译)
- Choose two adjacent piles such that the left pile contains more ducks than the right pile. Ja swaps these two piles, and then adds the number of ducks in the new left pile to the new right pile.Formally, choose an index
$i$such that$1\le i \lt n$and$a_i \gt a_{i+1}$. Then replace the adjacent pair$(a_i,a_{i+1})$with$(a_{i+1},a_i+a_{i+1})$.
- 选择两堆相邻的鸭子,且左边一堆的鸭子数量多于右边一堆。Ja 交换这两堆,然后把新的左边一堆中的鸭子数量加到新的右边一堆中。形式化地,选择一个满足
$1\le i \lt n$且$a_i \gt a_{i+1}$的下标$i$,然后将相邻数对$(a_i,a_{i+1})$替换为$(a_{i+1},a_i+a_{i+1})$。
For example, if two adjacent piles contain $7$ and $3$ rubber ducks, then after the operation they contain $3$ and $10$ rubber ducks.
例如,如果两堆相邻的鸭子数量分别为 $7$ 和 $3$,操作后它们的数量将变为 $3$ 和 $10$。AI (CI翻译)
Ja may choose any index satisfying the condition above at each step. It can be shown that, regardless of his choices, the process eventually ends with the sequence sorted in nondecreasing order.
每一步中,Ja 都可以选择任意一个满足上述条件的下标。可以证明,无论他如何选择,最终过程都会以序列按非递减顺序排列而结束。AI (CI翻译)
Ja wants the largest pile at the end of the process to contain as few rubber ducks as possible. Determine the minimum possible value of the largest pile.
Ja 希望过程结束时最大的一堆尽可能少。请确定最大一堆数量的最小可能值。AI (CI翻译)
Input
输入格式
AI (CI翻译)Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.
每个输入包含多组测试用例。第一行包含测试用例数量 $t$($1 \le t \le 10^4$)。接下来是各测试用例的描述。AI (CI翻译)
The first line of each test case contains $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of piles.
每个测试用例的第一行包含一个整数 $n$($1 \le n \le 2 \cdot 10^5$),表示鸭子堆的数量。AI (CI翻译)
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1\le a_i\le 10^9$) — the number of ducks in each pile.
第二行包含 $n$ 个整数 $a_1, a_2, \ldots, a_n$($1\le a_i\le 10^9$),表示每堆鸭子的数量。AI (CI翻译)
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
保证所有测试用例的 $n$ 之和不超过 $2 \cdot 10^5$。AI (CI翻译)
Output
输出格式
AI (CI翻译)For each test case, output a single integer — the minimum possible value of the largest pile.
对于每个测试用例,输出一个整数,表示最大一堆数量的最小可能值。AI (CI翻译)
Note
说明
AI (CI翻译)In the transformations below, the two underlined numbers are the adjacent pair just obtained by the operation.
在下面的变换中,两个带下划线的数字是刚刚通过操作得到的相邻数对。AI (CI翻译)
In the first test case, the sequence is already sorted in nondecreasing order. Therefore Ja does not perform any operation, and the answer is $5$.
在第一个测试用例中,序列已经按非递减顺序排列。因此 Ja 不执行任何操作,答案为 $5$。AI (CI翻译)
In the second test case, Ja has only one possible operation: $$ [7,3]\to [\underline{3},\underline{10}]. $$ The sequence is then sorted, so the answer is $10$.
在第二个测试用例中,Ja 只有一种可能的操作:$$ [7,3]\to [\underline{3},\underline{10}]. $$ 此时序列已经有序,因此答案为 $10$。AI (CI翻译)
In the third test case, Ja can perform the following operations: $$ [3,2,1]\to [\underline{2},\underline{5},1]\to [2,\underline{1},\underline{6}]\to [\underline{1},\underline{3},6]. $$ The largest pile contains $6$ ducks. If Ja first chooses the last two piles instead, the final largest pile would contain $7$ ducks. Therefore the answer is $6$.
在第三个测试用例中,Ja 可以执行以下操作:$$ [3,2,1]\to [\underline{2},\underline{5},1]\to [2,\underline{1},\underline{6}]\to [\underline{1},\underline{3},6]. $$ 最大的一堆有 $6$ 只鸭子。如果 Ja 一开始选择最后两堆,最终最大一堆将有 $7$ 只鸭子。因此答案为 $6$。AI (CI翻译)
In the fourth test case, Ja cannot choose the first two piles at the beginning, because $2$ is not greater than $2$. One possible process is $$ [2,2,1,3,3]\to [2,\underline{1},\underline{3},3,3]\to [\underline{1},\underline{3},3,3,3]. $$ Thus the answer is $3$.
在第四个测试用例中,一开始 Ja 不能选择前两堆,因为 $2$ 并不大于 $2$。一种可能的操作过程为 $$ [2,2,1,3,3]\to [2,\underline{1},\underline{3},3,3]\to [\underline{1},\underline{3},3,3,3]. $$ 因此答案为 $3$。AI (CI翻译)
In the fifth test case, one optimal process is $$ [3,1,4,2]\to [\underline{1},\underline{4},4,2]\to [1,4,\underline{2},\underline{6}]\to [1,\underline{2},\underline{6},6]. $$ Therefore the answer is $6$.
在第五个测试用例中,一种最优操作过程为 $$ [3,1,4,2]\to [\underline{1},\underline{4},4,2]\to [1,4,\underline{2},\underline{6}]\to [1,\underline{2},\underline{6},6]. $$ 因此答案为 $6$。AI (CI翻译)
样例
10
4
1 2 2 5
2
7 3
3
3 2 1
5
2 2 1 3 3
4
3 1 4 2
5
1 4 3 2 5
6
6 2 5 1 4 3
7
2 7 1 6 3 5 4
8
8 1 7 2 6 3 5 4
5
1000000000 999999999 999999998 999999997 999999996
5
10
6
3
6
14
21
26
36
4999999990
题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。