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;

typedef long long ll;

typedef long double ld;

typedef vector<int> vi;

typedef set<int> si;

typedef pair<int, int> pi;

typedef map<int, int> mi;

#define endl "\n"

#define nl cout << "\n"

#define loopf(i, a, b) for (int i = a; i < b; i++)

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

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

#define ANS cout << ans << "\n"

#define read(v)                             \

    for (int i = 0; i < (int)v.size(); ++i) \

    cin >> v[i]

#define read1(v)                            \

    for (int i = 1; i < (int)v.size(); ++i) \

    cin >> v[i]

#define print(v)                                \

    {                                           \

        for (int i = 0; i < (int)v.size(); ++i) \

            cout << v[i] << " ";                \

        nl;                                     \

    }

#define F first

#define S second

#define PB push_back

#define MP make_pair

#define bits(x) __builtin_popcountll(x)

#define minvec(a) *min_element(all(a))

#define maxvec(a) *max_element(all(a))

const ll mod = 1e9 + 7;

const ll mod1 = 998244353;

const ld pie = 3.141592653589793238;



void solve()

{

    int n;

    cin >> n;

    vi a(n);

    read(a);



    if (is_sorted(a.begin(), a.end()))

    {

        yes return;

    }

    if (is_sorted(a.rbegin(), a.rend()))

    {

        no return;

    }



    int d = a[1] - a[0];

    bool possible = true;



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

    {

        if (a[i] < d)

        {

            possible = false;

            break;

        }



        d = a[i] - d;

    }



    if (possible)

        yes else no

}



int main()

{

    int t;

    cin >> t;

    while (t--)

    {

        solve();

    }



    return 0;

}

Submission (verdict: Wrong answer on test 21):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef long double ld;

typedef vector<int> vi;

typedef set<int> si;

typedef pair<int, int> pi;

typedef map<int, int> mi;

#define endl "\n"

#define nl cout << "\n"

#define loopf(i,a,b) for(int i=a;i<b;i++)

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

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

#define ANS cout<<ans<<"\n"

#define read(v) for(int i=0;i<(int)v.size();++i) cin>>v[i]

#define read1(v) for(int i=1;i<(int)v.size();++i) cin>>v[i]

#define print(v) {for(int i=0;i<(int)v.size();++i)cout<<v[i]<<" ";nl;}

#define F first

#define S second

#define PB push_back

#define MP make_pair

#define bits(x) __builtin_popcountll(x)

#define minvec(a) *min_element(all(a))

#define maxvec(a) *max_element(all(a))

const ll mod = 1e9+7;

const ll mod1 = 998244353;

const ld pie = 3.141592653589793238;



void solve()

{

    int n;  cin>>n;

    vector<ll> a(n);    read(a);



    if(is_sorted(a.begin(), a.end())){

        yes return;

    }

    if(is_sorted(a.rbegin(), a.rend())){

        no return;

    }

    

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

        ll dec= min(a[i], a[i+1]);

        a[i]-= dec;

        a[i+1]-= dec;

    }



    if(is_sorted(a.begin(), a.end()))

        yes

    else

        no

}



int main()

{

    int t; cin>>t; 

    while(t--){

        solve();

    }



    return 0;

}