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;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

template <typename T>
using ordered_set =
    __gnu_pbds::tree<T, __gnu_pbds::null_type, less<T>, __gnu_pbds::rb_tree_tag,
                     __gnu_pbds::tree_order_statistics_node_update>;
using pi = pair<int32_t, int32_t>;
using pl = pair<long long, long long>;
using vi = vector<int32_t>;
using vl = vector<long long>;
using vvi = vector<vector<int32_t>>;
using vvl = vector<vector<long long>>;
using vpi = vector<pair<int32_t, int32_t>>;
using vpl = vector<pair<long long, long long>>;
using vvpi = vector<vector<pair<int32_t, int32_t>>>;
using vvpl = vector<vector<pair<long long, long long>>>;
using vb = vector<bool>;
using vs = vector<string>;
using mpl = map<long long, long long>;
using mpi = map<int32_t, int32_t>;

#define fori(i, a, b) for (int i = a; i < b; ++i)
#define fore(i, a, b) for (int i = a; i <= b; ++i)
#define forr(i, a, b) for (int i = a - 1; i >= b; --i)

#define pb push_back
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define sz(x) (int32_t)x.size()
#define yes (void)(cout << "YES\n")
#define no (void)(cout << "NO\n")
#define approx(a) fixed << setprecision(a)
#define ff first
#define ss second
#define INF LONG_LONG_MAX
#define INFF LONG_LONG_MIN
#define inf INT_MAX
#define inff INT_MIN
#define nl '\n'

template <class T> void read(vector<T> &v);
template <class F, class S> void read(pair<F, S> &p);
template <class T, size_t Z> void read(array<T, Z> &a);
template <class T> void read(T &x) {
  cin >> x;
}
template <class R, class... T> void read(R &r, T &...t) {
  read(r);
  read(t...);
};
template <class T> void read(vector<T> &v) {
  for (auto &x : v)
    read(x);
}
template <class F, class S> void read(pair<F, S> &p) {
  read(p.ff, p.ss);
}
template <class T, size_t Z> void read(array<T, Z> &a) {
  for (auto &x : a)
    read(x);
}

template <class F, class S> void pr(const pair<F, S> &x);
template <class T> void pr(const T &x) {
  cout << x;
}
template <class R, class... T> void pr(const R &r, const T &...t) {
  pr(r);
  pr(t...);
}
template <class F, class S> void pr(const pair<F, S> &x) {
  pr("{", x.ff, ", ", x.ss, "}");
}
void ps() {
  pr("\n");
}
template <class T> void ps(const T &x) {
  pr(x);
  ps();
}
template <class T> void ps(vector<T> &v) {
  for (auto &x : v)
    pr(x, ' ');
  ps();
}
template <class T, size_t Z> void ps(const array<T, Z> &a) {
  for (auto &x : a)
    pr(x, ' ');
  ps();
}
template <class F, class S> void ps(const pair<F, S> &x) {
  pr(x.ff, ' ', x.ss);
  ps();
}
template <class R, class... T> void ps(const R &r, const T &...t) {
  pr(r, ' ');
  ps(t...);
}
#define definp()                                                               \
  int n;                                                                       \
  read(n);                                                                     \
  vl a(n);                                                                     \
  read(a);
#define int long long

// int dx[4] = {-1, 1, -1, 1}, dy[4] = {-1, -1, 1, 1};
#define MOD (long long)(998244353)
void exec_once() {
}

void solve(int tn [[maybe_unused]]) {
  definp();
  for (int i = 0; i < n; i += 2) {
    if (i != n - 1 && a[i] > a[i + 1])
      return no;
    if (i == n - 1) {
      if (a[i - 1] > a[i])
        return no;
    }
  }
  return yes;
}

bool tc = 1;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  exec_once();
  int32_t t = 1;
  if (tc)
    cin >> t;
  fore(tn, 1, t) solve(tn);
  return 0;
}


Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

