Problem: 2060D - Subtract Min Sort
Language: c++17 

Code 1:
#include<bits/stdc++.h>

using namespace std;

#define debug(x) cout << '[' << #x << " is: " << x << "] " << endl;
#define imod(a , n) (a % n + n ) % n

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
#define inF freopen("ladder.in","r",stdin );
#define outF freopen("ladder.out" , "w" , stdout ) ;
#define sor(v) sort(v.begin() , v.end());
//#define print(v) for(auto f : v ) cout << f << " " ;
#define rsor(v) sort(v.rbegin() , v.rend());
#define rev(v) reverse(v.begin() , v.end());
#define scan(v) for(auto &it : v)cin >> it ;

#define logar(x , y) log(x) / log(y)
#define __sum(n) n * (n + 1) / 2
#define __lcm(a , b) a / __gcd(a , b) * b
#define pii pair<int , int >
#define ll long long
#define int ll
#define matrix vector<vector<ll>>
#define pii pair<int , int >

const int di[] = {1 , -1 , 0 , 0};
const int dj[] = {0 , 0 , 1 , -1};

const int mod = 1e9 + 7;
const int N = 1e6 + 6 ;

int check(int a1 ,int a2 ,int  a3 ,int  a4 ,int a5){


    return (a1 + a2 == a3) + (a2 + a3 == a4 )+ (a3 + a4 == a5) ;


}

int32_t main()

{   //inF;
    //inF;outF;
    fastio;

    int t ;
    cin >> t ;

    while(t--){

        int n ;
        cin >> n ;

        vector<int> v(n);
        for(auto &it : v)cin >> it ;
        if(v[1] < v[0])cout << "NO";
        else {
            string ans = "YES";
            int mn = min(v[1] , v[0]);
            v[1] -= mn , v[0] -= mn ;


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

                }
                if(v[i] < v[i - 1]){
                    ans = "NO";
                    break;
                }

                mn = min(v[i] , v[i-1]);
                v[i]-=mn,v[i-1]-=mn;

            }
            cout << ans ;
        }


        cout << '\n';
    }

}




Code 2:
#include<bits/stdc++.h>

using namespace std;

#define debug(x) cout << '[' << #x << " is: " << x << "] " << endl;
#define imod(a , n) (a % n + n ) % n

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
#define inF freopen("ladder.in","r",stdin );
#define outF freopen("ladder.out" , "w" , stdout ) ;
#define sor(v) sort(v.begin() , v.end());
//#define print(v) for(auto f : v ) cout << f << " " ;
#define rsor(v) sort(v.rbegin() , v.rend());
#define rev(v) reverse(v.begin() , v.end());
#define scan(v) for(auto &it : v)cin >> it ;

#define logar(x , y) log(x) / log(y)
#define __sum(n) n * (n + 1) / 2
#define __lcm(a , b) a / __gcd(a , b) * b
#define pii pair<int , int >
#define ll long long
#define int ll
#define matrix vector<vector<ll>>
#define pii pair<int , int >

const int di[] = {1 , -1 , 0 , 0};
const int dj[] = {0 , 0 , 1 , -1};

const int mod = 1e9 + 7;
const int N = 1e6 + 6 ;

int check(int a1 ,int a2 ,int  a3 ,int  a4 ,int a5){


    return (a1 + a2 == a3) + (a2 + a3 == a4 )+ (a3 + a4 == a5) ;


}

int32_t main()

{   //inF;
    //inF;outF;
    fastio;

    int t ;
    cin >> t ;

    while(t--){

        int n ;
        cin >> n ;

        vector<int> v(n);
        for(auto &it : v)cin >> it ;
        if(v[1] < v[0])cout << "NO";
        else {
            string ans = "YES";
            for(int i = 2 ; i < n ; i ++){
                if(v[i] < v[i - 1]){
                    v[i - 1] -= min(v[i - 1] , v[i - 2]);

                }
                if(v[i] < v[i - 1]){
                    ans = "NO";
                    break;
                }
            }
            cout << ans ;
        }


        cout << '\n';
    }

}




Answer: 1