Codeforces Round #681 (Div. 2, based on VK Cup 2019-2020 - Final) D - Extreme Subtraction

思路:对每个点尽量从左边减,算从右边最少的减的次数,如果这个次数超过a[i]则非法

	#include<bits/stdc++.h>
	#define pb push_back
	#define mp make_pair
	#define fi first
	#define se second
	#define p_q priority_queue
	#define all(x) (x).begin(),(x).end()
	#define rall(x) (x).rbegin(),(x).rend()
	#define inf 0x3f3f3f3f
	const int  mod =1e9+7;
	const int p_mod=998244353;
	#define forn(i,n) for(int (i)=1;(i)<=(n);(i)++)
	#define forn0(i,n) for(int (i)=0;(i)<(n);(i)++)
	#define vii vector<pair<int ,int >>
	#define vi vector<int> 
	#define pii pair<int,int>
	#define DBG 0
	#define debug(x) cout<<#x<<" is "<<x<<endl
	#define pw(x) (1LL<<(x))
	#define lc(x) (x<<1)
	#define rc(x) ((x<<1)|1)
	typedef long long ll;
	typedef unsigned long long ull;
	using namespace std;
	/*1.be able to use template [Multiset] skillful
	function	parameter is double type:ceil() floor() 
	__gcd() */ 
	ll fast_pow(ll a,ll b){
		ll res=1;
		while(b){
			if(b&1)res=(res*a)%mod;
			b>>=1;
			a=(a*a)%mod;
		}
		return res%mod;
	}
	const int N=3e5+5;
	int root[N],n; 
	void make_set(){for(int i=1;i<=n;i++)root[i]=i;}
	int find_set(int x){return root[x]==x?root[x]:root[x]=find_set(root[x]);}
	bool union_set(int x,int y){
		x=find_set(x);
		y=find_set(y);
		if(x==y)return false;
		return root[y]=root[x];
	}
	void fail(bool flag){if(flag){puts("NO");exit(0);}else cout<<"YES"<<endl;}
	ll a[N];
	ll L[N],R[N];
	const int INF = 0x3f3f3f3f;
	int main(){
		std::ios::sync_with_stdio(false);
	    std::cin.tie(0);
	#if DBG
	    freopen("input.txt","r",stdin);
	#endif
		int t;
		cin>>t;
		for(int j = 1;j <= t;j++){
			cin>>n;
			for(int i = 1;i <= n;i++)cin>>a[i];
			int premin = a[1],minus = 0;
			bool f = true;
			for(int i = 2;i <= n;i++){
				a[i] -= minus;
				
				if(a[i] > premin){
					minus += a[i] - premin;
				}else premin = a[i];
				if(a[i] < 0){
					f = false;
					break;
				}
			}
			if(f)
				cout<<"YES"<<endl;
			else
				cout<<"NO"<<endl;
		}
	    
		return 0;
	}
	
	

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值