Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
#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;
}


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

#define int long long int
// #define ll long long
#define minaZ                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define do_prefix(x, n)         \
    for (int i = 1; i < n; i++) \
    {                           \
        x[i] += x[i - 1];       \
    }
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define copy_to_stream(x) copy(x.begin(), x.end(), ostream_iterator<int>{cout, " "});
#define for0(x) for (int i = 0; i < x; i++)
#define input(x)                       \
    for (int i = 0; i < x.size(); i++) \
    cin >> x[i]
#define sp(x, y) swap(x, y)
#define make_unique_plz(x) x.erase(unique(all(p)), p.end())
#define endl '\n'
vector<int> get_divisors(int n)
{
    vector<int> result;
    for (int i = 1; i * i <= n; i++)
    {
        if (n % i == 0)
        {
            result.push_back(i);
            if (i != n / i)
                result.push_back(n / i);
        }
    }
    return result;
}

bool check_prime(int n)
{
    if (n < 2)
        return false;
    for (int i = 2; i * i <= n; i++)
        if (n % i == 0)
            return false;
    return true;
}
//1e7-max
vector<int> sieve(int n)
{
    vector<bool> primes(n + 1, true);
    primes[0] = false;
    primes[1] = false;

    vector<int> result;
    for (int i = 2; i * i <= n; i++)
    {
        if (primes[i])
        {
            result.emplace_back(i);
            for (int j = i * i; j <= n; j += i)
            {
                primes[j] = false;
            }
        }
    }

    return result;
}

//smallest prime factor
void spf(int n)
{
    vector<int> v(n + 1);
    for (int i = 1; i <= n; i++)
        v[i] = i;
    for (int i = 2; i * i <= n; i++)
    {
        if (v[i] == i)
        {
            for (int j = i * i; j <= n; j += i)
            {
                if (v[j] == j)
                    v[j] = i;
            }
        }
    }
}

void p_multi(int n)
{
    for (int i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            cout << i << ' ';
            n /= i;
        }
    }
    if (n > 1)
        cout << n << ' ';
}

vector<int> count_divisors()
{
    int n = 1e6;
    vector<int> result(n + 1, 0);

    for (int i = 1; i <= n; i++)
    {
        for (int j = i; j <= n; j += i)
        {
            result[j]++;
        }
    }

    return result;
}

vector<int> all_mults(int n)
{
    vector<int> result;
    for (int i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            result.push_back(i);
            n /= i;
        }
    }
    if (n > 1)
        result.push_back(n);
    return result;
}

int gcd(int a, int b)
{
    while (b != 0)
    {
        int temp = b;
        b = a % b;
        a = temp;
    }
    return a;
}

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

inline int lcm(int a, int b)
{
    return a / gcd(a, b) * b;
}

int fast_power_recursive(int base, int exp)
{
    if (exp == 0)
        return 1;
    if (exp == 1)
        return base;
    int temp = fast_power_recursive(base, exp / 2);
    temp *= temp;
    if (exp & 1)
        temp *= base;
    return temp;
}
int fast_power(int base, int exp)
{
    int result = 1;
    while (exp > 0)
    {
        if (exp & 1)
        {
            result *= base;
        }
        base *= base;
        exp /= 2;
    }
    return result;
}

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

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

int MBE(int base, int exp)
{
    const int mod = (1e9 + 7);
    if (exp == 0)
        return 1;
    int result = MBE(base, exp / 2);
    if (exp % 2 == 1)
        return (((result * result) % mod) * base) % mod;
    else
        return (result * result) % mod;
}

vector<int> phi_1_to_n(int n)
{
    vector<int> phi(n + 1);
    for (int i = 0; i <= n; i++)
        phi[i] = i;

    for (int i = 2; i <= n; i++)
    {
        if (phi[i] == i)
        {
            for (int j = i; j <= n; j += i)
                phi[j] -= phi[j] / i;
        }
    }
    return phi;
}

int phi(int n)
{
    int result = n;
    for (int i = 2; i * i <= n; i++)
    {
        if (n % i == 0)
        {
            while (n % i == 0)
                n /= i;
            result -= result / i;
        }
    }
    if (n > 1)
        result -= result / n;
    return result;
}

vector<vector<int>> generateSubsets(const vector<int> &set)
{
    vector<vector<int>> subsets;
    int n = set.size();
    for (int mask = 1; mask < (1 << n); ++mask)
    {
        vector<int> subset;
        for (int i = 0; i < n; ++i)
        {
            if (mask & (1 << i))
            {
                subset.push_back(set[i]);
            }
        }
        subsets.push_back(subset);
    }
    return subsets;
}

int MBE(int base, int exp, int m)
{
    if (exp == 0)
        return 1;
    int result = MBE(base, exp / 2, m);
    if (exp % 2 == 1)
        return (((result * result) % m) * base) % m;
    else
        return (result * result) % m;
}

int geomatric(int base, int exp)
{
    const int mod = (1e9 + 7);
    int numerator = (MBE(base, exp + 1) - 1 + mod) % mod;
    int denomenrator = MBE(base - 1, mod - 2);
    return (numerator * denomenrator) % mod;
}

int rotations(string s)
{
    string temp = s.back() + s.substr(0, s.size() - 1);
    int ans = 1;
    while (temp != s)
    {
        ans++;
        temp = temp.back() + temp.substr(0, temp.size() - 1);
    }
    return ans;
}
// max_sum = max(current element , current element + m) m is a subarray that has the maximum subarray sum
int kadanes_algo_for_max(vector<int>& nums) 
{
    int current_sum,global_sum;
    current_sum = global_sum = nums.front();
    for(int i=1;i<nums.size();i++)
    {
        current_sum = max(current_sum+nums[i],nums[i]);
        global_sum = max(global_sum,current_sum);
    }
    return  global_sum;
}
int kadanes_algo_for_min(vector<int>& nums) 
{
    int current_sum,global_sum;
    current_sum = global_sum = nums.front();
    for(int i=1;i<nums.size();i++)
    {
        current_sum = min(current_sum+nums[i],nums[i]);
        global_sum = min(global_sum,current_sum);
    }
    return  global_sum;
}

signed main()
{
    minaZ;
    int t;cin>>t;
    while(t--)
    {
        int n;cin>>n;
        vector<int>v(n);
        for0(n)
            cin>>v[i];
        int l = 0;
        bool ok = true;
        for(int r = 1;r<n;r++,l++)
        {
            if(v[l]<=v[r])
            {
                v[r] = v[r]- v[l];
                v[l] = 0;
            }
            if(v[r] < v[l])
            {
                ok = false;
                break;
            }
        }
        cout << (ok ? "YES\n":"NO\n");
    }
}