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;

#define int long long int
// #define ll long long
#define minaZ                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define do_prefix(x, n)         \
    for (int i = 1; i < n; i++) \
    {                           \
        x[i] += x[i - 1];       \
    }
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define copy_to_stream(x) copy(x.begin(), x.end(), ostream_iterator<int>{cout, " "});
#define for0(x) for (int i = 0; i < x; i++)
#define input(x)                       \
    for (int i = 0; i < x.size(); i++) \
    cin >> x[i]
#define sp(x, y) swap(x, y)
#define make_unique_plz(x) x.erase(unique(all(p)), p.end())
#define endl '\n'
vector<int> get_divisors(int n)
{
    vector<int> result;
    for (int i = 1; i * i <= n; i++)
    {
        if (n % i == 0)
        {
            result.push_back(i);
            if (i != n / i)
                result.push_back(n / i);
        }
    }
    return result;
}

bool check_prime(int n)
{
    if (n < 2)
        return false;
    for (int i = 2; i * i <= n; i++)
        if (n % i == 0)
            return false;
    return true;
}
//1e7-max
vector<int> sieve(int n)
{
    vector<bool> primes(n + 1, true);
    primes[0] = false;
    primes[1] = false;

    vector<int> result;
    for (int i = 2; i * i <= n; i++)
    {
        if (primes[i])
        {
            result.emplace_back(i);
            for (int j = i * i; j <= n; j += i)
            {
                primes[j] = false;
            }
        }
    }

    return result;
}

//smallest prime factor
void spf(int n)
{
    vector<int> v(n + 1);
    for (int i = 1; i <= n; i++)
        v[i] = i;
    for (int i = 2; i * i <= n; i++)
    {
        if (v[i] == i)
        {
            for (int j = i * i; j <= n; j += i)
            {
                if (v[j] == j)
                    v[j] = i;
            }
        }
    }
}

void p_multi(int n)
{
    for (int i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            cout << i << ' ';
            n /= i;
        }
    }
    if (n > 1)
        cout << n << ' ';
}

vector<int> count_divisors()
{
    int n = 1e6;
    vector<int> result(n + 1, 0);

    for (int i = 1; i <= n; i++)
    {
        for (int j = i; j <= n; j += i)
        {
            result[j]++;
        }
    }

    return result;
}

vector<int> all_mults(int n)
{
    vector<int> result;
    for (int i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            result.push_back(i);
            n /= i;
        }
    }
    if (n > 1)
        result.push_back(n);
    return result;
}

int gcd(int a, int b)
{
    while (b != 0)
    {
        int temp = b;
        b = a % b;
        a = temp;
    }
    return a;
}

int recursive_gcd(int a, int b)
{
    return b == 0 ? a : recursive_gcd(b, a % b);
}

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

int fast_power_recursive(int base, int exp)
{
    if (exp == 0)
        return 1;
    if (exp == 1)
        return base;
    int temp = fast_power_recursive(base, exp / 2);
    temp *= temp;
    if (exp & 1)
        temp *= base;
    return temp;
}
int fast_power(int base, int exp)
{
    int result = 1;
    while (exp > 0)
    {
        if (exp & 1)
        {
            result *= base;
        }
        base *= base;
        exp /= 2;
    }
    return result;
}

int add(int a, int b, int mod)
{
    return ((a % mod) + (b % mod)) % mod;
}
int mul(int a, int b, int mod)
{
    return ((a % mod) * (b % mod)) % mod;
}

int sub(int a, int b, int mod)
{
    return ((a % mod) - (b % mod) + mod) % mod;
}

int MBE(int base, int exp)
{
    const int mod = (1e9 + 7);
    if (exp == 0)
        return 1;
    int result = MBE(base, exp / 2);
    if (exp % 2 == 1)
        return (((result * result) % mod) * base) % mod;
    else
        return (result * result) % mod;
}

vector<int> phi_1_to_n(int n)
{
    vector<int> phi(n + 1);
    for (int i = 0; i <= n; i++)
        phi[i] = i;

    for (int i = 2; i <= n; i++)
    {
        if (phi[i] == i)
        {
            for (int j = i; j <= n; j += i)
                phi[j] -= phi[j] / i;
        }
    }
    return phi;
}

