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

Solution 1 (runtime: 93 ms):
// JAI MAHAKALLLLLLLLLLLLLLL

#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007

#define int long long

#define dbg(x) cout << #x << " = " << x << "\n"

#define vi vector<int>

#define pii pair<int, int>

#define pb push_back

#define mp make_pair

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

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

// ASCII values

// A=65, Z=90, a=97, z=122

// Some Tricks

// divide into cases, brute force, pattern finding

// sort, greedy, binary search, two pointer

// transform into graph

// calculating anything in a string = count(in.begin(), in.end(), '0')

// is a substring present on main string or not and X is repetition

// bool checking_substring = in.find(string(X, '1')) != string::npos;

// {for knowing MSB 32 -  __builtin_clz(n)}

// {for knowing set bits  -  __builtin_popcount(n) and __builtin_popcountll(n)}



// Function for modular exponentiation

long long mod_exp(long long base, long long exp, long long mod)

{

    long long result = 1;

    base = base % mod; // Handle base larger than mod

    while (exp > 0)

    {

        if (exp % 2 == 1)

        {

            result = (result * base) % mod;

        }

        base = (base * base) % mod;

        exp /= 2;

    }

    return result;

}

template <typename T>

void help(const vector<T> &vec)

{

    cout << "help is executed" << endl;

    for (const auto &i : vec)

    {

        cout << i << " ";

    }

    cout << endl;

}

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

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

int mod(int a) { return a < 0 ? -a : a; }



int prefix_sum(int a, int n)

{

    return (n * (2 * a + (n - 1))) / 2;

}

int coordinate_distance(int x1, int x2, int y1, int y2)

{

    int dist = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);

    return dist;

}

int min(int a, int b) { return std::min(a, b); }

int max(int a, int b) { return std::max(a, b); }

void coderaryan()

{

    // executing code from here

    int t;

    cin >> t;

    while (t--)

    {

        int n;

        cin >> n;

        vi vec(n);

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

            cin >> vec[i];

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

        {

            int x = min(vec[i], vec[i + 1]);

            vec[i] -= x;

            vec[i + 1] -= x;

        }

        // help(vec);

        int check = 0;

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

        {

            if (vec[i] != 0 && vec[i + 1] == 0)

            {

                check = 1;

                break;

            }

        }

        if (check)

        {

            cn;

        }

        else

        {

            cy;

        }

    }

}



int32_t main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);

    coderaryan();

    return 0;

}

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

using namespace std;



#define int long long

#define size_t long long

#define double long double



#define el cout << "\n"

const int M = 1000000007;

const int mod = 998244353;

#define YES cout << "YES"

#define Yes cout << "Yes"

#define NO cout << "NO"

#define No cout << "No"



#define vi vector<int>

#define pii pair<int,int>

#define vii vector<pair<int, int> >

#define vv vector<vector<int>>

#define vv2d(row, col, name) vector<vector<int>> name(row, vector<int>(col))

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



#ifdef CPH

#define debug(x) cout << #x << " = " << x << '\n';

#define vdebug(a) cout << #a << " = "; for(auto x: a) cout << x << ' '; cout << '\n';

#else

#define debug(x)

#define vdebug(a)

#endif



int binMultiply(int a, int b) {

int ans = 0;

while (b) {

if (b & 1)

ans = (ans + a) % M;

b >>= 1;

a = (a + a) % M;

}

return ans;

}



int largeBinExpo(int a, int b, int M) {

a = a % M;

int ans = 1;

while (b) {

if (b & 1)

ans = binMultiply(ans, a);

b >>= 1;

a = binMultiply(a, a);

}

return ans;

}

int binPow(int a, int b, int M) {

int ans = 1;

while (b) {

if (b & 1)

ans = (ans * 1ll * a) % M;

a = (a * 1ll * a) % M;

b >>= 1;

}

return ans;

}



signed main() {

ios_base::sync_with_stdio(false);

cin.tie(NULL);

int t = 1;

cin >> t;

while (t--) {

int n;

cin >> n;

n++;

vi v(n);

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

{

cin >> v[i];

}

bool ok = true;

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

// {

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

//     for (int j = 0; j < i; j++) {

//       v[j + 1] -= v[j];

//       v[j] = 0;

//     }

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

//       ok = !ok;

//       break;

//     }

//   }

// }



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

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

v[i] -= mini;

v[i+1] -= mini;

}

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

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

ok = !ok;

break;

}

}



if (ok)YES;else NO;



cout << "\n";

}

}