Era

Shohag has an integer sequence a1,a2,…,ana1,a2,…,an. He can perform the following operation any number of times (possibly, zero):

  • Select any positive integer kk (it can be different in different operations).
  • Choose any position in the sequence (possibly the beginning or end of the sequence, or in between any two elements) and insert kk into the sequence at this position.
  • This way, the sequence aa changes, and the next operation is performed on this changed sequence.

For example, if a=[3,3,4]a=[3,3,4] and he selects k=2k=2, then after the operation he can obtain one of the sequences [2–,3,3,4][2_,3,3,4], [3,2–,3,4][3,2_,3,4], [3,3,2–,4][3,3,2_,4], or [3,3,4,2–][3,3,4,2_].

Shohag wants this sequence to satisfy the following condition: for each 1≤i≤|a|1≤i≤|a|, ai≤iai≤i. Here, |a||a| denotes the size of aa.

Help him to find the minimum number of operations that he has to perform to achieve this goal. We can show that under the constraints of the problem it's always possible to achieve this goal in a finite number of operations.

Input

The first line contains a single integer tt (1≤t≤2001≤t≤200)  — the number of test cases.

The first line of each test case contains a single integer nn (1≤n≤1001≤n≤100) — the initial length of the sequence.

The second line of each test case contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109) — the elements of the sequence.

Output

For each test case, print a single integer  — the minimum number of operations needed to perform to achieve the goal mentioned in the statement.

Example

input

Copy

4
3
1 3 4
5
1 2 5 7 4
1
1
3
69 6969 696969

output

Copy

1
3
0
696966

Note

In the first test case, we have to perform at least one operation, as a2=3>2a2=3>2. We can perform the operation [1,3,4]→[1,2–,3,4][1,3,4]→[1,2_,3,4] (the newly inserted element is underlined), now the condition is satisfied.

In the second test case, Shohag can perform the following operations:

[1,2,5,7,4]→[1,2,3–,5,7,4]→[1,2,3,4–,5,7,4]→[1,2,3,4,5,3–,7,4][1,2,5,7,4]→[1,2,3_,5,7,4]→[1,2,3,4_,5,7,4]→[1,2,3,4,5,3_,7,4].

In the third test case, the sequence already satisfies the condition.

思路:只需要找出最大值即可,因为:假设最大值在中间时,它后面的值比它小,那就一定满足i了;假设在最后时,在把最大值推到位置时比它小的值那就一定出现过。所以我们只管最大值即可。

#include <iostream>
#include <algorithm>
#include <cstring>
 
using namespace std;
 
 long long int a[110];
 
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        memset(a,0,sizeof a);
        long long int res=0;
        for(int i=1,j=1;i<=n;i++)
        {
            cin>>a[i];
            res=max(res,a[i]-i);
 
        }
        cout<<res<<endl;
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值