ACM----Codeforces Round #703 (Div. 2)A. Shifting Stacks

time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You have nn stacks of blocks. The ii-th stack contains hihi blocks and it's height is the number of blocks in it. In one move you can take a block from the ii-th stack (if there is at least one block) and put it to the i+1i+1-th stack. Can you make the sequence of heights strictly increasing?

Note that the number of stacks always remains nn: stacks don't disappear when they have 00 blocks.

Input

First line contains a single integer t(1t104)(1≤t≤104) — the number of test cases.

The first line of each test case contains a single integer n(1n100)(1≤n≤100). The second line of each test case contains nn integers hihi (0hi109)(0≤hi≤109) — starting heights of the stacks.

It's guaranteed that the sum of all nn does not exceed 104104.

Output

For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise.

You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).

Example
input
Copy
6
2
1 2
2
1 0
3
4 4 4
2
0 0
3
0 1 0
4
1000000000 1000000000 1000000000 1000000000
output
Copy
YES
YES
YES
NO
NO
YES
Note

In the first test case there is no need to make any moves, the sequence of heights is already increasing.

In the second test case we need to move one block from the first stack to the second. Then the heights become 011.

In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights 3455.

In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.

In the fifth test case we can only make one move (from the second to the third stack), which would make the heights 0011. Both 0100 and 0011 are not increasing sequences, so the answer is NO.

题目大意:一共有i堆积木,每次可以从第i堆积木中取出一个放到第i+1堆,问能否实现绝对递增。注意:每堆积木始终存在,即使数量为0.

解题思路:由于不限制操作次数,可以尝试将积木变成0,1,2,3...........数量排序,所以可以从第一堆开始取,分别将每堆多出的积木放到下一堆,最后判定操作是否可行即可。

#include<cstdio>
#include<iostream>
typedef long long ll;
using namespace std;
ll a[200];
int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        for(int i=0;i<n-1;i++){
            if(a[i]!=0&&a[i]>=i){//从头堆开始将多余的块放到下一堆
                ll x=a[i];
                a[i]=i;
                a[i+1]+=(x-i);
            }
        }
        bool flag=1;
        for(int i=0;i<n-1;i++){
            if(a[i]>=a[i+1]){
                flag=0;
            }
        }
        if(flag)printf("YES\n");
        else printf("NO\n");
    }
}

 

 

 

posted @ 2021-02-20 15:02  AA、  阅读(142)  评论(0编辑  收藏  举报