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

Solution 1 (runtime: 93 ms):
#include <bits/stdc++.h>
 
using namespace std;
 
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#ifdef LOCAL
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...) /*All the isuues which were raised during all the time were quite impressive. what should I tell you now*/
#endif
 
#define ar array
#define ll long long
#define ld long double
#define sza(x) ((int)x.size())
#define all(a) (a).begin(), (a).end()
 
const int MAX_N = 1e5 + 5;
const ll M = 1000000007;
const ll INF = 1e9;
const ld EPS = 1e-9; 
 
vector<ll>primenum;

string struggle = "MenOfCulture";


void SieveOfEratosthenes(int n)
{
    bool prime[n + 1];
    memset(prime, true, sizeof(prime));
 
    for (int p = 2; p * p <= n; p++) {
        // If prime[p] is not changed, then it is a prime
        if (prime[p] == true) {
            for (int i = p * p; i <= n; i += p)
                prime[i] = false;
        }
    }
 
    // Print all prime numbers
    for (int p = 2; p <= n; p++){
        if (prime[p]){
            primenum.push_back(p);
        }
    }
}
 
 
 
bool isPrime(ll n)
{
    // Check from 2 to n-1
    for (ll i = 2; i*i <= n; i++)
        if (n % i == 0)
            return false;
 
    return true;
}
 
long long gcd(long long int a, long long int b) 
{ 
  if (b == 0) 
    return a; 
  return gcd(b, a % b); 
} 
  
// Function to return LCM of two numbers  
long long lcm(int a, int b) 
{ 
    return (a / gcd(a, b)) * b; 
} 
 
 
void solve(){
    ll t;
    cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        ll a[n];
        for(int i = 0 ; i < n ; i++){
            cin>>a[i];
        }

        bool flip = true;
        for(int i = 0 ; i < (n-1) ; i++ ) 
        {
            if(a[i] > a[i+1])
            {
                flip = false;
                break;
            }
            else
            {
                ll temp = a[i];
                a[i+1] -= a[i];
                a[i] = 0;
            }
        }

        if(flip) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}
 
 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int tc = 1;
    vector<int>edit;
    for (int t = 1; t <= tc; t++) {
        solve();
    }
}

Solution 2 (runtime: 328 ms):
//#include <bits/stdc++.h>

//using namespace std;

//

//

//void solve(){

//  int n;

//  cin>>n;

//  vector<int>a(n);

//  for(int i=0;i<n;++i) cin>>a[i];

//  int last=0;

//  int p=0;

//  int ans=1;

//  int gap;

//  while(p<n){

//    if(a[p]>=last){

//      gap=a[p]-last;

//      last=a[p];

//    }

//    else if(a[p]>=gap){

//        last=gap;

//        gap=a[p]-last;

//    }

//    else ans=0;

//    p++;

//  }

//  cout<<(ans?"YES\n":"NO\n");

//}

//int main(){

//  int t;

//  cin>>t;

//  while(t--) solve();

//  return 0;

//}



#include <bits/stdc++.h>

using namespace std;





void solve(){

  int n;

  cin>>n;

  vector<int>a(n);

  for(int i=0;i<n;++i) cin>>a[i];

  int ans=1;

  vector<int>v;

  for(int i=0;i<n;++i){

    if(v.empty()){

      v.push_back(a[i]);

    }

    else if(a[i]>=v.back()){

      int t=a[i]-v.back();

      v.clear();

      v.push_back(t);

//      v.push_back(a[i]);

    }

  else ans=0;

//    else{

//      int tt=v.back()-v.front();

//      if(a[i]>=tt){

//        v.clear();

//        v.push_back(tt);

//        v.push_back(a[i]);

//      }

//      else{

//        ans=0;

//      }

//    }

  }

  cout<<(ans?"YES\n":"NO\n");

}

int main(){

  int t=1;

  cin>>t;

  while(t--) solve();

  return 0;

}