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

Code 1:
#include <bits/stdc++.h>
using namespace std;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// find_by_order, order_of_key
#define all(v) v.begin(), v.end()
#define ll long long
#define en cout << endl;
#define memo(arr, val) memset(arr, val, sizeof(arr))
#define int long long
#define f first
#define s second
#define sz(s) (int)(s).size()
#define rep(i, st, ed) for (int i = st; i < ed; i++)

bool valid(int i, int j, int n, int m) {
    return i < n && i >= 0 && j < m && j >= 0;
}

int inf = 1e18;

void Sh3lan() {
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("errors.txt", "w", stderr);

#endif
}

int mod = 1e9 + 7;

int mul(int a, int b) { return ((a % mod) * (b % mod)) % mod; }

int add(int a, int b) { return ((a % mod) + (b % mod)) % mod; }

int sub(int a, int b) { return ((a % mod) - (b % mod) + mod) % mod; }

int GCD(int a, int b) { return b == 0 ? a : GCD(b, a % b); }

int LCM(int a, int b) { return a / GCD(a, b) * b; }

int fast(int a, int m) {
    if (m == 0) return 1;
    int x = fast(a, m / 2);
    x = mul(x, x);
    if (m & 1) x = mul(x, a);
    return x % mod;
}

int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};
const int N = 2e3 + 5;

void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (auto &i: a) cin >> i;
    if (n == 2 && a[0] > a[1]) {
        cout << "NO" << endl;
        return;
    }
    bool ok = false;
    for (int i = 1; i < n - 1; i++) {
        if (a[i] > a[i + 1] && a[i] < a[i - 1]) {
            ok = true;
        }
    }
    if (ok) {
        cout << "NO" << endl;
    } else {
        cout << "YES" << endl;
    }
}

signed main() {
    Sh3lan();
    int t = 1;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}


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

using namespace std;

#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#define ll long long
#define vii vector<int>
#define vib vector<bool>
#define vil vector<ll>
#define vis vector<string>
#define pp pair<int, int>
#define all(d) d.begin(), d.end()
#define py cout << "YES\n"
#define pm cout << "-1\n"
#define pn cout << "NO\n"
#define setit(v, name) ::memset(name, v, sizeof(name))
#define inf 1e5
#define sz(v) ((int)(v.size()))
#define GRAPH vector<vector<char>>
#define ceill(a, b) (((a) + (b) - 1) / b)
#define tests ll t; cin >> t; while (t--)
const double EPS = 1e-9;
ll mod = 1073741824;
const double pi = 3.14159265358979323846;
const int dx8[8] = {1, 0, -1, 0, -1, -1, 1, 1};
const int dy8[8] = {0, 1, 0, -1, -1, 1, -1, 1};
int dr[] = {+0, +0, +1, -1};
int dc[] ={+1, -1, +0, +0};
template<typename T>
istream& operator>>(istream &istream, vector<T> &v){for (auto &it : v)cin >> it;return istream;}



void solve(){
    int n;
    cin >> n ;

    vii arr(n + 1 , 0);

    for(int i =1 ;i <= n; i++){
        cin >> arr[i];
    }

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

            if(arr[i + 1] <=  arr[i]){
                cout << "NO\n";
                return ;
            }
        }
    }

    cout << "YES\n";
    return ;
}

int main(){

    fast
    tests
    solve();
}



Answer: 2