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

Solution 1 (runtime: 358 ms):
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
typedef long long ll;
ll n,a[N];
void solve(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(int i=1;i<n;i++){
        if(a[i]>a[i+1]){
            cout<<"NO"<<endl;
            return ;
        }
        ll t=min(a[i],a[i+1]);
        a[i]-=t,a[i+1]-=t;
        
    }
    cout<<"YES"<<endl;
    return ;
}

int main(){
    int _;
    cin>>_;
    while(_--){
        solve();
    }
    return 0;
}

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

#include<algorithm>

using namespace std;



typedef long long ll;

typedef double dl;

typedef vector<int> vi;

typedef vector<dl> vd;

typedef vector<ll> vl;

typedef vector<vi> vvi;

typedef vector<vl> vvl;

typedef pair<int,int> pii;

typedef pair<double, double> pdd;

typedef pair<ll, ll> pll;

typedef vector<pii> vii;

typedef vector<pll> vp;





#define rep(i,n) for(int i=0; i<n; i++)

#define pb push_back

#define mpair make_pair

#define F first

#define S second

#define MP make_pair

#define endl '\n'

#define all(a) (a).begin(),(a).end()

#define sz(x) (int)x.size()

#define mid(l,r) ((r+l)/2)

#define left(node) (node*2)

#define right(node) (node*2+1)

#define mx_int_prime 999999937



const double PI = acos(-1);

const double eps = 1e-9;

const int inf = 2000000000;

const ll infLL = 9000000000000000000;

#define MOD 1000000007



#define mem(a,b) memset(a, b, sizeof(a) )

#define gcd(a,b) __gcd(a,b)

#define sqr(a) ((a) * (a))



#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);



typedef vector<int>::iterator vit;

typedef set<int>::iterator sit;





//int dx[] = {0, 0, +1, -1};

//int dy[] = {+1, -1, 0, 0};

//int dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};

//int dy[] = {0, +1, 0, -1, +1, -1, +1, -1};







template < typename F, typename S >

ostream& operator << ( ostream& os, const pair< F, S > & p ) {

            return os << "(" << p.first << ", " << p.second << ")";

}



template < typename T >

ostream &operator << ( ostream & os, const vector< T > &v ) {

            os << "{";

                for(auto it = v.begin(); it != v.end(); ++it) {

                                if( it != v.begin() ) os << ", ";

                                        os << *it;

                                            }

                    return os << "}";

}



template < typename T >

ostream &operator << ( ostream & os, const set< T > &v ) {

            os << "[";

                for(auto it = v.begin(); it != v.end(); ++it) {

                                if( it != v.begin() ) os << ", ";

                                        os << *it;

                                            }

                    return os << "]";

}



template < typename T >

ostream &operator << ( ostream & os, const multiset< T > &v ) {

            os << "[";

                for(auto it = v.begin(); it != v.end(); ++it) {

                                if( it != v.begin() ) os << ", ";

                                        os << *it;

                                            }

                    return os << "]";

}



template < typename F, typename S >

ostream &operator << ( ostream & os, const map< F, S > &v ) {

            os << "[";

                for(auto it = v.begin(); it != v.end(); ++it) {

                                if( it != v.begin() ) os << ", ";

                                        os << it -> first << " = " << it -> second ;

                                            }

                    return os << "]";

}



#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)



void faltu () {

            cerr << endl;

}



template <typename T>

void faltu( T a[], int n ) {

            for(int i = 0; i < n; ++i) cerr << a[i] << ' ';

                cerr << endl;

}



template <typename T, typename ... hello>

void faltu( T arg, const hello &... rest) {

            cerr << arg << ' ';

                faltu(rest...);

}

ll gcd(ll a , ll b){ return __gcd(a,b);}

ll lcm(ll a , ll b){ return a * ( b / __gcd(a,b) ) ; }





int main()

{



    int t; cin>>t;

    while(t--)

    {

        ll n; cin>>n;

        vl v(n);

        for(ll i=0; i<n; i++) cin>>v[i];

        ll flag=1;

        for(ll i=0; i<n-1; i++)

        {

            ll x = min(v[i], v[i+1]);

            v[i] -= x;

            v[i+1] -= x;

            if(v[i]!=0 && v[i+1]==0)

            {

                flag=0;

            }

        }

        if(flag==1)

        {

            cout<<"YES";

        }

        else{

            cout<<"NO";

        }

//        for(ll i=0; i<n; i++) cout<<v[i]<<" ";

        cout<<endl;

    }



}