Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
/* AUTHOR : ashishsutar1210 */

#include<bits/stdc++.h>

using namespace std;

#define ll long long 

#define ld long double

#define i128 __int128_t

#define Endl endl

#define endl '\n' // undef when responsive 

#define F first

#define S second

#define all(x) begin(x),end(x)

#define rall(x) rbegin(x),rend(x)

#define sz  size()

#define pb push_back

#define mpp make_pair

#define yes cout<<"YES"<<endl

#define no cout<<"NO"<<endl

#define fr(i,a,b) for(ll i=a;i<b;++i)

#define rf(i,a,b) for(ll i=a-1;i>=b;--i)

#define lb lower_bound

#define ub upper_bound

#define eb emplace_back

#define INF 3e18



#ifdef local

    #include "./debug.cpp"

#else 

    #define debug(x...)

#endif



const ll mod = 1000000007;



void ash()

{

    int n;

    int mx = -1;

    stack<int>st;

    cin>>n;

    vector<int>a(n);

    fr(i,0,n){

        cin>>a[i];

    }

    vector<int>ng(n);

    rf(i,n,0)

    {

        while(st.sz && a[st.top()]<a[i])

        {

            st.pop();

        }

        if(st.sz)

        {

            ng[i] = st.top();

        }

        else

        {

            ng[i] = n;

        }

        st.push(i);

    }

    int idx = 0;

    while(idx < n)

    {

        if(ng[idx] == idx+1)

        {

            idx += 2;

            continue;

        }

        if(ng[idx] == n)

        {

            no;

            return;

        }

        debug(idx,ng[idx]);

        idx += 2;

    }

    yes;

}



int32_t main(){



ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);



#ifdef local1

    freopen("input.txt", "r", stdin);

    freopen("output.txt", "w", stdout);

#endif

   int t = 1;

   cin>>t;

   while(t--){

    ash();

   }

    return 0;

} 

Submission (verdict: Accepted):
/* AUTHOR : ashishsutar1210 */

#include<bits/stdc++.h>

using namespace std;

#define ll long long 

#define ld long double

#define i128 __int128_t

#define Endl endl

#define endl '\n' // undef when responsive 

#define F first

#define S second

#define all(x) begin(x),end(x)

#define rall(x) rbegin(x),rend(x)

#define sz  size()

#define pb push_back

#define mpp make_pair

#define yes cout<<"YES"<<endl

#define no cout<<"NO"<<endl

#define fr(i,a,b) for(ll i=a;i<b;++i)

#define rf(i,a,b) for(ll i=a-1;i>=b;--i)

#define lb lower_bound

#define ub upper_bound

#define eb emplace_back

#define INF 3e18



#ifdef local

    #include "./debug.cpp"

#else 

    #define debug(x...)

#endif



const ll mod = 1000000007;



void ash()

{

    int n;

    cin>>n;

    vector<int>a(n);

    fr(i,0,n){

        cin>>a[i];

    }

    fr(i,0,n-1)

    {

        int x = a[i];

        int y = a[i+1];

        if(x > y)

        {

            no;

            return;

        }

        a[i] -= min(x,y);

        a[i+1] -= min(x,y);

    }

    yes;

}



int32_t main(){



ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);



#ifdef local1

    freopen("input.txt", "r", stdin);

    freopen("output.txt", "w", stdout);

#endif

   int t = 1;

   cin>>t;

   while(t--){

    ash();

   }

    return 0;

}