EPIC Institute of Technology Round Summer 2024 (Div. 1 + Div. 2)
C
Basil's Garden
Codeforces
1200
原题
← BD →
翻译中…

There are $n$ flowers in a row, the $i$-th of them initially has a positive height of $h_i$ meters.

翻译中…

Every second, the wind will blow from the left, causing the height of some flowers to decrease.

翻译中…

Specifically, every second, for each $i$ from $1$ to $n$, in this order, the following happens:

翻译中…
  • If $i = n$ or $h_i \gt h_{i + 1}$, the value of $h_i$ changes to $\max(0, h_i - 1)$.
翻译中…

How many seconds will pass before $h_i=0$ for all $1 \le i \le n$ for the first time?

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line of input contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases. The description of the test cases follows.

翻译中…

The first line of each test case contains a single integer $n$ ($1 \le n \le 10^5$) — the number of flowers.

翻译中…

The second line of each test case contains $n$ integers $h_1, h_2, \ldots, h_n$ ($1 \le h_i \le 10 ^ 9$) — the heights of the flowers.

翻译中…

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

翻译中…

Output

翻译中…

For each test case, output a single integer — the number of seconds that will pass before $h_i=0$ for all $1 \le i \le n$.

翻译中…

Note

翻译中…

In the first test case, the flower heights change as follows: $[1, 1, 2] \rightarrow [1, 1, 1] \rightarrow [1, 1, 0] \rightarrow [1, 0, 0] \rightarrow [0, 0, 0]$.

翻译中…

In the second test case, the flower heights change as follows: $[3, 1] \rightarrow [2, 0] \rightarrow [1, 0] \rightarrow [0, 0]$.

翻译中…

样例

Input #1
4
3
1 1 2
2
3 1
1
9
5
7 4 4 3 2
Output #1
4
3
9
7
InputCopy OutputCopy
题目信息
题号
1987C
时间限制
2 s
内存限制
256 MB
标签
动态规划
贪心

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