Problem: 2060D - Subtract Min Sort
Language: c++17 

Solution 1 (runtime: 109 ms):
#include <bits/stdc++.h>

using namespace std;

#define ll long long

auto init = []()

{

  ios::sync_with_stdio(0);

  cin.tie(0);

  cout.tie(0);

  return 'c';

}();

bool check(vector<int> arr)

{

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

  {

    if (arr[i - 1] > arr[i])

      return false;

  }

  return true;

}

void solve()

{

  int n;

  cin >> n;

  vector<int> v(n);

  for (auto &x : v)

  {

    cin >> x;

  }

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

  {

    int k = min(v[i], v[i - 1]);

    v[i] -= k;

    v[i - 1] -= k;

  }

    if (check(v))

    {

      cout << "Yes" << endl;

      return;

    }

  else{

    cout<<"No"<<endl;

  }

}



int main()

{

  int t;

  cin >> t;

  while (t--)

  {

    solve();

  }

}

Solution 2 (runtime: 124 ms):
#include <bits/stdc++.h>

using namespace std;



#define PI (3.141592653589)

#define M 1000000007

#define pb push_back

#define f first

#define s second

#define rep(i,j) for(int i = 0; i<j; i++)

#define rrep(i,j) for(int i = j; i>=0; i--)

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

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

#define sz(x) (ll)(x.size())

#define out(x) cout << x << endl;

#define YES cout<<"YES"<<endl

#define NO cout<<"NO"<<endl

#define pm cout<<"-1"<<endl

#define nl "\n"



typedef long long ll;

typedef pair<int, int> pi;

typedef pair<ll, ll> pl;

typedef vector<int> vi;

typedef vector<ll> vl;

typedef vector<pi> vpi;

typedef vector<pl> vpl;

typedef vector<vi> vvi;

typedef vector<vl> vvl;

typedef map<int,int> mii;

typedef pair<ll,ll> pll;



#ifdef localenv

#define debug(x) _print(x); cerr << endl;

#else

#define debug(x)

#endif



template <class T, class V> void _print(pair <T, V> p);

template <class T> void _print(vector <T> v);

template <class T> void _print(set <T> v);

template <class T> void _print(multiset <T> v);

template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.f); cerr << ","; _print(p.s);cerr << "}";}

template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr <<"]";}

template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}

template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr <<"]";}

template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << "";} cerr << "]";}



// Operator Overloads

template<typename T> // cin >> vector<T>

istream& operator>>(istream &istream, vector<T> &v){for (auto &it : v)cin >> it;return istream;}

template<typename T> // cout << vector<T>

ostream& operator<<(ostream &ostream, const vector<T> &c) { for (auto &it : c) cout << it << " ";return ostream; }



// Utility Functions

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

ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

ll mod_exp(ll a, ll b, ll m) { ll res = 1; while (b) { if (b & 1) res = (res * a) % m; a = (a * a) % m; b >>= 1; } return res; }

bool is_prime(ll n) { if (n < 2) return false; for (ll i = 2; i * i <= n; i++) if (n % i == 0) return false; return true; }

vector<ll> sieve(ll n) { vector<ll> primes, is_prime(n + 1, 1); is_prime[0] = is_prime[1] = 0; for (ll i = 2; i <= n; i++) { if (is_prime[i]) { primes.pb(i); for (ll j = i * i; j <= n; j += i) is_prime[j] = 0; } } return primes; }



// BFS Implementation

void bfs(int start, const vector<vector<int>>& adj, vector<bool>& visited) {

queue<int> q;

q.push(start);

visited[start] = true;

while (!q.empty()) {

int node = q.front();

q.pop();

// Process node

for (int neighbor : adj[node]) {

if (!visited[neighbor]) {

visited[neighbor] = true;

q.push(neighbor);

}

}

}

}



// DFS Implementation

void dfs(int node, const vector<vector<int>>& adj, vector<bool>& visited) {

visited[node] = true;

// Process node

for (int neighbor : adj[node]) {

if (!visited[neighbor]) {

dfs(neighbor, adj, visited);

}

}

}



// DSU Implementation

struct DSU {

vector<int> parent, rank;



DSU(int n) {

parent.resize(n);

rank.resize(n, 0);

for (int i = 0; i < n; i++) parent[i] = i;

}



int find(int x) {

if (parent[x] != x) parent[x] = find(parent[x]);

return parent[x];

}



void unite(int x, int y) {

int rootX = find(x);

int rootY = find(y);

if (rootX != rootY) {

if (rank[rootX] > rank[rootY]) {

parent[rootY] = rootX;

} else if (rank[rootX] < rank[rootY]) {

parent[rootX] = rootY;

} else {

parent[rootY] = rootX;

rank[rootX]++;

}

}

}

};



void solve(){

ll n; cin >> n;

vl v(n); cin >> v;

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

ll mini = min(v[i - 1], v[i]);

v[i - 1] -= mini;

v[i] -= mini;

}

if(is_sorted(all(v)))

YES;

else

NO;

}



int32_t main()

{

ios_base::sync_with_stdio(false);

cin.tie(NULL);

cout.tie(NULL);

int t = 1;

cin>>t;

while(t--)

{

solve();

}

return 0;

}