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

Previous submission (verdict: Wrong answer on test 2):
// Aur Bhai Dekhne aagaye ;)

// Author: Parul(OG)

#include <bits/stdc++.h>

using namespace std;

#define pi (3.141592653589)

#define mod 1000000007

#define inp(x) \

int x;     \

cin >> x;

#define pb push_back

#define scanarr                 \

int arr[n];                 \

for (int i = 0; i < n; i++) \

cin >> arr[i]

#define pb push_back

#define is insert

#define fre(i, b) for (int i = 0; i < (int)(b); i++)

#define mp make_pair

#define ff first

#define ss second

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

#define min3(a, b, c) min(c, min(a, b))

#define min4(a, b, c, d) min(d, min(c, min(a, b)))

#define inpvi(n) \

vi a(n);     \

fr(n) { cin >> a[i]; }

#define rfr(n) for (int i = n - 1; i >= 0; i--)

#define rep1(i, a, b) for (long long i = a; i <= b; i++)

#define fr(n) for (long long i = 0; i < n; i++)

#define fr1(n) for (long long i = 1; i < n; i++)

#define nesfr(x, y)                   \

for (long long i = 0; i < x; i++) \

for (long long j = 0; j < y; j++)

#define rep(i, a, b) for (long long i = a; i < b; i++)

#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

typedef long long int ll;

typedef long double ld;

typedef vector<ll> vi;

typedef vector<pair<ll, ll>> vip;

#define nl cout << "\n"

const unsigned int M = 1000000007;

const int N = 2e5 + 5;



void solve()

{

int n;

cin >> n;



inpvi(n);



bool possi = true;



if (n > 2)

{

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



{

if (a[i - 1] > a[i] && a[i] > a[i + 1])

{

possi = false;

}

}

}

else

{

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

{

possi = false;

}

}



if (possi)

{

cout << "YES" << endl;

}

else

{

cout << "NO" << endl;

}

}



int main()

{

fast;

ll t = 1;

cin >> t;

while (t--)

{

solve();

}

return 0;

}



Submission (verdict: Accepted):
// Aur Bhai Dekhne aagaye ;)

// Author: Parul(OG)

#include <bits/stdc++.h>

using namespace std;

#define pi (3.141592653589)

#define mod 1000000007

#define inp(x) \

int x;     \

cin >> x;

#define pb push_back

#define scanarr                 \

int arr[n];                 \

for (int i = 0; i < n; i++) \

cin >> arr[i]

#define pb push_back

#define is insert

#define fre(i, b) for (int i = 0; i < (int)(b); i++)

#define mp make_pair

#define ff first

#define ss second

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

#define min3(a, b, c) min(c, min(a, b))

#define min4(a, b, c, d) min(d, min(c, min(a, b)))

#define inpvi(n) \

vi a(n);     \

fr(n) { cin >> a[i]; }

#define rfr(n) for (int i = n - 1; i >= 0; i--)

#define rep1(i, a, b) for (long long i = a; i <= b; i++)

#define fr(n) for (long long i = 0; i < n; i++)

#define fr1(n) for (long long i = 1; i < n; i++)

#define nesfr(x, y)                   \

for (long long i = 0; i < x; i++) \

for (long long j = 0; j < y; j++)

#define rep(i, a, b) for (long long i = a; i < b; i++)

#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

typedef long long int ll;

typedef long double ld;

typedef vector<ll> vi;

typedef vector<pair<ll, ll>> vip;

#define nl cout << "\n"

const unsigned int M = 1000000007;

const int N = 2e5 + 5;



void solve()

{

int n;

cin >> n;



inpvi(n);



bool possi = true;

/*

if (n > 2)

{

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



{

if (a[i - 1] > a[i] && a[i] > a[i + 1])

{

possi = false;

}

}

}

else

{

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

{

possi = false;

}

}

*/

fr(n-1){

if(a[i]<=a[i+1]){

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

a[i]=0;

}



}

fr1(n){

if(a[i]<a[i-1]){

possi =false;

}

}

if (possi)

{

cout << "YES" << endl;

}

else

{

cout << "NO" << endl;

}

}



int main()

{

fast;

ll t = 1;

cin >> t;

while (t--)

{

solve();

}

return 0;

}