思路:对每个点尽量从左边减,算从右边最少的减的次数,如果这个次数超过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;
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;
}