Codeforces1486 A Shifting Stacks (开long long)

简介: Codeforces1486 A Shifting Stacks (开long long)

原题链接

思路:

一觉醒来红了个题,一看发现没开ll,我大意了啊。

构造出0,1,2……的序列就行,如果少的话看前面多的能不能补上。

代码:

#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;typedef unsigned long long ull;
typedef pair<ll,ll>PLL;typedef pair<int,int>PII;typedef pair<double,double>PDD;
#define I_int ll
inline ll read(){ll x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;}
#define read read()
#define closeSync ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define multiCase int T;cin>>T;for(int t=1;t<=T;t++)
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define repp(i,a,b) for(int i=(a);i<(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define perr(i,a,b) for(int i=(a);i>(b);i--)
ll ksm(ll a,ll b,ll p){ll res=1;while(b){if(b&1)res=res*a%p;a=a*a%p;b>>=1;}return res;}
const int maxn=1e6+7;
ll a[maxn],n;
void solve(){
    n=read;
    rep(i,1,n) a[i]=read;
    ll las=-1,sum=0;
    rep(i,1,n){
        las++;
        if(a[i]>=las){
            sum+=a[i]-las;
        }
        else{
            int t=las-a[i];
            if(sum>=t) sum-=t;
            else{
                puts("NO");
                return ;
            }
        }
    }
    puts("YES");
}
int main(){
  int T=read;
  while(T--) solve();
  return 0;
}
目录
相关文章
|
1月前
|
C++
【PTA】​ L1-044 稳赢​ (C++)
【PTA】​ L1-044 稳赢​ (C++)
46 0
【PTA】​ L1-044 稳赢​ (C++)
|
1月前
|
C++
【PTA】​到底有多二​ (C++)
【PTA】​到底有多二​ (C++)
59 0
【PTA】​到底有多二​ (C++)
|
10月前
|
测试技术
PTA1002 写出这个数
PTA1002 写出这个数
40 0
|
测试技术
PTA 1002 写出这个数
读入一个正整数 n,计算其各位数字之和,用汉语拼音写出和的每一位数字。
75 0
|
Java 测试技术
杭电1024 Max Sum Plus Plus状压dp(java)
现在我认为你已经在Ignatius.L的“最大总和”问题中得到了AC。为了成为一名勇敢的ACMer,我们总是向更难挑战的问题挑战自我。现在你面临着一个更困难的问题。
115 0