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

Solution 1 (runtime: 109 ms):
///CF: 2060D
///Date: 17 February,2025 Time: 10:30pm

#include<bits/stdc++.h>
using namespace std;
#define loop(n,m)     for(int i=n; i<m; i++)
#define f(n)          for(int i=0; i<n; i++)
#define pb            push_back
#define mp            make_pair
#define vread(n,v)    for(int i=0;i<n;i++){int x;cin>>x;v.push_back(x);}
#define all(x) x.begin(), x.end()
#define sortme(v)     sort(v.begin(),v.end())
#define reverseme(v)  reverse(v.begin(),v.end())
#define yesno(ans) printf("%s\n", (ans)?"Yes":"No");
#define YESNO(ans) printf("%s\n", (ans)?"YES":"NO")
#define print(a)      for(auto x : a) cout << x << " ";
#define printpair(a)  for(auto x : a) cout << x.first << " " << x.second<< endl;


#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);


typedef long long int ll;
typedef pair <int, int> pii;
const ll MOD = 1e9 + 7;
const ll INF = INT_MAX;
const int N = 1e5 + 5;
const double PI = acos(-1);

const ll boro = 1e12 + 10;

// ll pow2[200001];
// ll arr[1000000 + 10];
//vector<ll> temp[300005];

void solve()
{
    vector<pair<ll, ll>> vc;
    vector<ll>vx, vy;
    // vector<pair<int, int>> v2;
    ll a,z, b, n, c, d,maxi,ans=0,t,x,y,k,m,total=0,count=0,mx=0;
    string str = "", strr = "";
    set<ll> s, ss, s1, s2;

    // vector<ll> v, aa, bb;
    vector<string> vstr;
    //map <string, ll> mpp;
    vector<ll> v1, v2;
    vector<pair<ll, ll> > vaa;



    vector<ll> v;

    cin >> n; 
    for(ll i=0; i<n; i++)
    {
        cin >> x; 
        v.pb(x);
    }
    ll pos = -1;
    for(ll i=0; i<n-1; i++)
    {
        if(v[i]>v[i+1])
        {
            pos = i;
        }
    }



    for(ll i=0; i<=pos; i++)
    {
        x = min(v[i],v[i+1]);
        v[i] = v[i]-x;
        v[i+1] = v[i+1]-x;
        if(v[i]>v[i+1])
        {
            cout << "NO" << endl;
            return;
        } 
    }

    cout << "YES" << endl;





    return;
}




int main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    int test, t, a, b, c, x, y, k, m, n, sum, count, result;
    int i = 1;
    test = 1;
    cin >> test;
    while (test--)
    {
        // cout << i << "th : ";
        solve(); i++;
    }
    return 0;
}

Solution 2 (runtime: 93 ms):
#include<bits/stdc++.h>

#include<numeric>

using namespace std;



#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)

#define endl "\n"

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

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

#define save_0(n, vec) for (int i = 0; i < n; i++) cin >> vec[i]

#define save_1(n, vec) for (int i = 1; i <= n; i++) cin >> vec[i]



int LIM = 1e6;



void solve() {

    int n;

    cin >> n;



    vector<int> vec(n);



    save_0(n, vec);



    for (int i = 0; i < n - 1; i++)

    {

        if (vec[i + 1] >= vec[i]) {

            int m = min(vec[i], vec[i + 1]);



            vec[i] -= m;

            vec[i + 1] -= m;

        }

        else {

            no;

            return;

        }

    }



    yes;

}



int main() {

    fast;



    int t;

    cin >> t;



    while (t--) {

        solve();

    }

}