CF1491C.Pekora and Trampoline
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There is a trampoline park with n trampolines in a line. The i -th of which has strength Si .
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 i , the trampoline will launch her to position i+Si , and Si will become equal to max(Si−1,1) . In other words, Si will decrease by 1 , except of the case Si=1 , when Si will remain equal to 1 .
If there is no trampoline in position i+Si , then this pass is over. Otherwise, Pekora will continue the pass by jumping from the trampoline at position i+Si by the same rule as above.
Pekora can't stop jumping during the pass until she lands at the position larger than n (in which there is no trampoline). Poor Pekora!
Pekora is a naughty rabbit and wants to ruin the trampoline park by reducing all Si to 1 . What is the minimum number of passes she needs to reduce all Si to 1 ?
输入格式
The first line contains a single integer t ( 1≤t≤500 ) — the number of test cases.
The first line of each test case contains a single integer n ( 1≤n≤5000 ) — the number of trampolines.
The second line of each test case contains n integers S1,S2,…,Sn ( 1≤Si≤109 ), where Si is the strength of the i -th trampoline.
It's guaranteed that the sum of n over all test cases doesn't exceed 5000 .
输出格式
For each test case, output a single integer — the minimum number of passes Pekora needs to do to reduce all Si to 1 .
输入输出样例
输入#1
3 7 1 4 2 2 2 2 2 2 2 3 5 1 1 1 1 1
输出#1
4 3 0
说明/提示
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,1,2,1,2,1]
- [1,3,1,2,1,1,1]
- [1,2,1,2,1,1,1]
For the second test case, the optimal series of passes is show below.
- [2,3]
- [1,3]
- [1,2]
For the third test case, all Si are already equal to 1 .