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

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



using namespace std;

using ll = long long;

typedef vector<int> vi;

typedef vector<ll> vll;



#define srt(a) sort(a.begin(), a.end());

#define vin(a,n) for(int i = 0; i < n; i++){cin >> a[i];};

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

#define pb push_back

#define mp make_pair

#define wut 1000000007

#define out(x) cout << x << "\n";

#define each(it, v) for(auto &it: v)



template<typename T>

void vout(const vector<T>& vec) {

for(const auto& it : vec) {

cout << it << " ";

}

cout << endl;

}



template <typename T>

istream& operator>>(istream& in, vector<T>& vec) {

for (auto& element : vec) {

in >> element;

}

return in;

}





ll gcd(ll a, ll b) {

while (b != 0) {

ll temp = b;

b = a % b;

a = temp;

}

return a;

}

ll lcm(ll a, ll b) {

return (a / gcd(a, b)) * b;

}





// const ll MAXN = 1e6;

// vector<ll> adj[MAXN];    // Adjacency list

// vector<bool> visited(MAXN, false);



// void dfs(ll node, vector<ll> &component) {

//     // to add nodes

//     // adj[u].push_back(v);

//     // adj[v].push_back(u); // for undirected graph

//     visited[node] = true;

//     component.pb(node);



//     for (ll neighbor : adj[node]) {

//         if (!visited[neighbor]) {

//             dfs(neighbor, component);

//         }

//     }

// }



/*

DO NOT TOUCH ABOVE THIS

*/



void solve(){

ll n; cin >> n;

vll a(n);

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

{

cin >> a[i];

}

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

{

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

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

a[i] = 0;

}

}

// vout(a);

int c = 0;

for(auto it: a) {

if(!it) c++;

}

if(c >= n-1) {

cout << "YES\n";

} else {

cout << "NO\n";

}







}



int main(){

std::ios_base::sync_with_stdio(false);

std::cin.tie(nullptr);

int t = 1;

cin >> t;

while (t--)

{

solve();

}



}





Submission (verdict: Accepted):
#include <bits/stdc++.h>



using namespace std;

using ll = long long;

typedef vector<int> vi;

typedef vector<ll> vll;



#define srt(a) sort(a.begin(), a.end());

#define vin(a,n) for(int i = 0; i < n; i++){cin >> a[i];};

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

#define pb push_back

#define mp make_pair

#define wut 1000000007

#define out(x) cout << x << "\n";

#define each(it, v) for(auto &it: v)



template<typename T>

void vout(const vector<T>& vec) {

for(const auto& it : vec) {

cout << it << " ";

}

cout << endl;

}



template <typename T>

istream& operator>>(istream& in, vector<T>& vec) {

for (auto& element : vec) {

in >> element;

}

return in;

}





ll gcd(ll a, ll b) {

while (b != 0) {

ll temp = b;

b = a % b;

a = temp;

}

return a;

}

ll lcm(ll a, ll b) {

return (a / gcd(a, b)) * b;

}





// const ll MAXN = 1e6;

// vector<ll> adj[MAXN];    // Adjacency list

// vector<bool> visited(MAXN, false);



// void dfs(ll node, vector<ll> &component) {

//     // to add nodes

//     // adj[u].push_back(v);

//     // adj[v].push_back(u); // for undirected graph

//     visited[node] = true;

//     component.pb(node);



//     for (ll neighbor : adj[node]) {

//         if (!visited[neighbor]) {

//             dfs(neighbor, component);

//         }

//     }

// }



/*

DO NOT TOUCH ABOVE THIS

*/



void solve(){

ll n; cin >> n;

vll a(n);

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

{

cin >> a[i];

}

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

{

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

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

a[i] = 0;

}

// vout(a);

}

int c = 0;

for(auto it: a) {

if(!it) c++;

}

if(is_sorted(all(a))) {

cout << "YES\n";

} else {

cout << "NO\n";

}







}



int main(){

std::ios_base::sync_with_stdio(false);

std::cin.tie(nullptr);

int t = 1;

cin >> t;

while (t--)

{

solve();

}



}