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

Solution 1 (runtime: 109 ms):
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
int gcdExtended(int a, int b, int* x, int* y)
{
 
    // Base Case
    if (a == 0) {
        *x = 0, *y = 1;
        return b;
    }
 
    // To store results of recursive call
    int x1, y1;
    int gcd = gcdExtended(b % a, a, &x1, &y1);
 
    // Update x and y using results of recursive
    // call
    *x = y1 - (b / a) * x1;
    *y = x1;
 
    return gcd;
}
ll modInverse(ll A, int M)
{
    int x, y;
    int g = gcdExtended(A, M, &x, &y);
  
 
        // m is added to handle negative x
        int res = (x % M + M) % M;
        return res;
        // cout << "Modular multiplicative inverse is " << res;
    
}

bool solve(ll &md,vector<ll>&v1,ll k)
{
  multiset<ll>s;
  s.insert(v1[0]);
  ll ct=1;
  ll mx=0;
  for(ll i=1;i<v1.size();i++)
  {
     auto itr=s.upper_bound(v1[i]);
     if(itr==s.end())
     {
        itr--;
        if(v1[i]-*itr>=md)
        s.insert(v1[i]);
        else
        {
            ct++;
            s.clear();
            s.insert(v1[i]);
        }
     }
     else
     {
        if(*itr-v1[i]<md)
        {
            ct++;
            s.clear();
            s.insert(v1[i]);
        }
        else
        {
            if(itr!=s.begin())
            {
                itr--;
                if(v1[i]-*itr>=md)
        s.insert(v1[i]);
        else
        {
            ct++;
            s.clear();
            s.insert(v1[i]);
        }

            }
        }

     }
  }
  if(ct>k)
  return false;
  return true;
}
ll power(ll i,ll j)
{
    ll ans=1;
    for(ll x=0;x<j;x++)
    {
        ans*=i;
    }
    return ans;
}
void dfs(ll i,vector<ll>&ch,vector<vector<ll>>&adj,vector<ll>&path,vector<vector<ll>>&c)
{
    ch[i]=1;
    path.push_back(i);
    for(auto k:adj[i])
    {
        if(!ch[k])
        dfs(k,ch,adj,path,c);
        else
        {
            auto itr=find(path.begin(),path.end(),k);
            vector<ll>cy(itr,path.end());
            c.push_back(cy);
        }
    }
    path.pop_back();
    ch[i]=0;
}
int main()
{
 ios_base::sync_with_stdio(false);
    cin.tie(NULL);
ll t;
cin>>t;
while(t--)
{
ll n;
cin>>n;
vector<ll>v1(n);
for(ll i=0;i<n;i++)
cin>>v1[i];
vector<ll>v2=v1;
sort(v2.begin(),v2.end());
if(v2==v1)
cout<<"Yes"<<endl;
else
{
    ll f=1;
  for(ll i=1;i<n;i++)
  {
    if(v1[i]>=v1[i-1])
    {
        ll mn=min(v1[i],v1[i-1]);
        v1[i]-=mn;
        v1[i-1]-=mn;
    }
    else
    {
    f=0;
    break;
    }
  }
  if(f)
  cout<<"yes"<<endl;
  else

  cout<<"No"<<endl;
}
    

}




return 0;
}

Solution 2 (runtime: 77 ms):
//#pragma GCC optimize (2)
#include <bits/stdc++.h>
//#include <windows.h>

using namespace std;

/* --------------- fast io --------------- */ // begin
namespace Fread {
	const int SIZE = 1 << 21;
	char buf[SIZE], *S, *T;
	inline char getchar() {
		if (S == T) {
			T = (S = buf) + fread(buf, 1, SIZE, stdin);
			if (S == T) return '\n';
		}
		return *S++;
	}
} // namespace Fread
namespace Fwrite {
	const int SIZE = 1 << 21;
	char buf[SIZE], *S = buf, *T = buf + SIZE;
	inline void flush() {
		fwrite(buf, 1, S - buf, stdout);
		S = buf;
	}
	inline void putchar(char c) {
		*S++ = c;
		if (S == T) flush();
	}
	struct NTR {
		~ NTR() { flush(); }
	} ztr;
} // namespace Fwrite
#ifdef ONLINE_JUDGE
#define getchar Fread :: getchar
#define putchar Fwrite :: putchar
#endif
namespace Fastio {
	struct Reader {
		template<typename T>
		Reader& operator >> (T& x) {
			char c = getchar();
			T f = 1;
			while (c < '0' || c > '9') {
				if (c == '-') f = -1;
				c = getchar();
			}
			x = 0;
			while (c >= '0' && c <= '9') {
				x = (x << 3) + (x << 1) + (c ^ 48);
				c = getchar();
			}
			x *= f;
			return *this;
		}
		Reader& operator >> (char& c) {
			c = getchar();
			while (c == ' ' || c == '\n' || c == '\r') c = getchar();
			return *this;
		}
		Reader& operator >> (char* str) {
			int len = 0;
			char c = getchar();
			while (c == ' ' || c == '\n' || c == '\r') c = getchar();
			while (c != ' ' && c != '\n' && c != '\r') {
				str[len++] = c;
				c = getchar();
			}
			str[len] = '\0';
			return *this;
		}
		Reader() {}
	} cin;
	const char endl = '\n';
	struct Writer {
		template<typename T>
		Writer& operator << (T x) {
			if (x == 0) { putchar('0'); return *this; }
			if (x < 0) { putchar('-'); x = -x; }
			static int sta[45];
			int top = 0;
			while (x) { sta[++top] = x % 10; x /= 10; }
			while (top) { putchar(sta[top] | 48); --top; }
			return *this;
		}
		Writer& operator << (char c) {
			putchar(c);
			return *this;
		}
		Writer& operator << (char* str) {
			int cur = 0;
			while (str[cur]) putchar(str[cur++]);
			return *this;
		}
		Writer& operator << (const char* str) {
			int cur = 0;
			while (str[cur]) putchar(str[cur++]);
			return *this;
		}
		Writer() {}
	} cout;
} // namespace Fastio
#define cin Fastio :: cin
#define cout Fastio :: cout
#define endl Fastio :: endl
/* --------------- fast io --------------- */ // end

#define ll long long
#define mid (l + r >> 1)
#define lowbit(x) (x & -x)

const int N = 2e5 + 5;

int T, n;
int a[N];

void Solve() {
	cin >> n;
	for (int i = 1; i <= n; ++i) cin >> a[i];
	for (int i = 1; i < n; ++i) {
		if (a[i] > a[i + 1]) { cout << "NO\n"; return; }
		int tmp = min(a[i], a[i + 1]); a[i] -= tmp; a[i + 1] -= tmp;
	}
	cout << "YES\n";
//	int val = 1e9 + 1;
//	for (int i = n; i > 0; --i) {
//		if (a[i] > val && i < n) {
//			if (i == 1) { cout << "NO\n"; return; }
//			int tmp = min(a[i], a[i - 1]);
//			a[i] -= tmp; a[i - 1] -= tmp;
//			if (a[i] > val) { cout << "NO\n"; return; }
//		}
//		val = min(val, a[i]);
//	}
//	cout << "YES\n";
}

signed main() {
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	cin >> T;
	while (T--) Solve();
	return 0;
}