Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#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 = 2; i<n; i++){
        if(a[i] < a[i-1]){
            a[i-1] -= min(a[i-2],a[i-1]);
            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;
}

Submission (verdict: Accepted):
#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;
}