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

Solution 1 (runtime: 108 ms):
// Created at: 2025-02-26 19:39:40



#include <bits/stdc++.h>

using namespace std;



#define ll long long

#define ld long double

#define ull unsigned long long

#define vti vector<int>

#define vvti vector<vti>

#define vtl vector<ll>

#define vvtl vector<vtl>

#define vtc vector<char>

#define vvtc vector<vtc>

#define vts vector<string>

#define vvts vector<vts>

#define vtb vector<bool>

#define vvtb vector<vtb>

#define pii pair<int, int>

#define pll pair<ll, ll>

#define vpi vector<pii>

#define pic pair<int, char>

#define pci pair<char, int>

#define pcc pair<char, char>

#define pss pair<string, string>

#define pq priority_queue

#define pb push_back

#define gcd __gcd

#define nline "\n"

#define pi acos(-1)

#define elif else if

#define pf printf

#define sf scanf

#define fi first

#define si second

#define bpop(x) __builtin_popcount(x)

#define len(x) x.length()

#define asc(v) sort(all(v))

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

#define sall(v, a) accumulate(all(v), a)

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

#define dsc(v) asc(v), reverse(all(v))

#define sum(v) accumulate(all(v), 0)

#define mem0(a) memset(a, 0, sizeof(a))

#define mem1(a) memset(a, -1, sizeof(a))

#define memc(a, c) memset(a, c, sizeof(a))

#define FOR(i, start, end, a) for (ll i = start; i < end; i += a)

#define FORN(i, start, end, a) for (ll i = start; i > end; i -= a)

#define remDup(c) c.erase(unique(all(c)), c.end());



int dx[] = {1, 0, -1, 0};

int dy[] = {0, 1, 0, -1};

int d8x[] = {0, 1, 0, -1, -1, 1, -1, 1};

int d8y[] = {1, 0, -1, 0, -1, -1, 1, 1};

const long long INF = LLONG_MAX >> 1;

const long long MOD = 1e9 + 7;

const long double e = 1e-9;



//------------------------------------------------------------------------------

ll power(ll a, ll b)

{

    ll result = 1;

    for (; b; a *= a, b /= 2)

        result *= (b % 2) ? a : 1;

    return result;

}

int factorial(int a) { return tgamma(a + 1); }

//------------------------------------------------------------------------------



void solve()

{

    int n;

    cin >> n;

    vti v(n);

    for (auto &i : v)

        cin >> i;

    FOR(i, 0, n - 2, 1)

    {

        if (v[i] > v[i + 1])

        {

            cout << "NO" << nline;

            return;

        }

        int mn = min(v[i], v[i + 1]);

        v[i] -= mn;

        v[i + 1] -= mn;

    }

    cout << (v[n - 2] <= v[n - 1] || v.size() == 1 ? "YES" : "NO") << nline;

}



int main()

{

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    cout.precision(10);

    cout << fixed;

    int tt;

    cin >> tt;

    while (tt--)

    {

        solve();

    }

    return 0;

}

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

using namespace std;



typedef long long ll;

typedef unsigned long long ull;



#define entf          cout << endl

#define ent           cout << "\n"

#define REP(i, a, b)  for (int i = a; i < b; ++i)

#define REPV(i, a, b) for (int i = a; i >= b; --i)

#define MOD           1000000007

#define PRINT(x) cout << x << endl

#define d(x) cerr << #x << " = " << x << endl  // Pass a variable name and it will print it with the value



#define TESTCASES true



void solve(int tt) {

int n;

cin >> n;



int val;

vector<int> a;

a.reserve(n);

REP(i, 0, n){

cin >> val;

a.push_back(val);

}

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

cout << "NO" << endl;

return;

}



bool ans = true;

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

if(a[i] > a[i+1]) {

ans = false;

break;

}

int diff = min(a[i], a[i+1]);

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

a[i] -= a[i];

}



cout << (ans ? "YES": "NO") << endl;

}



int main() {

ios::sync_with_stdio(0);

cin.tie(0);



if (TESTCASES) {

int tt; cin >> tt;

REP(i, 1, tt+1) {

solve(i);

}

} else solve(1);



return 0;

}