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

Code 1:
// Problem: D. Subtract Min Sort
// Contest: Codeforces - Codeforces Round 998 (Div. 3)
// URL: https://codeforces.com/problemset/problem/2060/D
// Memory Limit: 256 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;

#define int long long
// #define ll long long
#define ld long double
#define lld long long double

/////////////////////////////////////////////////////////////////////////////////////

#define debug(x)     \
  cout << #x << " "; \
  _print(x);         \
  cout << en;

void _print(int x) { cout << x; }

void _print(char x) { cout << x; }

void _print(string s) { cout << s; }

void _print(bool a) { cout << a; }

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, class V>
void _print(map<T, V> v);
template <class T>
void _print(multiset<T> v);
template <class T, class V>
void _print(pair<T, V> p) {
  cout << "{";
  _print(p.first);
  cout << ",";
  _print(p.second);
  cout << "}";
}
template <class T>
void _print(vector<T> v) {
  cout << "[ ";
  for (T i : v) {
    _print(i);
    cout << " ";
  }
  cout << "]";
}

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

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

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

///////////////////////////////////////////////////////////////////

// #define int long long
// #define ld long double
// #define lld long long double
#define ff first
#define ss second
#define yes cout << "YES"
#define no cout << "NO"
#define fl(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vs vector<string>
#define vpii vector<pair<int, int>>
#define mii map<int, int>
#define pb push_back
#define ppb push_back
#define div(a, b) (a) / (b)
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define ceil(a, b) (a + b - 1) / b
#define input(a, n) fl(i, 1, n) cin >> a[i]
#define intake(a, n) \
  int n;             \
  cin >> n;          \
  vector<int> a(n);  \
  for (int i = 0; i < n; i++) cin >> a[i]
#define intake2(a, n, k) \
  int n, k;              \
  cin >> n >> k;         \
  vector<int> a(n);      \
  for (int i = 0; i < n; i++) cin >> a[i]
#define fast                        \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);                    \
  cout.tie(NULL)
#define pq priority_queue
#define out(a)                                            \
  for (int i = 0; i < a.size(); i++) cout << a[i] << " "; \
  cout << "\n"
#define en "\n"
// #define sp <<" "
#define sorti(a) sort(a.begin(), a.end())
#define sortd(a) sort(a.rbegin(), a.rend())
#define get_sum(a) accumulate(a.begin(), a.end(), 0LL)
#define get_max(a) *max_element(a.begin(), a.end())
#define get_min(a) *min_element(a.begin(), a.end())
#define get_max_pos(v) max_element(v.begin(), v.end()) - v.begin()
#define get_min_pos(v) min_element(v.begin(), v.end()) - v.begin()
#define sz(x) ((int)(x).size())
#define setbits(x) __builtin_popcountll(x)
const int modd = 1000000007;
const ld eps = 1e-6, pi = 3.14159265358979323846264338327950;

int gcd(int a, int b) { return __gcd(a, b); }

int binexpo(int a, int b, int mod) {
  int res = 1;
  while (b > 0) {
    if (b & 1) res = (res * a) % mod;
    a = (a * a) % mod;
    b = b >> 1;
  }
  return res;
}

int Find_gcd_Extended(int a, int b, int* x, int* y) {
  // Base Case
  if (a == 0) {
    *x = 0, *y = 1;
    return b;
  }

  // Storing results of recursive call
  int x1, y1;
  int gcd = Find_gcd_Extended(b % a, a, &x1, &y1);

  /*
    After recursive call, update the values
    of x and y
  */
  *x = y1 - (b / a) * x1;
  *y = x1;

  return gcd;
}

int modinv(int a, int m) {
  int x, y;
  int g = Find_gcd_Extended(a, m, &x, &y);

  /*
    If the gcd value doesn't matches
    to 1, then inverse doesn't exist
  */
  if (g != 1) {
    return -1;
    // cout << "sdf";
  } else {
    /*
      m is added once more to handle
      negative values
    */
    int res = (x % m + m) % m;
    // cout<<res<<endl;
    return res;
  }
}

