Shifting Stacks (递增思想特例化)

time limit per test1 second
memory limit per test256 megabytes

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

题目分析我们可以知道0,1,2.……n是最小的递增整数,所以我们可以判断用数列的和比较。

具体操作看代码。

听懂了记得给个赞鼓励一下,码字不易,用爱发电。

上ac代码。

 我的头像

 有事你就q我;QQ2917366383

学习算法

 

	#include<iostream>
	using namespace std;
	int n,b;
	
	int main()
	{
		int a[150000];
		int t;
		cin>>t;
		while(t--)
		{
		    long long sum1,sum2;
			b=sum1=sum2=0;
			cin>>n;
			for(int i=1;i<=n;i++) 
			cin>>a[i];
			for(int i=1;i<=n;i++)
			{
				sum1+=a[i];
				sum2+=(i-1);//0,到i-1的和 
				if(sum1<sum2)
				{
				cout<<"NO"<<endl;
					b=1;
					break;
				}
			}
			if(!b)
			cout<<"YES"<<endl;
		}
	}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

算法编程张老师

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值