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

Solution 1 (runtime: 328 ms):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
using mp=map<int,int>;
signed main(){
    int t; cin>>t;
    while(t--){
        int n; cin>>n;
        vector<int> v(n);
        int f=1;
        for(int i=0;i<n;i++) cin>>v[i];
        int ref=0;
        for(int i=1;i<n;i++){
            if(v[i-1]>v[i]){
                cout<<"NO\n";
                break;
            }
            else{
                int temp=min(v[i-1],v[i]);
                v[i-1]-=temp; v[i]-=temp;
                ref=i+1;
            }
        }
        if(ref==n) cout<<"YES\n";
    }
    }

Solution 2 (runtime: 359 ms):
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double lld;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key
const ll mod = 1e9+7;
const ll BASE1 = 5689;
const ll BASE2 = 5681;
struct Hash{
    vector<pair<ll,ll>> hashes,Pow;
    Hash(string s){
        hashes.assign(s.size()+1,{0,0});// indexign 1based
        Pow.assign(s.size()+1,{1,1});
        for(int i = 0; i<s.size();i++){
            hashes[i+1] = {(hashes[i].first*BASE1 + (s[i]-'a'+1))%mod,(hashes[i].second*BASE2 + (s[i]-'a'+1))%mod};
            Pow[i+1] = {(Pow[i].first * BASE1)%mod,(Pow[i].second*BASE2)%mod};
        }
    }
    pair<ll,ll>get(int l, int r){
        l++,r++;
        ll hash1 = (hashes[r].first - (hashes[l-1].first*Pow[r-l+1].first)%mod + mod)%mod;
        ll hash2 = (hashes[r].second - (hashes[l-1].second*Pow[r-l+1].second)%mod + mod)%mod;
        return {hash1,hash2};
    }
};
ll modinverse(ll A,ll M){
    ll m0 = M;
    ll y = 0;
    ll x = 1;
    if(M == 1) return 0;
    while(A>1){
        ll q = A/M;
        ll t = M;
        M = A%M, A= t;
        t = y;
        y = x-q*y;
        x = t;
    }
    if(x<0){
        x += m0;
    }
    return x;
}
vector<bool> is_prime;
void sieve(int n){
    is_prime.assign(n,true);
    is_prime[0] = is_prime[1] = false;
    for(int i =2;i*i<= n;i++){
        if(is_prime[i]){
            for(int j = i*i;j<= n;j+=i){
                is_prime[j] =false;
            }
        }
    }
}
lld ncr(ll n,ll r){
    lld numo = 1.0;
    lld deno = 1.0;
    lld ans = 1.0;
    if(r>n) return 0.0;
    if(r == 0) return 1;
    for(int i = 0; i<r;i++){
        numo = n-i;
        deno = i+1;
        ans *=(numo/deno);
    }
    return ans;
}
// const long long INF = 1LL << 32;
/*---------------------------------------------------------------------------------------------------------------------------------------------------------*/
// testcase achese analyse

void solve(){
    ll n;
    cin>>n;
    vector<ll> a(n);
    for(int i = 0; i<n;i++){
        cin>>a[i];
    }
    for(int i = 0; i<n-1;i++){
        if(a[i] > a[i+1]){
            cout<<"NO"<<endl;
            return;
        }
        else{
            ll temp = min( a[i],a[i+1]);
            a[i] -= temp;
            a[i+1] -= temp;
        }
    }
    cout<<"YES"<<endl;
}
int main() {
    int t;
    cin>>t;
    while(t--){
        solve();
    }
}