// --------Sieve-------
// if isPrime[i] if true then, i is a prime number
vector<bool> isPrime(1000001);
void sieve() {
  for (int i = 0; i <= 1000001; i++) {
    isPrime[i] = 1;
  }
  isPrime[0] = isPrime[1] = 0;

  for (int i = 2; i * i <= 1000000; i++) {
    if (isPrime[i] == true) {
      for (int j = i * i; j <= 1000000; j += i) {
        isPrime[j] = false;
      }
    }
  }
}

//-----spf------
// SPF[i] => smallest prime number that divides i

vector<int> spf(1000001);
void findspf() {
  for (int i = 0; i <= 1e6; i++) {
    spf[i] = i;
  }

  for (int i = 2; i * i <= 1e6; i++) {
    if (spf[i] == i) {
      for (int j = i * i; j <= 1e6; j += i) {
        if (spf[j] == j) {
          spf[j] = i;
        }
      }
    }
  }
}

int madd(int a, int b, int m) {
  a = a % m;
  b = b % m;
  return (((a + b) % m + m) % m);
}

int mmul(int a, int b, int m) {
  a = a % m;
  b = b % m;
  return (((a * b) % m + m) % m);
}

int msub(int a, int b, int m) {
  a = a % m;
  b = b % m;
  return (((a - b) % m + m) % m);
}

int mdiv(int a, int b, int m) {
  a = a % m;
  b = b % m;
  return ((mmul(a, modinv(b, m), m) + m) % m);
}

// string hashing

pair<const int, const int> mod = {1e9 + 7, 1e9 + 9};
vector<pair<int, int>> pref_hash;
vector<pair<int, int>> power_pref;
void createHashfn(int n, string& s) {
  pref_hash.resize(n);
  power_pref.resize(n);
  pref_hash[0] = {s[0] - 'a' + 1, s[0] - 'a' + 1};
  power_pref[0] = {1, 1};
  for (int i = 1; i < n; i++) {
    pref_hash[i].first =
        (pref_hash[i - 1].first * (int)31 + (s[i] - 'a' + 1)) % mod.first;
    pref_hash[i].second =
        (pref_hash[i - 1].second * (int)53 + (s[i] - 'a' + 1)) % mod.second;

    power_pref[i].first = (power_pref[i - 1].first * (int)31) % mod.first;
    power_pref[i].second = (power_pref[i - 1].second * (int)53) % mod.second;
  }
}

auto subhash(int l, int r, string& s) {
  if (l == 0) return pref_hash[r];

  pair<int, int> sub_hash;
  sub_hash.first = ((pref_hash[r].first - (int)pref_hash[l - 1].first *
                                              power_pref[r - l + 1].first) %
                    mod.first);
  if (sub_hash.first < 0) sub_hash.first += mod.first;

  sub_hash.second = ((pref_hash[r].second - (int)pref_hash[l - 1].second *
                                                power_pref[r - l + 1].second) %
                     mod.second);
  if (sub_hash.second < 0) sub_hash.second += mod.second;
  return sub_hash;
}

//////////////////  DSU 1 BASED INDEXING /////////////////////////////
vector<int> par(2e5 + 1);
vector<int> rnk(2e5 + 1);
// intrnk[1e5];

void make_set(int n) {
  for (int i = 1; i < n + 1; i++) {
    par[i] = i;
    rnk[i] = 1;
  }
}

int find_set(int x) {
  if (par[x] == x) {
    return x;
  }

  par[x] = find_set(par[x]);

  return par[x];
}

void union_set(int a, int b) {
  int p1 = find_set(a);
  int p2 = find_set(b);

  if (p1 == p2) {
    return;
  }

  if (rnk[p1] > rnk[p2]) {
    par[p2] = p1;
    rnk[p1] = rnk[p1] + rnk[p2];
  } else {
    par[p1] = p2;
    rnk[p2] = rnk[p2] + rnk[p1];
  }
}
////////////////////DSU 1 BASED
/// INDEXING//////////////////////////////////////////////////

// x|(1<<k) : sets the kth bit
// x&~(1<<k): unsets the kth bit
// x^(1<<k) : inverts the kth bit

// gcd, binexpo, modinv, {sieve, isPrime}, {spf, findspf}
// madd, mmul, msub, mdiv

