《Codeforces Round #681 (Div. 2, based on VK Cup 2019-2020 - Final)》
阿新 • • 發佈:2020-11-14
D:沒想到這個看起來簡單的題能卡我這麼久。
#include<bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<LL,int> pii; const int N = 2e5+5; const int M = 1e6+5; const LL Mod = 998244353; #define pi acos(-1) #define INF 1e18 #define CT0 cin.tie(0),cout.tie(0) #define IO ios::sync_with_stdio(false) #defineView Codedbg(ax) cout << "now this num is " << ax << endl; namespace FASTIO{ inline LL read(){ LL x = 0,f = 1;char c = getchar(); while(c < '0' || c > '9'){if(c == '-') f = -1;c = getchar();} while(c >= '0' && c <= '9'){x = (x<<1)+(x<<3)+(c^48);c = getchar();} return x*f; } } using namespace FASTIO; int a[N]; int main() { int ca;ca = read(); while(ca--) { int n;n = read(); for(int i = 1;i <= n;++i) a[i] = read(); int f = 0,used = 0,pre = a[1]; for(int i = 1;i <= n;++i){ a[i]-= used; if(a[i] < 0){f = 1;break;} if(a[i] > pre) used += a[i] - pre; pre = min(pre,a[i]); } printf("%s\n",f ? "NO" : "YES"); } system("pause"); return 0; }