#P14788. [NERC 2025] Greta' s Game
[NERC 2025] Greta' s Game
题目描述
Greta and Alice are the two permanent hosts of the hit comedy show “QuestExpert”. For this season they invited programmers to complete quests, set by Alice. After that they all meet in a studio to review how well they did and complete the final studio quest.
Today, the studio quest that Alice came up with is as follows: first, all participants stand in a circle in order from 1 to counter-clockwise. Then Alice holds some number of rounds. In each round, every participant writes down an integer on a piece of paper. After that, Alice checks the numbers and for each from 1 to , if the -th participant’s number is strictly larger than the number of the next participant in counter-clockwise order (participant number ), then the -th and the -st participants both receive one point. After all rounds are complete, Alice calculates the total number of points for each participant and reports them to Greta. It turned out that the -th participant scored points.
Greta thinks that math games are boring, and this one took too long. To prove her wrong, Alice decides to cheat a little and instead of telling Greta the real number of rounds, she will tell her the minimum possible number of rounds that could still result in the -th participant scoring points for each .
Help Alice determine this number.
输入格式
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line of each test case contains a single integer , denoting the number of participants ().
The second line contains integers , denoting the final scores of the participants (). It is guaranteed that those scores were achieved in the described game with at least one round.
It is guaranteed that the sum of over all test cases does not exceed .
输出格式
For each test case, output on a separate line the minimum number of rounds that could lead to the given scores.
5
2
3 3
3
2 2 2
4
1 2 4 3
5
0 2 3 5 4
6
5 8 3 10 14 4
3
2
2
4
10