Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>

using namespace std;



#define int long long



#define all(a) a.begin(), a.end()

#define pb push_back

#define yes cout << "Yes\n"

#define no cout << "No\n"

#define F first

#define S second



const int MOD = 1e9 + 7;



template <typename T>

istream &operator>>(istream &istream, vector<T> &v){

    for (auto &it : v)

        cin >> it;

    return istream;

}

template <typename T>

ostream &operator<<(ostream &ostream, vector<T> &v){

    for (auto &it : v)

        cout << it << ' ';

    return ostream;

}



template <typename T>

vector<T> prefixsum(const vector<T> &a){

    int n = a.size();

    vector<T> psum(n, 0);

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

        psum[i] = psum[i - 1] + a[i];

    return psum;

}





void solve(){

    int n;

    cin >> n;

    vector<int> a(n);

    cin >> a;

    int idx = -1;

    if(a[0] < a[1]) {

        cout << "YES" << endl;

        return;

    }

    if(a[0] > a[1]){

        cout << "NO" << endl;

        return;

    }

    for(int i = 1; i < n; i++){

        if(a[0] == a[i]) idx = i;

        else break;

    }

    // cout << idx << endl;

    if(idx == -1 || idx == n-1 || a[idx+1] < a[idx+2]) cout << "YES" << endl;

    else cout << "NO" << endl;

}



int32_t main(){



    ios::sync_with_stdio(false);

    cin.tie(nullptr);



#ifndef ONLINE_JUDGE

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

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

#endif



    int t;

    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



#define all(a) a.begin(), a.end()

#define pb push_back

#define yes cout << "Yes\n"

#define no cout << "No\n"

#define F first

#define S second



const int MOD = 1e9 + 7;



template <typename T>

istream &operator>>(istream &istream, vector<T> &v){

    for (auto &it : v)

        cin >> it;

    return istream;

}

template <typename T>

ostream &operator<<(ostream &ostream, vector<T> &v){

    for (auto &it : v)

        cout << it << ' ';

    return ostream;

}



template <typename T>

vector<T> prefixsum(const vector<T> &a){

    int n = a.size();

    vector<T> psum(n, 0);

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

        psum[i] = psum[i - 1] + a[i];

    return psum;

}





void solve(){

    int n;

    cin >> n;

    vector<int> a(n);

    cin >> a;

    int idx = 0;

    if(a[0] < a[1]) {

        cout << "YES" << endl;

        return;

    }

    if(a[0] > a[1]){

        cout << "NO" << endl;

        return;

    }

    for(int i = 1; i < n; i++){

        if(a[i-1] > a[i]) idx = i;

    }

    for(int i = 0; i < idx; i++){

        int mini = min(a[i], a[i+1]);

        a[i] -= mini;

        a[i+1] -= mini;

    }

    cout << (is_sorted(all(a)) ? "YES" : "NO") << endl;

}



int32_t main(){



    ios::sync_with_stdio(false);

    cin.tie(nullptr);



#ifndef ONLINE_JUDGE

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

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

#endif



    int t;

    cin >> t;



    while (t--)

        solve();



    return 0;

}