Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
//! Bismillahi-Rahamanirahim.
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define str string
#define vll vector<ll>
// vector<vector<ll>> a(n,vector<ll>(n,v));
// priority_queue <int, vector<int>, greater<int>> pq;
#define pl pair<ll,ll>
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define sz(n) (ll)(n).size()
#define sp ' '
#define sfor(i, s, n, m) for (ll i = s; i < n; i += m)
#define refor(i, n, s, m) for (ll i = n - 1; i >= s; i -= m)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define eps 1e-12
#define mod 1000000007
#define MAX 100007
#define inf 1000000000000000000
#define pi (2 * acos(0))
#define torad(x) ((x) * ((2 * acos(0)) / 180.0))
#define todeg(x) ((x) * (180.0 / (2 * acos(0))))
#define fixangle(x) ((x) > 1 ? 1 : (x) < -1 : (x))
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define endl "\n"
#define mem(x, y) memset(&x[0], y, sizeof(x))
#define bs(v, x) binary_search(v.begin(), v.end(), x)
#define ub(v, x) upper_bound(v.begin(), v.end(), x) - v.begin()
#define lb(v, x) lower_bound(v.begin(), v.end(), x) - v.begin()
#define fast() ios_base::sync_with_stdio(0);
#define fast1() cin.tie(0);cout.tie(0);
//-------------------------------------------------------------------------//

int main()
{
    fast();
//    fast1();
    ll test = 1, cas = 1;
    cin >> test;
    while (test--)
    {
        ll n,f=0;
        cin >> n;
        vll a(n,0);
        sfor(i,0,n,1)
        {
            cin >> a[i];
        }
        refor(i,n-1,0,1)
        {
            if(a[i]>a[i+1] && i>0)
            {
                ll p=a[i]-a[i-1];
                if(p>0 && p>a[i+1])
                {
                    f=1;
                    break;
                }
                else if(p<0)
                {
                    a[i-1]=p;
                }
            }
            else if(a[i]>a[i+1] && i==0)
            {
                f=1;
                break;
            }
        }
        if(f)
            no;
        else
            yes;
    }
    return 0;
}


Submission (verdict: Wrong answer on test 2):
//! Bismillahi-Rahamanirahim.
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define str string
#define vll vector<ll>
// vector<vector<ll>> a(n,vector<ll>(n,v));
// priority_queue <int, vector<int>, greater<int>> pq;
#define pl pair<ll,ll>
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define sz(n) (ll)(n).size()
#define sp ' '
#define sfor(i, s, n, m) for (ll i = s; i < n; i += m)
#define refor(i, n, s, m) for (ll i = n - 1; i >= s; i -= m)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define eps 1e-12
#define mod 1000000007
#define MAX 100007
#define inf 1000000000000000000
#define pi (2 * acos(0))
#define torad(x) ((x) * ((2 * acos(0)) / 180.0))
#define todeg(x) ((x) * (180.0 / (2 * acos(0))))
#define fixangle(x) ((x) > 1 ? 1 : (x) < -1 : (x))
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define endl "\n"
#define mem(x, y) memset(&x[0], y, sizeof(x))
#define bs(v, x) binary_search(v.begin(), v.end(), x)
#define ub(v, x) upper_bound(v.begin(), v.end(), x) - v.begin()
#define lb(v, x) lower_bound(v.begin(), v.end(), x) - v.begin()
#define fast() ios_base::sync_with_stdio(0);
#define fast1() cin.tie(0);cout.tie(0);
//-------------------------------------------------------------------------//

int main()
{
    fast();
//    fast1();
    ll test = 1, cas = 1;
    cin >> test;
    while (test--)
    {
        ll n,f=0;
        cin >> n;
        vll a(n,0);
        sfor(i,0,n,1)
        {
            cin >> a[i];
        }
        refor(i,n-1,0,1)
        {
            if(a[i]>a[i+1] && i>0)
            {
                ll p=a[i]-a[i-1];
                if(p>0 && p>a[i+1])
                {
                    f=1;
                    break;
                }
                else if(p<0)
                {
                    a[i-1]=abs(p);
                }
            }
            else if(a[i]>a[i+1] && i==0)
            {
                f=1;
                break;
            }
        }
        if(f)
            no;
        else
            yes;
    }
    return 0;
}