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

Solution 1 (runtime: 358 ms):
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

void solve(){
    int n;
    cin >> n;
    vector<int>v(n);
    for(auto &x : v) cin >> x;
    if(is_sorted(v.begin(),v.end())){
        cout << "YES\n";
        return;
    }
    for(int i =0;i<n-1;i++){
        int mini = min(v[i],v[i+1]);
        if(v[i]<=v[i+1]){
            v[i]-=mini;
            v[i+1]-=mini;
        }
    }
    if(is_sorted(v.begin(), v.end())) cout << "YES\n";
    else cout << "NO\n";
}

int main(){
    int t;
    cin >> t;
    while(t--){
        solve();
    }
}

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

using namespace std;



#define Gremlin ios_base::sync_with_stdio(false); cin.tie(0);

#define OwL cout.tie(0);

#define endl "\n"

#define ll long long

#define ld long double

#define pb push_back

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

#define py cout<<"YES"<<endl

#define pn cout<<"NO"<<endl

#define watch(x) cout << #x << " = " << x << endl;



const double pie = 2*acos(0) ;

const int mod = 1e9+7 ;

const double eps = 1e-9;



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

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



/// longest common substring in two strings

/// here m and n size of x and size of y



string LCS(string X, string Y, int m, int n)

{

    int maxlen = 0;         // stores the max length of LCS

    int endingIndex = m;    // stores the ending index of LCS in `X`



    // `lookup[i][j]` stores the length of LCS of substring `X[0??-1]`, `Y[0??-1]`

    int lookup[m + 1][n + 1];



    // initialize all cells of the lookup table to 0

    memset(lookup, 0, sizeof(lookup));



    // fill the lookup table in a bottom-up manner

    for (int i = 1; i <= m; i++)

    {

        for (int j = 1; j <= n; j++)

        {

            // if the current character of `X` and `Y` matches

            if (X[i - 1] == Y[j - 1])

            {

                lookup[i][j] = lookup[i - 1][j - 1] + 1;



                // update the maximum length and ending index

                if (lookup[i][j] > maxlen)

                {

                    maxlen = lookup[i][j];

                    endingIndex = i;

                }

            }

        }

    }



    // return longest common substring having length `maxlen`

    return X.substr(endingIndex - maxlen, maxlen);

}





/// write it in the main function  =>





/** Dynamic programming to find the longest common subsequence (LCS)



    vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));



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

        for (int j = 1; j <= m; ++j) {

            if (a[i - 1] == b[j - 1]) {

                dp[i][j] = dp[i - 1][j - 1] + 1;

            } else {

                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);

            }

        }

    }



    int lcs_length = dp[n][m];

    int min_length = n + m - lcs_length;





    here is the full code    **/





bool cmp (const pair < ll , ll > &p , const pair < ll , ll > &q )

{

    if(p.first == q.first) return p.second > q.second ;



    return p.first < q.first ;

}



void printBinary ( int num )

{

    for (int i = 7 ; i>= 0 ; i--) /// here for 8 bit.

    {

        cout << ((num>> i) & 1 ) ;

    }

    cout << endl ;

}



/// instead of ceil ,use (x+y-1)/y ;



/// sub arrays = (total number - common number + 1) * (total number - common number + 2) / 2;



/// Sort a pair

// sort(v.begin() , v.end() , [] (const pair < int , int> &a , const pair< int , int >&b){

        // return a.second < b.second ; }) ;







void solve()

{

    int n ;

    cin>> n ;



    vector < int > v(n) ;



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



    int t = 0 ;



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

        if(v[i] < t) {

            pn ;

            return ;

        }

        t = v[i] - t ;

    }



    py ;

}



int main() {

    Gremlin OwL

    ll testcase;

    cin >> testcase;



    for (ll i = 1; i <= testcase; i++) {

    //  cout << "Case "<< i << ": " ;

        solve();

    // cout << endl ;

    }



    return 0;

}