CF BUDDY
← Problems·

1491C · Pekora and Trampoline

1700 · brute force, data structures, dp

Problem: There is a trampoline park with nn trampolines in a line. The ii-th of which has strength SiS_i.

Pekora can jump on trampolines in multiple passes. She starts the pass by jumping on any trampoline of her choice.

If at the moment Pekora jumps on trampoline ii, the trampoline will launch her to position i+Sii + S_i, and SiS_i will become equal to max(Si1,1)\max(S_i-1,1). In other words, SiS_i will decrease by 11, except of the case Si=1S_i=1, when SiS_i will remain equal to 11.

If there is no trampoline in position i+Sii + S_i, then this pass is over. Otherwise, Pekora will continue the pass by jumping from the trampoline at position i+Sii + S_i by the same rule as above.

Pekora can't stop jumping during the pass until she lands at the position larger than nn (in which there is no trampoline). Poor Pekora!

Pekora is a naughty rabbit and wants to ruin the trampoline park by reducing all SiS_i to 11. What is the minimum number of passes she needs to reduce all SiS_i to 11?

Input Format: The first line contains a single integer tt (1t5001 \le t \le 500) — the number of test cases.

The first line of each test case contains a single integer nn (1n50001 \leq n \leq 5000) — the number of trampolines.

The second line of each test case contains nn integers S1,S2,,SnS_1, S_2, \dots, S_n (1Si1091 \le S_i \le 10^9), where SiS_i is the strength of the ii-th trampoline.

It's guaranteed that the sum of nn over all test cases doesn't exceed 50005000.

Output Format: For each test case, output a single integer — the minimum number of passes Pekora needs to do to reduce all SiS_i to 11.

Note: For the first test case, here is an optimal series of passes Pekora can take. (The bolded numbers are the positions that Pekora jumps into during these passes.)

  • [1,4,2,2,2,2,2][1,4,\textbf{2},2,\textbf{2},2,\textbf{2}]
  • [1,4,1,2,1,2,1][1,\textbf{4},1,2,1,\textbf{2},1]
  • [1,3,1,2,1,1,1][1,\textbf{3},1,2,\textbf{1},\textbf{1},\textbf{1}]
  • [1,2,1,2,1,1,1][1,\textbf{2},1,\textbf{2},1,\textbf{1},\textbf{1}]

For the second test case, the optimal series of passes is show below.

  • [2,3][\textbf{2},3]
  • [1,3][1,\textbf{3}]
  • [1,2][1,\textbf{2}]

For the third test case, all SiS_i are already equal to 11.

Sample Cases

Case 1

Input

3
7
1 4 2 2 2 2 2
2
2 3
5
1 1 1 1 1

Output

4
3
0

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback