Codeforces Round 982 (Div. 2)
C
Add Zeros
Codeforces
1500
原题
← BD1 →
翻译中…

You're given an array $a$ initially containing $n$ integers. In one operation, you must do the following:

翻译中…
  • Choose a position $i$ such that $1 \lt i \le |a|$ and $a_i = |a| + 1 - i$, where $|a|$ is the current size of the array.
  • Append $i - 1$ zeros onto the end of $a$.
翻译中…

After performing this operation as many times as you want, what is the maximum possible length of the array $a$?

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 1000$). The description of the test cases follows.

翻译中…

The first line of each test case contains $n$ ($1 \le n \le 3 \cdot 10^5$) — the length of the array $a$.

翻译中…

The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^{12}$).

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.

翻译中…

Output

翻译中…

For each test case, output a single integer — the maximum possible length of $a$ after performing some sequence of operations.

翻译中…

Note

翻译中…

In the first test case, we can first choose $i = 4$, since $a_4 = 5 + 1 - 4 = 2$. After this, the array becomes $[2, 4, 6, 2, 5, 0, 0, 0]$. We can then choose $i = 3$ since $a_3 = 8 + 1 - 3 = 6$. After this, the array becomes $[2, 4, 6, 2, 5, 0, 0, 0, 0, 0]$, which has a length of $10$. It can be shown that no sequence of operations will make the final array longer.

翻译中…

In the second test case, we can choose $i=2$, then $i=3$, then $i=4$. The final array will be $[5, 4, 4, 5, 1, 0, 0, 0, 0, 0, 0]$, with a length of $11$.

翻译中…

样例

Input #1
4
5
2 4 6 2 5
5
5 4 4 5 1
4
6 8 2 3
1
1
Output #1
10
11
10
1
InputCopy OutputCopy
题目信息
题号
2027C
时间限制
3 s
内存限制
256 MB
标签
暴力
数据结构
DFS 及类似
动态规划
图论
贪心

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