template <typename T>
using ordered_set =
    __gnu_pbds::tree<T, __gnu_pbds::null_type, less<T>, __gnu_pbds::rb_tree_tag,
                     __gnu_pbds::tree_order_statistics_node_update>;
using pi = pair<int32_t, int32_t>;
using pl = pair<long long, long long>;
using vi = vector<int32_t>;
using vl = vector<long long>;
using vvi = vector<vector<int32_t>>;
using vvl = vector<vector<long long>>;
using vpi = vector<pair<int32_t, int32_t>>;
using vpl = vector<pair<long long, long long>>;
using vvpi = vector<vector<pair<int32_t, int32_t>>>;
using vvpl = vector<vector<pair<long long, long long>>>;
using vb = vector<bool>;
using vs = vector<string>;
using mpl = map<long long, long long>;
using mpi = map<int32_t, int32_t>;

#define fori(i, a, b) for (int i = a; i < b; ++i)
#define fore(i, a, b) for (int i = a; i <= b; ++i)
#define forr(i, a, b) for (int i = a - 1; i >= b; --i)

#define pb push_back
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define sz(x) (int32_t)x.size()
#define yes (void)(cout << "YES\n")
#define no (void)(cout << "NO\n")
#define approx(a) fixed << setprecision(a)
#define ff first
#define ss second
#define INF LONG_LONG_MAX
#define INFF LONG_LONG_MIN
#define inf INT_MAX
#define inff INT_MIN
#define nl '\n'

template <class T> void read(vector<T> &v);
template <class F, class S> void read(pair<F, S> &p);
template <class T, size_t Z> void read(array<T, Z> &a);
template <class T> void read(T &x) {
  cin >> x;
}
template <class R, class... T> void read(R &r, T &...t) {
  read(r);
  read(t...);
};
template <class T> void read(vector<T> &v) {
  for (auto &x : v)
    read(x);
}
template <class F, class S> void read(pair<F, S> &p) {
  read(p.ff, p.ss);
}
template <class T, size_t Z> void read(array<T, Z> &a) {
  for (auto &x : a)
    read(x);
}

template <class F, class S> void pr(const pair<F, S> &x);
template <class T> void pr(const T &x) {
  cout << x;
}
template <class R, class... T> void pr(const R &r, const T &...t) {
  pr(r);
  pr(t...);
}
template <class F, class S> void pr(const pair<F, S> &x) {
  pr("{", x.ff, ", ", x.ss, "}");
}
void ps() {
  pr("\n");
}
template <class T> void ps(const T &x) {
  pr(x);
  ps();
}
template <class T> void ps(vector<T> &v) {
  for (auto &x : v)
    pr(x, ' ');
  ps();
}
template <class T, size_t Z> void ps(const array<T, Z> &a) {
  for (auto &x : a)
    pr(x, ' ');
  ps();
}
template <class F, class S> void ps(const pair<F, S> &x) {
  pr(x.ff, ' ', x.ss);
  ps();
}
template <class R, class... T> void ps(const R &r, const T &...t) {
  pr(r, ' ');
  ps(t...);
}
#define definp()                                                               \
  int n;                                                                       \
  read(n);                                                                     \
  vl a(n);                                                                     \
  read(a);
#define int long long

// int dx[4] = {-1, 1, -1, 1}, dy[4] = {-1, -1, 1, 1};
#define MOD (long long)(998244353)
void exec_once() {
}

void solve(int tn [[maybe_unused]]) {
  definp();
  fori(i, 0, n - 1) {
    int mn = min(a[i], a[i + 1]);
    a[i + 1] -= mn;
    a[i] -= mn;
    if (a[i] > a[i + 1]) {
      // ps(a);
      return no;
    }
  }
  return yes;
}

bool tc = 1;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  exec_once();
  int32_t t = 1;
  if (tc)
    cin >> t;
  fore(tn, 1, t) solve(tn);
  return 0;
}