Problem: 2060D - Subtract Min Sort
Language: c++17 

Solution 1 (runtime: 327 ms):
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=2e5+10;
void solve(){
	int n;
	cin>>n;
	vector<int> a(n+10);
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<n;i++){
		if(a[i]<=a[i+1]){
			a[i+1]-=a[i];
		}else{
			cout<<"NO"<<endl;
			return;
		}
	}
	cout<<"YES"<<endl;
	return;
}
signed main(){
	int T;
	cin>>T;
	while(T--) solve();
	return 0;
}
//快速幂
//#include<bits/stdc++.h> 
//using namespace std;
//#define MOD 1e9+7
//#define int long long
//int a,b;
//int fast(int a,int b,int c){
//	int ans=1;
//	a%=c;
//	while(b){
//		if((b%2)==1){
//			ans=(ans*a)%c;
//		}
//		a=(a*a)%c;
//		b/=2;
//	}
//	return ans;
//} 
//signed main(){
//    cin>>a>>b;
//    cout<<fast(a,b,MOD);
//	
//	return 0;
//} 
// 计算最大公约数
//int gcd(int a,int b){
//	if(a%b==0) return b;
//	else return gcd(b,a%b);
//}
//signed main(){
//	int a,b;
//	cin>>a>>b;
//	cout<<gcd(a,b);
//	
//	return 0;
//}

Solution 2 (runtime: 93 ms):
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file  
#include <ext/pb_ds/tree_policy.hpp>  
#include <functional> // for less 

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef double long dl;
typedef tree<int, null_type, less<int>, rb_tree_tag,  
            tree_order_statistics_node_update>  
    ordered_set;

ll n,k;
string sa,sb;
vector<ll> a,p;
//vector<vector<ll>> ca;
ll mod = 1e9 + 7;
ll fact[200005];

ll powN(ll x, ll y);
ll getNcR(ll n, ll r);
ll ansSparseQuery(vector<vector<ll>>& sparseTable,int l, int r);
vector<vector<ll>> getSparseTable(vector<ll>& arr);
void initFact();
void initArr(vector<ll>& arr, ll n);

map<char,bool> mp;

bool solve()
{
    if(a[0] > a[1]) return false;
    ll x = 0;
    for(int i = 1; i<n; i++){
        ll mn = min(a[i],a[i-1]);
        a[i] -= mn;
        a[i-1] -= mn;
    }
    for(int i = 1; i<n; i++){
        if(a[i] < a[i-1]) return false;
    }
    return true;
} 

int main()
{
    #ifndef ONLINE_JUDGE 
       freopen("input.txt", "r", stdin); 
       freopen("output.txt", "w", stdout); 
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll ts;
    cin>>ts;
    //initFact();
    while(ts--)
    {
        cin>>n;
        initArr(a,n);
        //cin>>sa;
        //initArr(p,n-1);
        //initArr(c,n);
        cout<<(solve() ? "YES\n" : "NO\n");
        
        //cout<<solve()<< "\n";
        //solve();
    }
    
    return 0;
}

void initFact(){
    fact[0] = 1;
    for (int i = 1; i < 200005; i++) {
        fact[i] = (fact[i - 1] * i) % mod;
    }
}

void initArr(vector<ll>& arr, ll n){
    arr.clear();
    arr.resize(n);
    for(int i=0;i<n;i++) cin>>arr[i];
}

ll powN(ll x, ll y){
    ll res = 1;     // Initialize result 
 
    x = x % mod; // Update x if it is more than or 
                // equal to p
  
    if (x == 0) return 0; // In case x is divisible by p;
 
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % mod; 
 
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % mod; 
    } 
    return res; 
}

ll getNcR(ll n, ll r)
{
    if(n < r) return 0;
	return (fact[n] * powN((fact[n - r] * fact[r]) % mod, mod - 2)) % mod;
}

ll ansSparseQuery(vector<vector<ll>>& sparseTable,int l, int r)
{
    int j = log2(r-l+1);

    return __gcd(sparseTable[l][j], sparseTable[r - (1<<j) + 1][j]);
}

vector<vector<ll>> getSparseTable(vector<ll>& arr)
{
    ll n = arr.size();
    if(n == 0) return {{}};
    vector<vector<ll>> sparseTable(n,vector<ll>(log2(n)+1));
    for(int i = 0; i<n; i++){
        sparseTable[i][0] = arr[i];
    }

    for(int j = 1; (1<<j) <= n; j++){
        for(int i = 0; i + (1<<j) <= n; i++){
            sparseTable[i][j] = __gcd(sparseTable[i][j-1],sparseTable[i + (1<<(j-1))][j-1]);
        }
    }
    return sparseTable;
}