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

传送门
在这里插入图片描述

思路:

能满足条件的最低限度为{0,1,2,3,…,n}这种序列,因此我们只需要将给出的序列构造成这种序列就行。

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int mod = 1e9 + 7;
ll a[110];
int main()
{
    
    
	int t;
	scanf("%d",&t);
	while(t--)
	{
    
    
		int n;
		scanf("%d",&n);
		ll sum = 0,ans = 0;
		for(ll i = 0; i < n; i++)
		{
    
    
			scanf("%lld",&a[i]);
		}
		int flag = 0;
		for(int i = 0; i < n; i++)
		{
    
    
			if(a[i] >= i)
			{
    
    
				a[i + 1] += a[i] - i;
			}
			else
			{
    
    
				printf("no\n");
				flag = 1;
				break;
			}
		}
		if(flag == 1)
		{
    
    
			continue;
		}
		else
		printf("yes\n");
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/p15008340649/article/details/114155787
今日推荐