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

Solution 1 (runtime: 374 ms):
#include <bits/stdc++.h>
using namespace std;

int main() {
    int t;
    cin >> t; // Number of test cases
    while (t--) {
        int n;
        cin>>n;
        vector<int>v(n);
        for(int i=0;i<n;i++){
          cin>>v[i];
        }
        
       
          v[1]=v[1]-v[0];
          v[0]=0;
          bool flag = true;
          for(int i=0;i<n-1;i++){
              if(v[i]>v[i+1]){
                cout<<"NO"<<endl;
                flag = false;
                break;
              }
              
              v[i+1]=v[i+1]-v[i];
              v[i]=0;
          }
          
          if(flag) cout<<"YES"<<endl;
        
        
        
        
        
        }
        
        
    
        
    
    return 0;
}


Solution 2 (runtime: 109 ms):
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define MOD 1000000007
#define INF 1e18
#define MAXN 400005
#define ZNF 1e9
#define PI 3.1415926535897932384626

#define pb push_back
#define ppb pop_back
#define mp make_pair
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
 
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define mii map<int, int>
#define si set<int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define umii unordered_map<int, int>
#define usi unordered_set<int>
 
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
 
#define mod(x) ((x) % MOD)
#define inf(x) ((x) == INF ? "INF" : to_string(x))
#define deb(x) cerr << #x << " = " << x << "\n"
 
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 
#define lp(i, a, b) for (int i = a; i < b; i++)
#define rlp(i, a, b) for (int i = b - 1; i >= a; i--)
#define trav(a, x) for (auto &a : x)
 
#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x << " "; _print(x); cerr << "\n";
#else
#define debug(x)
#endif
 
void _print(int t) { cerr << t; }
void _print(string t) { cerr << t; }
void _print(char t) { cerr << t; }
void _print(long double t) { cerr << t; }
void _print(double t) { cerr << t; }
void _print(bool t) { cerr << (t ? "true" : "false"); }
 
template <class T, class V> void _print(pair<T, V> p);
template <class T> void _print(vector<T> v);
template <class T> void _print(set<T> v);
template <class T, class V> void _print(map<T, V> v);
template <class T> void _print(multiset<T> v);
 
template <class T, class V> void _print(pair<T, V> p) {
    cerr << "{"; _print(p.F); cerr << ", "; _print(p.S); cerr << "}";
}
template <class T> void _print(vector<T> v) {
    cerr << "[ "; for (T i : v) { _print(i); cerr << " "; } cerr << "]";
}
template <class T> void _print(set<T> v) {
    cerr << "[ "; for (T i : v) { _print(i); cerr << " "; } cerr << "]";
}
template <class T, class V> void _print(map<T, V> v) {
    cerr << "[ "; for (auto i : v) { _print(i); cerr << " "; } cerr << "]";
}
template <class T> void _print(multiset<T> v) {
    cerr << "[ "; for (T i : v) { _print(i); cerr << " "; } cerr << "]";
}

void solve(){
    int n;
    cin>>n;
    vector<int> 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]){
            int temp=min(a[i],a[i+1]);
            a[i]-=temp;
            a[i+1]-=temp;
        }
        else{
            cout<<"NO"<<endl;
            return;
        }
    }
    cout<<"YES"<<endl;    
}


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

    fast_io;
    
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
    }