bool ipot(int x) { return (x != 0LL) && ((x & (x - 1LL)) == 0LL); }

// sometime think oppsite from output ----> input
const int MOD = 998244353;
void add(int& a, int b) {
  a += b;
  if (a >= MOD) a -= MOD;
}

int sum(int a, int b) {
  a += b;
  if (a >= MOD) a -= MOD;
  if (a < 0) a += MOD;
  return a;
}

int mul(int a, int b) { return (a * 1LL * b) % MOD; }

const int N = 2000005;
// const int mod = 1e9 + 7;
int fact[N], invfact[N];

void precompute() {
  fact[0] = fact[1] = 1;
  for (int i = 2; i < N; i++) {
    fact[i] = fact[i - 1] * i;
    fact[i] %= modd;
  }

  invfact[N - 1] = modinv(fact[N - 1], modd);
  for (int i = N - 2; i >= 0; i--) {
    invfact[i] = invfact[i + 1] * (i + 1);
    invfact[i] %= modd;
  }
}

int nCr(int x, int y) {
  if (y > x) return 0;
  int num = fact[x];
  num *= invfact[y];
  num %= modd;
  num *= invfact[x - y];
  num %= modd;
  return num;
}

vi binRep(int x) {
  vi v(32);
  for (int i = 29; i >= 0; i--) {
    v[i] = (x >= (1 << i));
    x %= (1 << i);
  }
  return v;
}

// RADHE RADHE

// vvi tree;
// vi vis, parent, depth;

//---------- max seg code ---- 0based indexing--------------//

const int MAXMAX = 2e5;  // Max size of array
int treemax[2 * MAXMAX];

// Function to build the tree
void buildmax(vector<int>& arr, int n) {
  for (int i = 0; i < n; i++) treemax[n + i] = arr[i];
  for (int i = n - 1; i > 0; --i)
    treemax[i] = max(treemax[i << 1], treemax[i << 1 | 1]);
}

// Function to update a tree node
void updatemax(int p, int value, int n) {
  treemax[p + n] = value;
  p = p + n;
  for (int i = p; i > 1; i >>= 1)
    treemax[i >> 1] = max(treemax[i], treemax[i ^ 1]);
}

// Function to get minimum value in a given range
// [l,r)
int querymax(int l, int r, int n) {
  int res = -1e18;
  for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l & 1) res = max(res, treemax[l++]);
    if (r & 1) res = max(res, treemax[--r]);
  }
  return res;
}

// array mein value ko dalne ke liye update ko call karna

//---------- max seg code ---- 0based indexing--------------//-------------//
//---------- min seg code ---- 0based indexing--------------//

const int MAXMIN = 2e5;  // Max size of array
int treemin[2 * MAXMIN];

// Function to build the tree
void buildmin(vector<int>& arr, int n) {
  for (int i = 0; i < n; i++) treemin[n + i] = arr[i];
  for (int i = n - 1; i > 0; --i)
    treemin[i] = min(treemin[i << 1], treemin[i << 1 | 1]);
}

// Function to update a tree node
void updatemin(int p, int value, int n) {
  treemin[p + n] = value;
  p = p + n;
  for (int i = p; i > 1; i >>= 1)
    treemin[i >> 1] = min(treemin[i], treemin[i ^ 1]);
}

// Function to get minimum value in a given range
// [l,r)
int querymin(int l, int r, int n) {
  int res = 1e18;
  for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l & 1) res = min(res, treemin[l++]);
    if (r & 1) res = min(res, treemin[--r]);
  }
  return res;
}

// array mein value ko dalne ke liye update ko call karna
////////////////////////////////////////////
//---------- min seg code ---- 0based indexing--------------//-------------//
///////////////////////////////////////

//////////////////////////////////////////////////////////////////
///////////////////////////BINARY INDEX TREE/////////////////////////////////
//////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////
//////////////////////BINARY INDEX TREE//////////////////////////////
///////////////////////////////////////////////////////////////////////////

// point update range min/max => seg tree
// point update range sum ==> Binary index tree

// for static
// range min/max/gcd/lcm/or/and ==> sparse table , query in O(1)
// range sum/xor ==> prefix sum

