Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
// #include <bits/stdc++.h>

// #pragma GCC optimize("O3,unroll-loops,Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")

#include <algorithm>
#include <chrono>
#include <cmath>
#include <iostream>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <unordered_set>
#include <string>
#include <iomanip>
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define sc second
#define endl "\n"
#define pii pair<ll,ll>
#define rep(i,x,a) for(ll i=x;i<a;i++)
#define per(i,x,a) for(ll i=a-1;i>=x;i--)
#define yesno(x) cout << ((x) ? "YES" : "NO") << endl

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const ll MOD = 1e9 + 7;

struct Point{
    ll x, y;
};

void print(vector<ll> &a){
    for(ll i = 0; i<a.size(); i++){
        cout << a[i] << ' ';
    }
    cout << endl;
}

void print_pii(vector<pii> &a){
    for(ll i = 0; i<a.size(); i++){
        cout << a[i].first << ' ' << a[i].second << '\n';
    }
    cout << "\n";
}

ll fact(ll n){
    if(n == 0) return 1;
    return n * fact(n-1);
}

ll sum_d(ll n){
    ll s = 0;
    while(n > 0){
        s += n % 10;
        n /= 10;
    }

    return s;
}

bool cmp(pii a, pii b){
    if(a.first == b.first){
        return a.second < b.second;
    } else {
        return a.first > b.first;
    }
}

ll gcd(ll a, ll b){
    return (a == 0) ? b : gcd(b % a, a);
}

ll sum_a_progress(ll a, ll d, ll n){
    if(n <= 0) return 0;
    return (2 * a + d * (n - 1)) * n / 2;
}

ll c(ll n, ll k){
    return fact(n) / (fact(k) * fact(n - k));
}

ll c2(ll n){
    return n * (n - 1) / 2;
}

ll c3(ll n){
    return n * (n - 1) * (n - 2) / 6;
}

bool is_prime(ll n){
    if(n == 1) return 0;
    if(n == 2) return 1;

    ll d = 2;
    while(d * d <= n){
        if(n % d == 0) return 0;
        d++;
    }
    return 1;
}

ll mex(vector<ll> a, ll l, ll r){
    set<ll> s;
    for(ll i = l; i<=r; i++){
        s.insert(a[i]);
    }

    ll i = 1;
    while(1){
        if(s.find(i) == s.end()){
            return i;
        } else {
            i++;
        }
    }
}

void solve(){
    ll n;

    cin >> n;

    vector<ll> a(n);
    for(ll i = 0; i<n; i++){
        cin >> a[i];
    }

    ll f = 1;
    for(ll i = 0; i<n - 1; i++){
        if(a[i] < a[i+1]){
            a[i + 1] -= a[i];
            a[i] = 0;
        } else if(a[i] > a[i+1]){
            f = 0;
        }
    }

    yesno(f);
    
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    // freopen("input.txt", "r", stdin);

    ll t = 1;
    cin >> t;

    while(t--){
        solve();
    }
}

Submission (verdict: Wrong answer on test 2):
// #include <bits/stdc++.h>

// #pragma GCC optimize("O3,unroll-loops,Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")

#include <algorithm>
#include <chrono>
#include <cmath>
#include <iostream>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <unordered_set>
#include <string>
#include <iomanip>
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define sc second
#define endl "\n"
#define pii pair<ll,ll>
#define rep(i,x,a) for(ll i=x;i<a;i++)
#define per(i,x,a) for(ll i=a-1;i>=x;i--)
#define yesno(x) cout << ((x) ? "YES" : "NO") << endl

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const ll MOD = 1e9 + 7;

struct Point{
    ll x, y;
};

void print(vector<ll> &a){
    for(ll i = 0; i<a.size(); i++){
        cout << a[i] << ' ';
    }
    cout << endl;
}

void print_pii(vector<pii> &a){
    for(ll i = 0; i<a.size(); i++){
        cout << a[i].first << ' ' << a[i].second << '\n';
    }
    cout << "\n";
}

ll fact(ll n){
    if(n == 0) return 1;
    return n * fact(n-1);
}

ll sum_d(ll n){
    ll s = 0;
    while(n > 0){
        s += n % 10;
        n /= 10;
    }

    return s;
}

bool cmp(pii a, pii b){
    if(a.first == b.first){
        return a.second < b.second;
    } else {
        return a.first > b.first;
    }
}

ll gcd(ll a, ll b){
    return (a == 0) ? b : gcd(b % a, a);
}

ll sum_a_progress(ll a, ll d, ll n){
    if(n <= 0) return 0;
    return (2 * a + d * (n - 1)) * n / 2;
}

ll c(ll n, ll k){
    return fact(n) / (fact(k) * fact(n - k));
}

ll c2(ll n){
    return n * (n - 1) / 2;
}

ll c3(ll n){
    return n * (n - 1) * (n - 2) / 6;
}

bool is_prime(ll n){
    if(n == 1) return 0;
    if(n == 2) return 1;

    ll d = 2;
    while(d * d <= n){
        if(n % d == 0) return 0;
        d++;
    }
    return 1;
}

ll mex(vector<ll> a, ll l, ll r){
    set<ll> s;
    for(ll i = l; i<=r; i++){
        s.insert(a[i]);
    }

    ll i = 1;
    while(1){
        if(s.find(i) == s.end()){
            return i;
        } else {
            i++;
        }
    }
}

void solve(){
    ll n;

    cin >> n;

    vector<ll> a(n);
    for(ll i = 0; i<n; i++){
        cin >> a[i];
    }

    ll f = 1;
    ll c = 0;
    for(ll i = 0; i<n - 1; i++){
        if(a[i] < a[i+1] && c == 0){
            a[i + 1] -= a[i];
            a[i] = 0;
        } else if(a[i] > a[i+1]){
            f = 0;
        } else {
            c = 1;
        }
    }

    yesno(f);
    
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    // freopen("input.txt", "r", stdin);

    ll t = 1;
    cin >> t;

    while(t--){
        solve();
    }
}