Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define db long double
#define fi first
#define se second
#define endl "\n"
#define all(v) v.begin(), v.end()
#define vi vector<int>
#define vb vector<bool>
#define vii vector<pair<int, int>>
#define vvi vector<vector<int>>
#define ii pair<int, int>
#define iii pair<int, pair<int, int>>
#define mii map<int, int>
#define mci map<char, int>
#define altgraph vector<set<int>>
#define pqueue priority_queue
const int max_n = 200005;
const int max_ai = 1000000;
const int mod = 998244353;
const int base = 193939;
const db pi = atan(1) * 4;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); //random
int bpowm(int b, int e){if(e == 0) return 1;int ans = bpowm(b, e / 2);if(e % 2 == 1) return (((ans * ans) % mod) * b) % mod;else return ((ans * ans) % mod);}
int bpow(int b, int e){if(e == 0) return 1;int ans = bpow(b, e / 2);if(e % 2 == 1) return (ans * ans * b);else return (ans * ans);}
int moddiv(int x, int y){return (x % mod) * ((bpowm(y, mod - 2))) % mod;}
int modmin(int a, int b){return (a + mod - b) % mod;}
bool prime[max_n];void primeseev(){prime[1]=true;for(int i=2;i<=sqrt(max_n);i++){if(prime[i])continue;for(int j=i*i;j<=max_n;j+=i){prime[j]=true;}}}
int factori[max_n];void factoree(){factori[0] = 1;for(int i = 1; i <= max_n; i++){factori[i] = (factori[i - 1] * i) % mod;}}
int combi(int n, int k){if(k > n){return 0;}return (((factori[n] * bpowm(factori[n - k], mod - 2)) % mod) * bpowm(factori[k], mod - 2)) % mod;}
 
// upperbound: > val
// lowerbound: >= val
// cout << (condition ? "YES" : "NO") << endl;
// cout.flush();
// sum perm: n(n + 1)/2

void solve()
{
    int n;
    cin >> n;

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

    
    int p;
    //last editable element
    if(a[n - 2] <= a[n - 1])
    {
        p = n - 2;
        while(p >= 0 && a[p] <= a[p + 1])
        {
            p--;
        }
        if(p == -1)
        {
            cout << "YES" << endl;
            return;
        }
        // cout << p << " 1" << endl;
    }
    else
    {
        p = n - 2;
        // cout << p << " 2" << endl;
    }

    for(int i = 0; i < p; i++)
    {
        a[i + 1] -= a[i];
        a[i] = 0;
    }

    for(int i = 0; i < n - 1; i++)
    {
        if(a[i] > a[i + 1])
        {
            cout << "NO" << endl;
            return;
        }
    }
    
    cout << "YES" << endl;
}
 
signed main()
{
    clock_t tStart = clock();
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    #ifndef ONLINE_JUDGE
    freopen("INPUT.INP", "r", stdin);
    freopen("OUTPUT.OUT", "w", stdout);
    #endif
 
    // primeseev();
    // factoree();
 
    int t = 1;
    cin >> t;
    while(t--) solve();
 
    fprintf(stderr,"\n>> Runtime: %.10fs\n",(double)(clock()-tStart)/CLOCKS_PER_SEC);
    return 0;
}
/*
pls don't hac me
am friendli
if you hac i eat yur balls
*/

Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define db long double
#define fi first
#define se second
#define endl "\n"
#define all(v) v.begin(), v.end()
#define vi vector<int>
#define vb vector<bool>
#define vii vector<pair<int, int>>
#define vvi vector<vector<int>>
#define ii pair<int, int>
#define iii pair<int, pair<int, int>>
#define mii map<int, int>
#define mci map<char, int>
#define altgraph vector<set<int>>
#define pqueue priority_queue
const int max_n = 200005;
const int max_ai = 1000000;
const int mod = 998244353;
const int base = 193939;
const db pi = atan(1) * 4;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); //random
int bpowm(int b, int e){if(e == 0) return 1;int ans = bpowm(b, e / 2);if(e % 2 == 1) return (((ans * ans) % mod) * b) % mod;else return ((ans * ans) % mod);}
int bpow(int b, int e){if(e == 0) return 1;int ans = bpow(b, e / 2);if(e % 2 == 1) return (ans * ans * b);else return (ans * ans);}
int moddiv(int x, int y){return (x % mod) * ((bpowm(y, mod - 2))) % mod;}
int modmin(int a, int b){return (a + mod - b) % mod;}
bool prime[max_n];void primeseev(){prime[1]=true;for(int i=2;i<=sqrt(max_n);i++){if(prime[i])continue;for(int j=i*i;j<=max_n;j+=i){prime[j]=true;}}}
int factori[max_n];void factoree(){factori[0] = 1;for(int i = 1; i <= max_n; i++){factori[i] = (factori[i - 1] * i) % mod;}}
int combi(int n, int k){if(k > n){return 0;}return (((factori[n] * bpowm(factori[n - k], mod - 2)) % mod) * bpowm(factori[k], mod - 2)) % mod;}
 
// upperbound: > val
// lowerbound: >= val
// cout << (condition ? "YES" : "NO") << endl;
// cout.flush();
// sum perm: n(n + 1)/2

void solve()
{
    int n;
    cin >> n;

    vi a(n);
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    
    int p = 0;
    for(int i = 1; i < n; i++)
    {
        if(a[i - 1] > a[i]) p = i;
    }

    for(int i = 0; i < p; i++)
    {
        int mn = min(a[i], a[i + 1]);
        a[i + 1] -= mn;
        a[i] -= mn;
    }

    for(int i = 0; i < n - 1; i++)
    {
        if(a[i] > a[i + 1])
        {
            cout << "NO" << endl;
            return;
        }
    }
    
    cout << "YES" << endl;
}
 
signed main()
{
    clock_t tStart = clock();
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    #ifndef ONLINE_JUDGE
    freopen("INPUT.INP", "r", stdin);
    freopen("OUTPUT.OUT", "w", stdout);
    #endif
 
    // primeseev();
    // factoree();
 
    int t = 1;
    cin >> t;
    while(t--) solve();
 
    fprintf(stderr,"\n>> Runtime: %.10fs\n",(double)(clock()-tStart)/CLOCKS_PER_SEC);
    return 0;
}
/*
pls don't hac me
am friendli
if you hac i eat yur balls
*/