// range update , set ; range min/max/sum = lazy

// sparsetable code

// int n;
// cin >> n;
//
// vi a(n);
// fl(i, 0, n) cin >> a[i];
//
// int maxk = 25;
// int st[n + 1][maxk + 1];
//
// for (int i = 0; i < n; i++) {
// st[i][0] = a[i];
// }
//
// for (int k = 1; k <= maxk; k++) {
// for (int i = 0; i + (1 << k) <= n; i++) {
// st[i][k] = (st[i][k - 1] & st[i + (1 << (k - 1))][k - 1]);
// }
// }
//
// for (int i = 0; i < n; i++) {
// for (int j = 0; j < 4; j++) {
// cout << st[i][j] << " ";
// }
// cout << endl;
// }
//
// int l, r;
// cin >> l >> r;
// // int s = 0;
// // for (int k = maxk; k >= 0; k--) {
// // if ((1 << k) <= r - l + 1) {
// // s += st[l][k];
// // l += (1 << k);
// // }
// // }
// // cout << s;
//
// vi lg(n + 1);
// lg[1] = 0;
// for (int i = 2; i <= n; i++) {
// lg[i] = lg[i / 2] + 1;
// }
//
// int w = lg[r - l + 1];
// int ans = (st[l][w] & st[r - (1 << w) + 1][w]);
// cout << ans;

// sparsetable code

void solve() {
  int n;
  cin >> n;
  vi v(n);
  fl(i, 0, n) cin >> v[i];

  for (int i = 0; i < n - 1; i++) {
    int x = v[i];
    int y = v[i + 1];
    v[i] -= min(x, y);
    v[i + 1] -= min(x, y);
    // debug(v);
  }
  // debug(v);
  int f = 0;
  fl(i, 0, n - 1) {
    if (v[i] > 0) f = 1;
  }
  // debug(f);
  if (f) {
    cout << "NO";
  } else {
    cout << "YES";
  }
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  // // ----Atcode----
  // int q = 1;
  // // ----Atcode----
  // -----cf/cc----
  int q;
  cin >> q;
  //-----cf/cc----

  precompute();
  while (q--) {
    solve();
    cout << en;
  }
  return 0;
}


Code 2:
// Problem: D. Subtract Min Sort
// Contest: Codeforces - Codeforces Round 998 (Div. 3)
// URL: https://codeforces.com/problemset/problem/2060/D
// Memory Limit: 256 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;

#define int long long
// #define ll long long
#define ld long double
#define lld long long double

/////////////////////////////////////////////////////////////////////////////////////

#define debug(x)     \
  cout << #x << " "; \
  _print(x);         \
  cout << en;

void _print(int x) { cout << x; }

void _print(char x) { cout << x; }

void _print(string s) { cout << s; }

void _print(bool a) { cout << a; }

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, class V>
void _print(map<T, V> v);
template <class T>
void _print(multiset<T> v);
template <class T, class V>
void _print(pair<T, V> p) {
  cout << "{";
  _print(p.first);
  cout << ",";
  _print(p.second);
  cout << "}";
}
template <class T>
void _print(vector<T> v) {
  cout << "[ ";
  for (T i : v) {
    _print(i);
    cout << " ";
  }
  cout << "]";
}

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

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

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

///////////////////////////////////////////////////////////////////

// #define int long long
// #define ld long double
// #define lld long long double
#define ff first
#define ss second
#define yes cout << "YES"
#define no cout << "NO"
#define fl(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vs vector<string>
#define vpii vector<pair<int, int>>
#define mii map<int, int>
#define pb push_back
#define ppb push_back
#define div(a, b) (a) / (b)
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define ceil(a, b) (a + b - 1) / b
#define input(a, n) fl(i, 1, n) cin >> a[i]
#define intake(a, n) \
  int n;             \
  cin >> n;          \
  vector<int> a(n);  \
  for (int i = 0; i < n; i++) cin >> a[i]
#define intake2(a, n, k) \
  int n, k;              \
  cin >> n >> k;         \
  vector<int> a(n);      \
  for (int i = 0; i < n; i++) cin >> a[i]
