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

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define ull unsigned long long
#define lld long double
#define ll long long int
#define inp(vec)        \
    for (auto &i : vec) \
        cin >> i;
#define vi vector<ll>
#define vs vector<string>
#define vpi vector<pair<ll, ll>>
using namespace std;

const ll MODI = 1e9 + 7;
const ll MAX_NUM = 1e6 + 1;

bool comp(pair<ll, ll> p1, pair<ll, ll> p2)
{
    if (p1.first == p2.first)
    {
        return p1.second > p2.second;
    }
    return p2.second > p1.second;
}

bool compare(pair<ll, ll> p1, pair<ll, ll> p2)
{
    if (p1.first == p2.first)
        return p1.second < p2.second;
    return p1.first > p2.first;
}

ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    if (b == 0)
        return a;
    while (a > 0 && b > 0)
    {
        if (a > b)
            a -= b;
        else
            b -= a;
    }
    return a == 0 ? b : a;
}

ll power(ll a, ll b, ll MODI)
{
    ll ans = 1;
    while (b > 0)
    {
        if (b & 1)
        {
            ans = (ans * a) % MODI;
        }
        a = (a * a) % MODI;
        b >>= 1;
    }
    return ans;
}

vector<bool> sieveOfEratosthenes(ll n)
{
    vector<bool> prime(n + 1, true);
    prime[0] = prime[1] = false;
    for (ll i = 2; i * i <= n; i++)
    {
        if (prime[i])
        {
            for (ll j = i * i; j <= n; j += i)
            {
                prime[j] = false;
            }
        }
    }
    return prime;
}

ll findSum(ll num)
{
    ll sum = 0;
    while (num > 0)
    {
        sum += num % 10;
        num /= 10;
    }
    return sum;
}

void solution()
{
    ll n;
    cin >> n;

    vi v(n);
    for (auto &i : v)
        cin >> i;

    if (is_sorted(v.begin(), v.end()))
    {
        cout << "YES" << endl;
        return;
    }

    for (ll i = 1; i < n; i++)
    {
        if(v[i] == v[i-1])
        {
            continue;
        }
        else if(v[i] > v[i-1])
        {
            v[i] -= (v[i-1]);
            v[i-1] -= (v[i-1]);
        }
        else if(v[i] < v[i-1])
        {
            cout << "NO" << endl;
            return;
        }
    }

    if(is_sorted(v.begin(), v.end()))
    {
        cout << "YES" << endl;
        return;
    }
    else
    {
        cout << "NO" << endl;
        return;
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    // solution();

    ll t;
    cin >> t;
    while (t--)
    {
        solution();
    }

    return 0;
}
// JAY SHRI RADHEYYY


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define ull unsigned long long
#define lld long double
#define ll long long int
#define inp(vec)        \
    for (auto &i : vec) \
        cin >> i;
#define vi vector<ll>
#define vs vector<string>
#define vpi vector<pair<ll, ll>>
using namespace std;

const ll MODI = 1e9 + 7;
const ll MAX_NUM = 1e6 + 1;

bool comp(pair<ll, ll> p1, pair<ll, ll> p2)
{
    if (p1.first == p2.first)
    {
        return p1.second > p2.second;
    }
    return p2.second > p1.second;
}

bool compare(pair<ll, ll> p1, pair<ll, ll> p2)
{
    if (p1.first == p2.first)
        return p1.second < p2.second;
    return p1.first > p2.first;
}

ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    if (b == 0)
        return a;
    while (a > 0 && b > 0)
    {
        if (a > b)
            a -= b;
        else
            b -= a;
    }
    return a == 0 ? b : a;
}

ll power(ll a, ll b, ll MODI)
{
    ll ans = 1;
    while (b > 0)
    {
        if (b & 1)
        {
            ans = (ans * a) % MODI;
        }
        a = (a * a) % MODI;
        b >>= 1;
    }
    return ans;
}

vector<bool> sieveOfEratosthenes(ll n)
{
    vector<bool> prime(n + 1, true);
    prime[0] = prime[1] = false;
    for (ll i = 2; i * i <= n; i++)
    {
        if (prime[i])
        {
            for (ll j = i * i; j <= n; j += i)
            {
                prime[j] = false;
            }
        }
    }
    return prime;
}

ll findSum(ll num)
{
    ll sum = 0;
    while (num > 0)
    {
        sum += num % 10;
        num /= 10;
    }
    return sum;
}

void solution()
{
    ll n;
    cin >> n;

    vi v(n);
    for (auto &i : v)
        cin >> i;

    if (is_sorted(v.begin(), v.end()))
    {
        cout << "YES" << endl;
        return;
    }

    for (ll i = 1; i < n; i++)
    {
        if(v[i] == v[i-1])
        {
            continue;
        }
        else if(v[i] > v[i-1] && (i != n-1))
        {
            v[i] -= (v[i-1]);
            v[i-1] -= (v[i-1]);
        }
        else if(v[i] < v[i-1])
        {
            cout << "NO" << endl;
            return;
        }

        if(is_sorted(v.begin(), v.end()))
        {
            cout << "YES" << endl;
            return;
        }
    }

    if(is_sorted(v.begin(), v.end()))
    {
        cout << "YES" << endl;
        return;
    }
    else
    {
        cout << "NO" << endl;
        return;
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    // solution();

    ll t;
    cin >> t;
    while (t--)
    {
        solution();
    }

    return 0;
}
// JAY SHRI RADHEYYY