int phi(int n)
{
    int result = n;
    for (int i = 2; i * i <= n; i++)
    {
        if (n % i == 0)
        {
            while (n % i == 0)
                n /= i;
            result -= result / i;
        }
    }
    if (n > 1)
        result -= result / n;
    return result;
}

vector<vector<int>> generateSubsets(const vector<int> &set)
{
    vector<vector<int>> subsets;
    int n = set.size();
    for (int mask = 1; mask < (1 << n); ++mask)
    {
        vector<int> subset;
        for (int i = 0; i < n; ++i)
        {
            if (mask & (1 << i))
            {
                subset.push_back(set[i]);
            }
        }
        subsets.push_back(subset);
    }
    return subsets;
}

int MBE(int base, int exp, int m)
{
    if (exp == 0)
        return 1;
    int result = MBE(base, exp / 2, m);
    if (exp % 2 == 1)
        return (((result * result) % m) * base) % m;
    else
        return (result * result) % m;
}

int geomatric(int base, int exp)
{
    const int mod = (1e9 + 7);
    int numerator = (MBE(base, exp + 1) - 1 + mod) % mod;
    int denomenrator = MBE(base - 1, mod - 2);
    return (numerator * denomenrator) % mod;
}

int rotations(string s)
{
    string temp = s.back() + s.substr(0, s.size() - 1);
    int ans = 1;
    while (temp != s)
    {
        ans++;
        temp = temp.back() + temp.substr(0, temp.size() - 1);
    }
    return ans;
}
// max_sum = max(current element , current element + m) m is a subarray that has the maximum subarray sum
int kadanes_algo_for_max(vector<int>& nums) 
{
    int current_sum,global_sum;
    current_sum = global_sum = nums.front();
    for(int i=1;i<nums.size();i++)
    {
        current_sum = max(current_sum+nums[i],nums[i]);
        global_sum = max(global_sum,current_sum);
    }
    return  global_sum;
}
int kadanes_algo_for_min(vector<int>& nums) 
{
    int current_sum,global_sum;
    current_sum = global_sum = nums.front();
    for(int i=1;i<nums.size();i++)
    {
        current_sum = min(current_sum+nums[i],nums[i]);
        global_sum = min(global_sum,current_sum);
    }
    return  global_sum;
}

signed main()
{
    minaZ;
    int t;cin>>t;
    while(t--)
    {
        int n;cin>>n;
        vector<int>v(n);
        for0(n)
            cin>>v[i];
        int l = 0;
        bool ok = true;
        for(int r = 1;r<n;r++,l++)
        {
            if(v[l]<=v[r])
            {
                v[r] = v[r]- v[l];
                v[l] = 0;
            }
            if(v[r] < v[l])
            {
                ok = false;
                break;
            }
        }
        cout << (ok ? "YES\n":"NO\n");
    }
}


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

using namespace std;

#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#define ll long long
#define vii vector<int>
#define vib vector<bool>
#define vil vector<ll>
#define vis vector<string>
#define pp pair<int, int>
#define all(d) d.begin(), d.end()
#define py cout << "YES\n"
#define pm cout << "-1\n"
#define pn cout << "NO\n"
#define setit(v, name) ::memset(name, v, sizeof(name))
#define inf 1e5
#define sz(v) ((int)(v.size()))
#define GRAPH vector<vector<char>>
#define ceill(a, b) (((a) + (b) - 1) / b)
#define tests ll t; cin >> t; while (t--)
const double EPS = 1e-9;
ll mod = 1073741824;
const double pi = 3.14159265358979323846;
const int dx8[8] = {1, 0, -1, 0, -1, -1, 1, 1};
const int dy8[8] = {0, 1, 0, -1, -1, 1, -1, 1};
int dr[] = {+0, +0, +1, -1};
int dc[] ={+1, -1, +0, +0};
template<typename T>
istream& operator>>(istream &istream, vector<T> &v){for (auto &it : v)cin >> it;return istream;}



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

    vii arr(n);
    cin >> arr;

    for(int i = 1 ; i < n - 1 ; i++){
        if(arr[i + 1] < arr[i]){
            int mn = min(arr[i] , arr[i - 1]);
            arr[i] -= mn;
            arr[i - 1] -= mn;

            if(arr[i +1] < arr[i]){
                cout << "NO\n";
                return ;
            }
        }
    }

    cout << "YES\n";
    return ;
}

int main(){

    fast
    tests
    solve();
}