CodeForces - 1486A 思维

CodeForces - 1486A

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

Note that the number of stacks always remains n: stacks don’t disappear when they have 0 blocks.

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

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

It’s guaranteed that the sum of all n does not exceed 104.

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
6
2
1 2
2
1 0
3
4 4 4
2
0 0
3
0 1 0
4
1000000000 1000000000 1000000000 1000000000
Output
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 0 1.

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 3 4 5.

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 0 0 1. Both 0 1 0 and 0 0 1 are not increasing sequences, so the answer is NO.

题意:可以移动第i处的砖到第i+1处,不计次数,使得数组严格单调增。
思路:因为砖数>=0,所以可以把数组主动构造成0,1,2,3,4……简单方便的进行判断,如果某处i的砖为x,那么它可以分出x-i个砖给i+1处,以此类推,一旦某处砖不够,就说明NO。

#include <bits/stdc++.h>
using namespace std;
#define inf 1e5+10
#define ll long long
const int gm=10010;
ll a[gm];
int main()
{
    int t,n;
    cin>>t;
    while (t--)
    {
        cin>>n;
        for (int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        ll temp=a[0];
        bool flag=1;
        for (int i=1;i<n;i++)
        {
            a[i]+=temp;
            temp=a[i]-i;//“多出的砖”
            //cout<<"i:"<<i<<"temp:"<<temp<<endl;
            if (temp<0){
                flag=0;
                cout<<"NO"<<endl;
                break;
            }
        }
        if (flag)
            cout<<"YES"<<endl;
    }
    system("pause");
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值