#define fast                        \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);                    \
  cout.tie(NULL)
#define pq priority_queue
#define out(a)                                            \
  for (int i = 0; i < a.size(); i++) cout << a[i] << " "; \
  cout << "\n"
#define en "\n"
// #define sp <<" "
#define sorti(a) sort(a.begin(), a.end())
#define sortd(a) sort(a.rbegin(), a.rend())
#define get_sum(a) accumulate(a.begin(), a.end(), 0LL)
#define get_max(a) *max_element(a.begin(), a.end())
#define get_min(a) *min_element(a.begin(), a.end())
#define get_max_pos(v) max_element(v.begin(), v.end()) - v.begin()
#define get_min_pos(v) min_element(v.begin(), v.end()) - v.begin()
#define sz(x) ((int)(x).size())
#define setbits(x) __builtin_popcountll(x)
const int modd = 1000000007;
const ld eps = 1e-6, pi = 3.14159265358979323846264338327950;

int gcd(int a, int b) { return __gcd(a, b); }

int binexpo(int a, int b, int mod) {
  int res = 1;
  while (b > 0) {
    if (b & 1) res = (res * a) % mod;
    a = (a * a) % mod;
    b = b >> 1;
  }
  return res;
}

int Find_gcd_Extended(int a, int b, int* x, int* y) {
  // Base Case
  if (a == 0) {
    *x = 0, *y = 1;
    return b;
  }

  // Storing results of recursive call
  int x1, y1;
  int gcd = Find_gcd_Extended(b % a, a, &x1, &y1);

  /*
    After recursive call, update the values
    of x and y
  */
  *x = y1 - (b / a) * x1;
  *y = x1;

  return gcd;
}

int modinv(int a, int m) {
  int x, y;
  int g = Find_gcd_Extended(a, m, &x, &y);

  /*
    If the gcd value doesn't matches
    to 1, then inverse doesn't exist
  */
  if (g != 1) {
    return -1;
    // cout << "sdf";
  } else {
    /*
      m is added once more to handle
      negative values
    */
    int res = (x % m + m) % m;
    // cout<<res<<endl;
    return res;
  }
}

// --------Sieve-------
// if isPrime[i] if true then, i is a prime number
vector<bool> isPrime(1000001);
void sieve() {
  for (int i = 0; i <= 1000001; i++) {
    isPrime[i] = 1;
  }
  isPrime[0] = isPrime[1] = 0;

  for (int i = 2; i * i <= 1000000; i++) {
    if (isPrime[i] == true) {
      for (int j = i * i; j <= 1000000; j += i) {
        isPrime[j] = false;
      }
    }
  }
}

//-----spf------
// SPF[i] => smallest prime number that divides i

vector<int> spf(1000001);
void findspf() {
  for (int i = 0; i <= 1e6; i++) {
    spf[i] = i;
  }

  for (int i = 2; i * i <= 1e6; i++) {
    if (spf[i] == i) {
      for (int j = i * i; j <= 1e6; j += i) {
        if (spf[j] == j) {
          spf[j] = i;
        }
      }
    }
  }
}

int madd(int a, int b, int m) {
  a = a % m;
  b = b % m;
  return (((a + b) % m + m) % m);
}

int mmul(int a, int b, int m) {
  a = a % m;
  b = b % m;
  return (((a * b) % m + m) % m);
}

int msub(int a, int b, int m) {
  a = a % m;
  b = b % m;
  return (((a - b) % m + m) % m);
}

int mdiv(int a, int b, int m) {
  a = a % m;
  b = b % m;
  return ((mmul(a, modinv(b, m), m) + m) % m);
}

// string hashing

pair<const int, const int> mod = {1e9 + 7, 1e9 + 9};
vector<pair<int, int>> pref_hash;
vector<pair<int, int>> power_pref;
void createHashfn(int n, string& s) {
  pref_hash.resize(n);
  power_pref.resize(n);
  pref_hash[0] = {s[0] - 'a' + 1, s[0] - 'a' + 1};
  power_pref[0] = {1, 1};
  for (int i = 1; i < n; i++) {
    pref_hash[i].first =
        (pref_hash[i - 1].first * (int)31 + (s[i] - 'a' + 1)) % mod.first;
    pref_hash[i].second =
        (pref_hash[i - 1].second * (int)53 + (s[i] - 'a' + 1)) % mod.second;

    power_pref[i].first = (power_pref[i - 1].first * (int)31) % mod.first;
    power_pref[i].second = (power_pref[i - 1].second * (int)53) % mod.second;
  }
}

