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

Solution 1 (runtime: 108 ms):
//Burn like amaterasu
//compete 
#include <bits/stdc++.h>
#define ll long long int
#define ld long double 
#define f(i,a,b) for(i=a;i<b;i++)
#define fr(i,a,b) for(i=a;i>=b;i--)
#define sz(x) (ll)x.size()
#define Yes cout<<"YES\n"
#define yes cout<<"Yes\n"
#define No cout<<"NO\n"
#define no cout<<"No\n"
#define vll vector<ll>
#define vi vector<int>
#define pl pair<ll,ll>
#define pi pair<int,int>
#define vpl vector<pair<ll,ll>> 
#define vpi vector<pair<int,int>> 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define srt(v) sort(v.begin(),v.end())
#define rst(v) sort(v.rbegin(),v.rend())
#define rev(v) reverse(v.begin(),v.end())
#define read(v) for(ll xyzd=0;xyzd<v.size();xyzd++)cin>>v[xyzd];
#define print(a)  {for(auto x:a)cout<<x<<" "; cout<<'\n';}
#define printn(a,n) {for(ll i=0;i<n;i++)cout<<a[i]<<" "; cout<<'\n';}
const ll mod=1e9+7;
const ll Mod=998244353;
using namespace std;

//*******************************************************************ordered_set********************************************************************************
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
// operations-> o_set.insert(5); 
// o_set.find_by_order(1)
// o_set.find(2) != o_set.end()
// o_set.erase(o_set.find(2)); 
// *(o_set.find_by_order(1))
//**************************************************************************************************************************************************************
//**********************************************************************G.C.D***********************************************************************************
ll gcd(ll high,ll low)
{
 ll h=high>low?high:low;
 ll l=high>low?low:high;
 ll temp;
while(l!=0)
{
   temp=l;
   l=h%l;
   h=temp;
}
return h;
}
//**************************************************************************************************************************************************************
//**********************************************************************x to the power n (Binpow)***************************************************************
ll binpow(ll x,ll n)
{                   
    ll r=1;
    while(n)
    {
        if(n&1)
        r=r*x;
        x=x*x;
        n>>=1;
    }
    return r; 
}
//**************************************************************************************************************************************************************
//**********************************************************************Fenwick Tree/Binary Indexed Tree********************************************************
template<class T>
class fenwick_tree
{ 
 vector<T> tre;
 public:
 fenwick_tree(T n)
 {
   tre.resize(n+1);
 }
 void add(T index,T value)
 {
    for(;index<=tre.size()-1;index+=(index&(-index)))
    tre[index]+=value;
 }
 T sum_i(T index)
 {
     T ans=0;
     for(;index>0;index-=(index&(-index)))
     ans+=tre[index];
     return ans;
 } 
}; 
//**************************************************************************************************************************************************************
//**********************************************************************SEGEMENT TREE***************************************************************************
class segment_tree{
  public:
    vector<int> seg,val;
    segment_tree(int n){
       val.resize(n);
       seg.resize(4*n+1);
    }
    void build(int ind,int low,int high){
       if(low==high){
         seg[ind]=val[low];
         return;
    }
    int mid =(low+high)/2;
    build(2*ind+1,low,mid);
    build(2*ind+2,mid+1,high);

    seg[ind]=min(seg[2*ind+1],seg[2*ind+2]);
    }
    int query(int ind,int low,int high,int l,int r){
       if(r<low||high<l)return INT_MAX;
       else if(low>=l&&high<=r) return seg[ind];
       
       int mid=(low+high)/2;
       int left=query(2*ind+1,low,mid,l,r);
       int right=query(2*ind+2,mid+1,high,l,r);

       return  min(left,right);
    }
    void update(int ind,int low,int high,int i ,int value){
       if(low==high){
          seg[ind]=value;
          return;
       }
    int mid=(low+high)/2;
    if(i<=mid)update(2*ind+1,low,mid,i,value);
    else update(2*ind+2,mid+1,high,i,value);

    seg[ind]=min(seg[2*ind+1],seg[2*ind+2]);
    }
};
//**************************************************************************************************************************************************************
//**********************************************************************DSU*************************************************************************************
class dsu{
   vector<long long> parent, size;
   public :
   dsu(long long n){ 
         parent.resize(n+1);
         size.resize(n+1);
         long long i;
         for(i=1;i<n+1;i++) parent[i]=i,size[i]=1;
    }
    long long find(long long a){
        if(a==parent[a]) return a;
        return parent[a]=find(parent[a]);
    }
    void union_(long long a, long long b){
         a=find(a), b=find(b);
         if(a==b)return;
         if(size[a]<size[b]) swap(a,b);
         parent[b]=a;
         size[a]+=size[b];
    }
    long long size_(long long a){return size[a];}
  };
//**********************************************************************Solution Begins***************************************************************************
//first check the constraints to determine what complexity is acceptable.
//you always forget to use approach of pivots to calculate anwsers. 
//dont forget the edge cases like when n==1
//always try to prove your solution will work on all cases.
//brute force->implementation->sliding window->
//binary search->math->gready->dynamic programming;

void solve_Func()
{
    ll i, j, k, l, r, q, n, m;
    cin>>n;
    vll a(n); read(a);
    if(n == 1){Yes; return;}
    if(a[0] > a[1]){No; return;}

    a[1] -=a[0];

    f(i,2,n){
        if(a[i] < a[i-1]){
            No;
            return;
        }
        a[i] -= a[i-1];
    }
    Yes;
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // cout<<fixed<<setprecision(9);
    ll t=1;
  
    cin>>t;
    while(t--)
        solve_Func();

}

//*********end*********//

Solution 2 (runtime: 93 ms):
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
#define ys cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define nl cout<<endl
#define fi(i,n) for(int i=0;i<n;i++)
#define fj(j,n) for(int j=0;j<n;j++)
#define fii(i,n) for(int i=1;i<=n;i++)
#define fjj(j,n) for(int j=1;j<=n;j++)
#define fir(i,n) for(int i=n;i>0;i--)
#define fjr(j,n) for(int j=n;j>0;j--)
#define vi vector<int>
#define vii vector<long long>
#define vs vector<string>
#define pi pair<int,int>
#define pii pair<ll,ll>
#define pb push_back
#define pp pop_back

void solve(){
                                                                                                                                                                                               int n;
                                                                                                                                                                                               cin>>n;
                                                                                                                                                                                               vi v(n);
                                                                                                                                                                                               fi(i,n)cin>>v[i];
                                                                                                                                                                                               int c=0;
                                                                                                                                                                                               int i=0;
                                                                                                                                                                                               while(i<n-1){
                                                                                                                                                                                                if(v[i]>v[i+1]){
                                                                                                                                                                                                  c++;
                                                                                                                                                                                                  break;

                                                                                                                                                                                                }
                                                                                                                                                                                                else{
                                                                                                                                                                                                   v[i+1]-=v[i];
                                                                                                                                                                                                   v[i]=0;
                                                                                                                                                                                                                                                                                                                                                                                          }
                                                                                                                                                                                                i++;
                                                                                                                                                                                               }
                                                                                                                                                                                               if(c)no;
                                                                                                                                                                                               else ys;
    



}


 int main() {
   ios::sync_with_stdio(false);
   cin.tie(nullptr);
  ll t;
  //t=1;
  cin>>t;
  while(t--){
    solve();
  }
   return 0;
}