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 size_t long long

#define double long double



#define el cout << "\n"

const int M = 1000000007;

const int mod = 998244353;

#define YES cout << "YES"

#define Yes cout << "Yes"

#define NO cout << "NO"

#define No cout << "No"



#define vi vector<int>

#define pii pair<int,int>

#define vii vector<pair<int, int> >

#define vv vector<vector<int>>

#define vv2d(row, col, name) vector<vector<int>> name(row, vector<int>(col))

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



#ifdef CPH

#define debug(x) cout << #x << " = " << x << '\n';

#define vdebug(a) cout << #a << " = "; for(auto x: a) cout << x << ' '; cout << '\n';

#else

#define debug(x)

#define vdebug(a)

#endif



int binMultiply(int a, int b) {

int ans = 0;

while (b) {

if (b & 1)

ans = (ans + a) % M;

b >>= 1;

a = (a + a) % M;

}

return ans;

}



int largeBinExpo(int a, int b, int M) {

a = a % M;

int ans = 1;

while (b) {

if (b & 1)

ans = binMultiply(ans, a);

b >>= 1;

a = binMultiply(a, a);

}

return ans;

}

int binPow(int a, int b, int M) {

int ans = 1;

while (b) {

if (b & 1)

ans = (ans * 1ll * a) % M;

a = (a * 1ll * a) % M;

b >>= 1;

}

return ans;

}



signed main() {

ios_base::sync_with_stdio(false);

cin.tie(NULL);

int t = 1;

cin >> t;

while (t--) {

int n;

cin >> n;

n++;

vi v(n);

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

{

cin >> v[i];

}

bool ok = true;

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

{

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

if (v[i] - v[i + 1] <= v[i - 1] - v[i - 2]) {

v[i] -= (v[i - 1] - v[i - 2]);

v[i - 1] = 0;

}

else {

ok = !ok;

break;

}

}

}



if (ok)YES;else NO;



cout << "\n";

}

}

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

using namespace std;



#define int long long

#define size_t long long

#define double long double



#define el cout << "\n"

const int M = 1000000007;

const int mod = 998244353;

#define YES cout << "YES"

#define Yes cout << "Yes"

#define NO cout << "NO"

#define No cout << "No"



#define vi vector<int>

#define pii pair<int,int>

#define vii vector<pair<int, int> >

#define vv vector<vector<int>>

#define vv2d(row, col, name) vector<vector<int>> name(row, vector<int>(col))

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



#ifdef CPH

#define debug(x) cout << #x << " = " << x << '\n';

#define vdebug(a) cout << #a << " = "; for(auto x: a) cout << x << ' '; cout << '\n';

#else

#define debug(x)

#define vdebug(a)

#endif



int binMultiply(int a, int b) {

int ans = 0;

while (b) {

if (b & 1)

ans = (ans + a) % M;

b >>= 1;

a = (a + a) % M;

}

return ans;

}



int largeBinExpo(int a, int b, int M) {

a = a % M;

int ans = 1;

while (b) {

if (b & 1)

ans = binMultiply(ans, a);

b >>= 1;

a = binMultiply(a, a);

}

return ans;

}

int binPow(int a, int b, int M) {

int ans = 1;

while (b) {

if (b & 1)

ans = (ans * 1ll * a) % M;

a = (a * 1ll * a) % M;

b >>= 1;

}

return ans;

}



signed main() {

ios_base::sync_with_stdio(false);

cin.tie(NULL);

int t = 1;

cin >> t;

while (t--) {

int n;

cin >> n;

n++;

vi v(n);

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

{

cin >> v[i];

}

bool ok = true;

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

{

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

if (v[i] - v[i + 1] <= v[i - 1] - v[i - 2]) {

v[i] -= (v[i - 1] - v[i - 2]);

v[i - 1] = 0;

v[i - 2] = 0;

}

else {

ok = !ok;

break;

}

}

}



if (ok)YES;else NO;



cout << "\n";

}

}