CodeForces - Problem 1442 A - Extreme Subtraction - DP
这是一道构造题,之前没练过构造.思路是贪心,DP
#include <bits/stdc++.h>
using namespace std;
int n,t;
int v[30000+4];
int a[30000+4],b[30000+4];
int main(){
scanf("%d",&t);
while(t--){
int flag = 1;
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",&v[i]);
}
a[1]=v[1],b[1]=0;
for(int i=2;i<=n;i++){
a[i]=min(a[i-1],v[i]-b[i-1]);
b[i]=v[i]-a[i];
if(b[i]<0||b[i]>v[i]){
flag=0;
break;
}
}
if(flag){
puts("YES");
}else{
puts("NO");
}
}
system("pause");
return 0;
}