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

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

/* TYPES  */
#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vi vector<int>
#define vll vector<long long>
#define mii map<int, int>
#define si set<int>
#define sc set<char>
#define ff first
#define ss second
#define nl_ cout<<"\n";
#define sz(v) v.size()
/* FUNCTIONS */
#define f(i,s,e) for(long long int i=s;i<e;i++)
#define rf(i,e,s) for(long long int i=e-1;i>=s;i--)
#define pb push_back


#define MOD 1000000007
#define all(a) (a).begin(),(a).end()
#define tc int tc; cin>>tc; while(tc--)

// print a map
#define PRINT_MAP(m)                                                         \
    do {                                                                     \
        cout << #m << " = {";                                                \
        bool first = true;                                                   \
        for (const auto &pair : m) {                                         \
            if (!first) cout << ", ";                                        \
            cout << "[" << pair.first << "] = " << pair.second;              \
            first = false;                                                   \
        }                                                                    \
        cout << "}" << endl;                                                 \
    } while (0)


// print a vector
#define PRINT_VECTOR(vec)                          \
    do {                                           \
        cout << #vec << " = {";                   \
        for (size_t i = 0; i < vec.size(); ++i) { \
            if (i > 0) cout << ", ";              \
            cout << vec[i];                       \
        }                                         \
        cout << "}" << endl;                      \
    } while (0)


// read a vector
#define READ_VECTOR(vec)                \
    do {                                \
        int nn = (int) v.size();        \
        for (int i = 0; i < nn; ++i) {   \
            cin >> vec[i];              \
        }                               \
    } while (0)
    
    
int binsearch(vi v, bool is_lower,int k){
    int l = 0;
    int r = sz(v)-1;
    int ans=-1;
    while(l<=r){
        int mid = (l+r)/2;
        
      if(v[mid]< k){
        if(is_lower)
            ans = mid;
                l = mid+1;
        }
        else{
            if(!is_lower)
            ans = mid;
            r = mid-1;
        }
    }
    return ans;
}



int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    
    
	// Be very sure about the solution before touching the keyboard.
	// Write implementation below.
	
	tc{
	    int n;
	    cin>>n;
	    vi v(n);
	    READ_VECTOR(v);
	    int minTillNow = v[n-1];
	    int fault=0;
	    rf(i,n-1,1){
	        
	        if(v[i] <= minTillNow ){
	            minTillNow = v[i];
	            continue;
	        }
	        else if(v[i] > v[i-1] and v[i] - v[i-1] <= minTillNow){
	            minTillNow = v[i];
	            continue;
	        }
	        else{
	            fault=1;
	        }
	    }
	   fault==1?cout<<"NO\n":cout<<"YES\n";
	}

}


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

/* TYPES  */
#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vi vector<int>
#define vll vector<long long>
#define mii map<int, int>
#define si set<int>
#define sc set<char>
#define ff first
#define ss second
#define nl_ cout<<"\n";
#define sz(v) v.size()
/* FUNCTIONS */
#define f(i,s,e) for(long long int i=s;i<e;i++)
#define rf(i,e,s) for(long long int i=e-1;i>=s;i--)
#define pb push_back


#define MOD 1000000007
#define all(a) (a).begin(),(a).end()
#define tc int tc; cin>>tc; while(tc--)

// print a map
#define PRINT_MAP(m)                                                         \
    do {                                                                     \
        cout << #m << " = {";                                                \
        bool first = true;                                                   \
        for (const auto &pair : m) {                                         \
            if (!first) cout << ", ";                                        \
            cout << "[" << pair.first << "] = " << pair.second;              \
            first = false;                                                   \
        }                                                                    \
        cout << "}" << endl;                                                 \
    } while (0)


// print a vector
#define PRINT_VECTOR(vec)                          \
    do {                                           \
        cout << #vec << " = {";                   \
        for (size_t i = 0; i < vec.size(); ++i) { \
            if (i > 0) cout << ", ";              \
            cout << vec[i];                       \
        }                                         \
        cout << "}" << endl;                      \
    } while (0)


// read a vector
#define READ_VECTOR(vec)                \
    do {                                \
        int nn = (int) v.size();        \
        for (int i = 0; i < nn; ++i) {   \
            cin >> vec[i];              \
        }                               \
    } while (0)
    
    
int binsearch(vi v, bool is_lower,int k){
    int l = 0;
    int r = sz(v)-1;
    int ans=-1;
    while(l<=r){
        int mid = (l+r)/2;
        
      if(v[mid]< k){
        if(is_lower)
            ans = mid;
                l = mid+1;
        }
        else{
            if(!is_lower)
            ans = mid;
            r = mid-1;
        }
    }
    return ans;
}



int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    
    
	// Be very sure about the solution before touching the keyboard.
	// Write implementation below.
	
	tc{
	    int n;
	    cin>>n;
	    vi v(n);
	    READ_VECTOR(v);
	    int minTillNow = v[n-1];
	    int fault=0;
	    rf(i,n-1,0){
	        if(i==0 and v[i] > minTillNow){
	            fault=1;
	        }
	        else if(v[i] <= minTillNow ){
	            minTillNow = v[i];
	            continue;
	        }
	        else if(v[i] > v[i-1] and v[i] - v[i-1] <= minTillNow){
	            minTillNow = v[i];
	            continue;
	        }
	        else{
	            fault=1;
	        }
	    }
	   fault==1?cout<<"NO\n":cout<<"YES\n";
	}
	

}