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;



// Header files, namespaces,

// macros as defined above

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;



#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>



using ll = long long;

using ull = unsigned long long;



#define pb(v) push_back(v)

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

#define rall(v) (v).rbegin(), (v).rend()

#define MSET(c, v) memset(c, v, sizeof(c))

#define debug(x) cout << #x << " is " << x << endl



const int NEGINF = 0xC0C0C0C0;

const int NULO = -1;

const double EPS = 1e-10;

const ll mod = 1e9 + 7;

const ll llInf = 4e17;

const int inf = 2e9;



int dy[] = {0,1,-1,0};

int dx[] = {1,0,0,-1};



template <typename T,typename U>

std::pair<T,U> operator+(const std::pair<T,U> & l,const std::pair<T,U> & r) {

return {l.first+r.first,l.second+r.second};

}



const int maxn = 2e5 + 100;



ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }



int a[maxn];

void solveTestCase(int test) {



int n;

cin >> n;

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

cin >> a[i];

}

int last = a[n];

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

if(a[i] > last) {

if(a[i] > a[i + 1]) {

cout << "NO" << endl;

return;

} else {

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

a[i] = 0;

//cout << a[i] << " " << a[i + 1] << endl;

}

}

}

cout << "YES" << endl;

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

//     cout << a[i] << " ";

// }

// cout << endl;

}



int main() {

ios::sync_with_stdio(false);

int test = 1;

cin >> test;

for (int t = 1; t <= test; t++) {

solveTestCase(t);

}



return 0;

}

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

using namespace std;



// Header files, namespaces,

// macros as defined above

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;



#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>



using ll = long long;

using ull = unsigned long long;



#define pb(v) push_back(v)

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

#define rall(v) (v).rbegin(), (v).rend()

#define MSET(c, v) memset(c, v, sizeof(c))

#define debug(x) cout << #x << " is " << x << endl



const int NEGINF = 0xC0C0C0C0;

const int NULO = -1;

const double EPS = 1e-10;

const ll mod = 1e9 + 7;

const ll llInf = 4e17;

const int inf = 2e9;



int dy[] = {0,1,-1,0};

int dx[] = {1,0,0,-1};



template <typename T,typename U>

std::pair<T,U> operator+(const std::pair<T,U> & l,const std::pair<T,U> & r) {

return {l.first+r.first,l.second+r.second};

}



const int maxn = 2e5 + 100;



ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }



int a[maxn];

void solveTestCase(int test) {



int n;

cin >> n;

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

cin >> a[i];

}

int last = a[n];

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

if(a[i] > a[i + 1]) {

cout << "NO" << endl;

return;

} else {

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

a[i] = 0;

//cout << a[i] << " " << a[i + 1] << endl;

}

}

cout << "YES" << endl;

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

//     cout << a[i] << " ";

// }

// cout << endl;

}



int main() {

ios::sync_with_stdio(false);

int test = 1;

cin >> test;

for (int t = 1; t <= test; t++) {

solveTestCase(t);

}



return 0;

}