auto subhash(int l, int r, string& s) {
  if (l == 0) return pref_hash[r];

  pair<int, int> sub_hash;
  sub_hash.first = ((pref_hash[r].first - (int)pref_hash[l - 1].first *
                                              power_pref[r - l + 1].first) %
                    mod.first);
  if (sub_hash.first < 0) sub_hash.first += mod.first;

  sub_hash.second = ((pref_hash[r].second - (int)pref_hash[l - 1].second *
                                                power_pref[r - l + 1].second) %
                     mod.second);
  if (sub_hash.second < 0) sub_hash.second += mod.second;
  return sub_hash;
}

//////////////////  DSU 1 BASED INDEXING /////////////////////////////
vector<int> par(2e5 + 1);
vector<int> rnk(2e5 + 1);
// intrnk[1e5];

void make_set(int n) {
  for (int i = 1; i < n + 1; i++) {
    par[i] = i;
    rnk[i] = 1;
  }
}

int find_set(int x) {
  if (par[x] == x) {
    return x;
  }

  par[x] = find_set(par[x]);

  return par[x];
}

void union_set(int a, int b) {
  int p1 = find_set(a);
  int p2 = find_set(b);

  if (p1 == p2) {
    return;
  }

  if (rnk[p1] > rnk[p2]) {
    par[p2] = p1;
    rnk[p1] = rnk[p1] + rnk[p2];
  } else {
    par[p1] = p2;
    rnk[p2] = rnk[p2] + rnk[p1];
  }
}
////////////////////DSU 1 BASED
/// INDEXING//////////////////////////////////////////////////

// x|(1<<k) : sets the kth bit
// x&~(1<<k): unsets the kth bit
// x^(1<<k) : inverts the kth bit

// gcd, binexpo, modinv, {sieve, isPrime}, {spf, findspf}
// madd, mmul, msub, mdiv

bool ipot(int x) { return (x != 0LL) && ((x & (x - 1LL)) == 0LL); }

// sometime think oppsite from output ----> input
const int MOD = 998244353;
void add(int& a, int b) {
  a += b;
  if (a >= MOD) a -= MOD;
}

int sum(int a, int b) {
  a += b;
  if (a >= MOD) a -= MOD;
  if (a < 0) a += MOD;
  return a;
}

int mul(int a, int b) { return (a * 1LL * b) % MOD; }

const int N = 2000005;
// const int mod = 1e9 + 7;
int fact[N], invfact[N];

void precompute() {
  fact[0] = fact[1] = 1;
  for (int i = 2; i < N; i++) {
    fact[i] = fact[i - 1] * i;
    fact[i] %= modd;
  }

  invfact[N - 1] = modinv(fact[N - 1], modd);
  for (int i = N - 2; i >= 0; i--) {
    invfact[i] = invfact[i + 1] * (i + 1);
    invfact[i] %= modd;
  }
}

int nCr(int x, int y) {
  if (y > x) return 0;
  int num = fact[x];
  num *= invfact[y];
  num %= modd;
  num *= invfact[x - y];
  num %= modd;
  return num;
}

vi binRep(int x) {
  vi v(32);
  for (int i = 29; i >= 0; i--) {
    v[i] = (x >= (1 << i));
    x %= (1 << i);
  }
  return v;
}

// RADHE RADHE

// vvi tree;
// vi vis, parent, depth;

//---------- max seg code ---- 0based indexing--------------//

const int MAXMAX = 2e5;  // Max size of array
int treemax[2 * MAXMAX];

// Function to build the tree
void buildmax(vector<int>& arr, int n) {
  for (int i = 0; i < n; i++) treemax[n + i] = arr[i];
  for (int i = n - 1; i > 0; --i)
    treemax[i] = max(treemax[i << 1], treemax[i << 1 | 1]);
}

