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

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

using ll = long long;
#define ull unsigned long long
#define int long long
const ll M = 1e9 + 7;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define pb push_back
#define mp make_pair

void fastio()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

#define yes cout << "YES\n";
#define no cout << "NO\n";
#define nl cout << "\n";

#define vl vector<int>
#define pr pair<int, int>
#define us unordered_set<int>
#define ump unordered_map<int, int>

bool compareByFirstElement(const std::pair<int, int> &a, const std::pair<int, int> &b)
{
    return a.first < b.first;
}

bool isPrime(int n)
{
    if (n <= 1)
    {
        return false; // Numbers less than or equal to 1 are not prime
    }
    if (n <= 3)
    {
        return true; // 2 and 3 are prime numbers
    }
    if (n % 2 == 0 || n % 3 == 0)
    {
        return false; // Multiples of 2 and 3 are not prime
    }

    // Check divisibility from 5 to sqrt(n)
    for (int i = 5; i * i <= n; i += 6)
    {
        if (n % i == 0 || n % (i + 2) == 0)
        {
            return false; // Found a divisor, so not prime
        }
    }
    return true; // No divisors found, number is prime
}
/*----------------------------------MAINCODE------------------------------------*/
void solve()
{
    int n;
    cin>>n;
    vl v;
    rep(i,0,n){
        int a;
        cin>>a;
        v.pb(a);
    }
    bool an=true;
    if(v[1]<v[0])an=false;
    if(n==3){
        int cut=min(v[1],v[2]);
        if(an){
            if(v[1]-v[0]>v[2]){
                an=false;
            }
        }
    }
    rep(j,3,n){
        int diff=v[j]-v[j-1];
        int diff2=v[j-1]-v[j-2];
        if(diff<0&&diff2<0){
            an=false;
            break;
        }
    }
    if(an){
        yes
    }
    else{
        no
    }
}

int32_t main()
{
    fastio();
    int T = 1LL;
    cin >> T;
    while (T--)
    {
        solve();
    }
    return 0;
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define ull unsigned long long
#define int long long
const ll M = 1e9 + 7;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define pb push_back
#define mp make_pair

void fastio()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

#define yes cout << "YES\n";
#define no cout << "NO\n";
#define nl cout << "\n";

#define vl vector<int>
#define pr pair<int, int>
#define us unordered_set<int>
#define ump unordered_map<int, int>

bool compareByFirstElement(const std::pair<int, int> &a, const std::pair<int, int> &b)
{
    return a.first < b.first;
}

bool isPrime(int n)
{
    if (n <= 1)
    {
        return false; // Numbers less than or equal to 1 are not prime
    }
    if (n <= 3)
    {
        return true; // 2 and 3 are prime numbers
    }
    if (n % 2 == 0 || n % 3 == 0)
    {
        return false; // Multiples of 2 and 3 are not prime
    }

    // Check divisibility from 5 to sqrt(n)
    for (int i = 5; i * i <= n; i += 6)
    {
        if (n % i == 0 || n % (i + 2) == 0)
        {
            return false; // Found a divisor, so not prime
        }
    }
    return true; // No divisors found, number is prime
}
/*----------------------------------MAINCODE------------------------------------*/
void solve()
{
    int n;
    cin >> n;
    vl v;
    rep(i, 0, n)
    {
        int a;
        cin >> a;
        v.pb(a);
    }
    bool an = true;
    if (v[1] < v[0])
        an = false;
    rep(j, 2, n)
    {
        if (v[j - 1] - v[j - 2] > v[j])
        {
            an = false;
            break;
        }
        else{
            v[j-1]-=v[j-2];
            v[j-2]=0;
        }
    }
    if (an)
    {
        yes
    }
    else
    {
        no
    }
}

int32_t main()
{
    fastio();
    int T = 1LL;
    cin >> T;
    while (T--)
    {
        solve();
    }
    return 0;
}