// Function to update a tree node
void updatemax(int p, int value, int n) {
  treemax[p + n] = value;
  p = p + n;
  for (int i = p; i > 1; i >>= 1)
    treemax[i >> 1] = max(treemax[i], treemax[i ^ 1]);
}

// Function to get minimum value in a given range
// [l,r)
int querymax(int l, int r, int n) {
  int res = -1e18;
  for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l & 1) res = max(res, treemax[l++]);
    if (r & 1) res = max(res, treemax[--r]);
  }
  return res;
}

// array mein value ko dalne ke liye update ko call karna

//---------- max seg code ---- 0based indexing--------------//-------------//
//---------- min seg code ---- 0based indexing--------------//

const int MAXMIN = 2e5;  // Max size of array
int treemin[2 * MAXMIN];

// Function to build the tree
void buildmin(vector<int>& arr, int n) {
  for (int i = 0; i < n; i++) treemin[n + i] = arr[i];
  for (int i = n - 1; i > 0; --i)
    treemin[i] = min(treemin[i << 1], treemin[i << 1 | 1]);
}

// Function to update a tree node
void updatemin(int p, int value, int n) {
  treemin[p + n] = value;
  p = p + n;
  for (int i = p; i > 1; i >>= 1)
    treemin[i >> 1] = min(treemin[i], treemin[i ^ 1]);
}

// Function to get minimum value in a given range
// [l,r)
int querymin(int l, int r, int n) {
  int res = 1e18;
  for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l & 1) res = min(res, treemin[l++]);
    if (r & 1) res = min(res, treemin[--r]);
  }
  return res;
}

// array mein value ko dalne ke liye update ko call karna
////////////////////////////////////////////
//---------- min seg code ---- 0based indexing--------------//-------------//
///////////////////////////////////////

//////////////////////////////////////////////////////////////////
///////////////////////////BINARY INDEX TREE/////////////////////////////////
//////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////
//////////////////////BINARY INDEX TREE//////////////////////////////
///////////////////////////////////////////////////////////////////////////

// point update range min/max => seg tree
// point update range sum ==> Binary index tree

// for static
// range min/max/gcd/lcm/or/and ==> sparse table , query in O(1)
// range sum/xor ==> prefix sum

// range update , set ; range min/max/sum = lazy

// sparsetable code

// int n;
// cin >> n;
//
// vi a(n);
// fl(i, 0, n) cin >> a[i];
//
// int maxk = 25;
// int st[n + 1][maxk + 1];
//
// for (int i = 0; i < n; i++) {
// st[i][0] = a[i];
// }
//
// for (int k = 1; k <= maxk; k++) {
// for (int i = 0; i + (1 << k) <= n; i++) {
// st[i][k] = (st[i][k - 1] & st[i + (1 << (k - 1))][k - 1]);
// }
// }
//
// for (int i = 0; i < n; i++) {
// for (int j = 0; j < 4; j++) {
// cout << st[i][j] << " ";
// }
// cout << endl;
// }
//
// int l, r;
// cin >> l >> r;
// // int s = 0;
// // for (int k = maxk; k >= 0; k--) {
// // if ((1 << k) <= r - l + 1) {
// // s += st[l][k];
// // l += (1 << k);
// // }
// // }
// // cout << s;
//
// vi lg(n + 1);
// lg[1] = 0;
// for (int i = 2; i <= n; i++) {
// lg[i] = lg[i / 2] + 1;
// }
//
// int w = lg[r - l + 1];
// int ans = (st[l][w] & st[r - (1 << w) + 1][w]);
// cout << ans;

// sparsetable code

void solve() {
  int n;
  cin >> n;
  vi v(n);
  fl(i, 0, n) cin >> v[i];
  if (v[0] == get_max(v)) {
    cout << "NO";
    return;
  }
  cout << "YES";
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  // // ----Atcode----
  // int q = 1;
  // // ----Atcode----
  // -----cf/cc----
  int q;
  cin >> q;
  //-----cf/cc----

  precompute();
  while (q--) {
    solve();
    cout << en;
  }
  return 0;
}


Answer: 1