You are given an array $a$ of $n$ positive integers.

You can use the following operation as many times as you like: select any integer $1 \le k \le n$ and do one of two things:   decrement by one $k$ of the first elements of the array.  decrement by one $k$ of the last elements of the array. 

For example, if $n=5$ and $a=[3,2,2,1,4]$, then you can apply one of the following operations to it (not all possible options are listed below):   decrement from the first two elements of the array. After this operation $a=[2, 1, 2, 1, 4]$;  decrement from the last three elements of the array. After this operation $a=[3, 2, 1, 0, 3]$;  decrement from the first five elements of the array. After this operation $a=[2, 1, 1, 0, 3]$; 

Determine if it is possible to make all the elements of the array equal to zero by applying a certain number of operations.


-----Input-----

The first line contains one positive integer $t$ ($1 \le t \le 30000$) — the number of test cases. Then $t$ test cases follow.

Each test case begins with a line containing one integer $n$ ($1 \le n \le 30000$) — the number of elements in the array.

The second line of each test case contains $n$ integers $a_1 \ldots a_n$ ($1 \le a_i \le 10^6$).

The sum of $n$ over all test cases does not exceed $30000$.


-----Output-----

For each test case, output on a separate line:   YES, if it is possible to make all elements of the array equal to zero by applying a certain number of operations.  NO, otherwise. 

The letters in the words YES and NO can be outputed in any case.


-----Example-----
Input
4
3
1 2 1
5
11 7 9 6 8
5
1 3 1 3 1
4
5 2 1 10

Output
YES
YES
NO
YES

Difficulty: MEDIUM_HARD
Tags: Greedy algorithms

Dynamic programming

Constructive algorithms
Skill types: Dynamic programming

Greedy algorithms

Starter code:

Solutions:
from sys import stdin
from math import *
for __ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	val = a[0]
	for i in range(n - 1, 0, -1):
		a[i] -= a[i - 1]
		if a[i] < 0:
			val += a[i]
	if val >= 0:
		print('YES')
	else:
		print('NO')


t = int(input())
while t:
	n = int(input())
	v = list(map(int, input().split()))
	a = [0 for i in range(n)]
	b = [0 for i in range(n)]
	a[0] = v[0]
	flag = True
	for i in range(1, n):
		a[i] = min(a[i - 1], v[i] - b[i - 1])
		b[i] = v[i] - a[i]
		if b[i] < b[i - 1] or a[i] < 0:
			flag = False
			break
	if flag:
		print('YES')
	else:
		print('NO')
	t -= 1


BUFSIZE = 8192
import os
import sys
from io import BytesIO, IOBase
from bisect import bisect_left
from bisect import bisect_right

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	r = a[0]
	l = 0
	for i in range(n):
		if r + l < a[i]:
			l = a[i] - r
		elif r + l > a[i]:
			r = a[i] - l
	if r >= 0:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	ans = True
	i = n - 2
	total = 0
	while i > 0:
		if arr[i] <= arr[i + 1]:
			i -= 1
		else:
			total += arr[i] - arr[i + 1]
			i -= 1
		if arr[i] - total < 0:
			ans = False
			break
	if ans:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	i = 1
	l = 0
	g = a[0]
	while i < n and a[i] <= a[i - 1]:
		g = min(g, a[i])
		i += 1
	l = i - 1
	i = n - 2
	h = a[-1]
	while i >= 0 and a[i + 1] >= a[i]:
		h = min(h, a[i])
		i -= 1
	r = i + 1
	if r <= l:
		print('YES')
	else:
		p = 0
		q = 0
		for i in range(l + 1, r + 1):
			if a[i] <= a[i - 1]:
				p += abs(a[i - 1] - a[i])
		for i in range(r - 1, l - 1, -1):
			if a[i] <= a[i + 1]:
				q += abs(a[i + 1] - a[i])
		if p <= g or q <= h:
			print('YES')
		else:
			print('NO')


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	curr = 0
	for i in range(n - 1):
		diff = l[i + 1] - l[i]
		l[i] -= curr
		if diff > 0:
			curr += diff
	l[n - 1] -= curr
	if min(l) >= 0:
		print('YES')
	else:
		print('NO')


import io
import os
from collections import Counter, defaultdict, deque

def solve(N, A):
	lefts = [0] * N
	for (i, (x, y)) in enumerate(zip(A, A[1:])):
		if x > y:
			lefts[i] = x - y
	check = [0] * N
	for i in range(N)[::-1]:
		if i != N - 1:
			lefts[i] += lefts[i + 1]
		check[i] = A[i] - lefts[i]
	if all((x >= 0 for x in check)):
		assert all((x <= y for (x, y) in zip(check, check[1:])))
		return 'YES'
	return 'NO'
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
TC = int(input())
for tc in range(1, TC + 1):
	(N,) = [int(x) for x in input().split()]
	A = [int(x) for x in input().split()]
	ans = solve(N, A)
	print(ans)


from sys import stdin, stdout
input = stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(x) for x in input().split()]
	s = sum([max(0, arr[i] - arr[i + 1]) for i in range(n - 1)])
	if s <= arr[0]:
		print('YES')
	else:
		print('NO')


from typing import List
n = int(input())
data = []
for i in range(n):
	l = int(input())
	tdata = []
	for chnum in input().split(' '):
		tdata.append(int(chnum))
	data.append(tdata)

def Solution(data: List[int]) -> str:
	last_num = 0
	tnum1 = 0
	for tnum in data:
		if tnum - last_num < 0:
			tnum1 += tnum - last_num
		last_num = tnum
	if -tnum1 <= data[0]:
		return 'YES'
	return 'NO'
for tdata in data:
	print(Solution(tdata))


import sys, math
import io, os
from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter
from itertools import permutations, combinations

def data():
	return sys.stdin.readline().strip()

def mdata():
	return list(map(int, data().split()))

def outl(var):
	sys.stdout.write(' '.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
sys.setrecursionlimit(100000)
INF = float('inf')
mod = 998244353
for t in range(int(data())):
	n = int(data())
	A = mdata()
	k = A[0]
	for i in range(1, n):
		k -= max(0, A[i - 1] - A[i])
	out('YES' if k >= 0 else 'NO')


from collections import deque, defaultdict

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	minr = []
	rgt = a[-1]
	for i in reversed(range(n)):
		if a[i] <= rgt:
			minr.append(a[i])
			rgt = a[i]
		else:
			minr.append(rgt)
	forced = flag = 0
	lft = a[0]
	for i in range(n):
		if forced > a[i] or lft + minr[n - i - 1] < a[i]:
			print('NO')
			break
		elif lft + forced > a[i]:
			lft = a[i] - forced
		elif lft + forced < a[i]:
			forced = a[i] - lft
		lft = min(lft, a[i])
	else:
		print('YES')

def main():
	t = 1
	t = int(input())
	for _ in range(t):
		solve()
main()


N = int(input())
for _ in range(N):
	n = int(input())
	l = list(map(int, input().split()))
	des_num = 0
	for i in range(len(l) - 1):
		if l[i + 1] - des_num < 0:
			print('NO')
			break
		if l[i] < l[i + 1]:
			des_num += l[i + 1] - l[i]
	else:
		print('YES')


def solve(arr, n):
	diffarr = [0] * n
	count = 0
	for i in range(n - 2, -1, -1):
		arr[i] -= count
		if arr[i] < 0:
			return 0
		if arr[i] > arr[i + 1]:
			count += arr[i] - arr[i + 1]
			arr[i] = arr[i + 1]
	return 1
t = int(input())
for _ in range(t):
	n = int(input())
	oriarr = [int(j) for j in input().split()]
	arr = oriarr[:]
	revarr = oriarr[::-1]
	if solve(arr, n) == 1 or solve(revarr, n) == 1:
		print('YES')
	else:
		print('NO')


import os
import sys
from io import BytesIO, IOBase
_str = str
BUFSIZE = 8192

def str(x=b''):
	return x if type(x) is bytes else _str(x).encode()

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def inp():
	return sys.stdin.readline().rstrip()

def mpint():
	return map(int, inp().split(' '))

def itg():
	return int(inp())

class LazySegmentTree:

	def __init__(self, data, default=0, func=max):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self._lazy = [0] * (2 * _size)
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __len__(self):
		return self._len

	def _push(self, idx):
		(q, self._lazy[idx]) = (self._lazy[idx], 0)
		self._lazy[2 * idx] += q
		self._lazy[2 * idx + 1] += q
		self.data[2 * idx] += q
		self.data[2 * idx + 1] += q

	def _update(self, idx):
		for i in reversed(range(1, idx.bit_length())):
			self._push(idx >> i)

	def _build(self, idx):
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1]) + self._lazy[idx]
			idx >>= 1

	def add(self, start, stop, value):
		start = start_copy = start + self._size
		stop = stop_copy = stop + self._size
		while start < stop:
			if start & 1:
				self._lazy[start] += value
				self.data[start] += value
				start += 1
			if stop & 1:
				stop -= 1
				self._lazy[stop] += value
				self.data[stop] += value
			start >>= 1
			stop >>= 1
		self._build(start_copy)
		self._build(stop_copy - 1)

	def query(self, start, stop, default=0):
		start += self._size
		stop += self._size
		self._update(start)
		self._update(stop - 1)
		res = default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'LazySegmentTree({0})'.format(self.data)

def solve():
	n = itg()
	tree = LazySegmentTree(list(mpint()), 10 ** 7, min)

	def get(idx):
		return tree.query(idx, idx + 1, 10 ** 7)
	for i in range(n - 1):
		(a, b) = (get(i), get(i + 1))
		if a > b:
			tree.add(0, i + 1, b - a)
	return tree.query(0, n, 10 ** 7) >= 0

def main():
	for _ in range(itg()):
		print('YES' if solve() else 'NO')
DEBUG = 0
URL = 'https://codeforces.com/contest/1443/problem/D'
if DEBUG == 1:
	import requests
	from ACgenerator.Y_Test_Case_Runner import TestCaseRunner
	runner = TestCaseRunner(main, URL, 2)
	inp = runner.input_stream
	print = runner.output_stream
	runner.checking()
elif DEBUG == 2:
	main()
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
	main()


import os, sys
from io import BytesIO, IOBase
from math import log2, ceil, sqrt, gcd
from _collections import deque
import heapq as hp
from bisect import bisect_left, bisect_right
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
mod = 10 ** 9 + 7
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	pos = neg = 0
	for i in range(1, n):
		d = a[i - 1] - a[i]
		if d < 0:
			neg += d
		else:
			pos += d
	if pos <= a[0] and a[-1] + neg >= 0:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.buffer.readline
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [-1 for _ in range(n)]
	minSoFar = float('inf')
	maxLeftOver = 0
	for i in range(n):
		b[i] = max(0, a[i] - minSoFar, maxLeftOver)
		b[i] = min(a[i], b[i])
		minSoFar = min(minSoFar, a[i] - b[i])
		maxLeftOver = max(maxLeftOver, b[i])
	c = [-1 for _ in range(n)]
	minSoFar = float('inf')
	for i in range(n - 1, -1, -1):
		minSoFar = min(minSoFar, b[i])
		c[i] = max(0, b[i] - minSoFar)
	if set(c) == {0}:
		print('YES')
	else:
		print('NO')


rep = int(input())
for i in range(rep):
	n = int(input())
	a = input()
	answer = 'YES'
	if n > 2:
		a = a.split(' ')
		f = int(a[0])
		b = 0
		c = int(a[1])
		for i in range(2, n):
			if int(a[i]) >= c - f + b and int(a[i]) >= b:
				if b < c - f + b:
					b = c - f + b
				f = int(a[i - 1])
				c = int(a[i])
			else:
				answer = 'NO'
				break
	print(answer)


import sys
input = sys.stdin.readline
a = int(input())
for i in range(a):
	b = int(input())
	c = list(map(int, input().split()))
	d = [c[0]]
	e = [0]
	for j in range(1, b):
		d.append(min(d[j - 1], c[j] - e[j - 1]))
		e.append(c[j] - d[j])

	def abc(d, e):
		for j in range(1, b):
			if d[j] > d[j - 1]:
				return 'NO'
			if e[-j - 1] > e[-j]:
				return 'NO'
			if d[j] < 0:
				return 'NO'
			if e[-j - 1] < 0:
				return 'NO'
		return 'YES'
	print(abc(d, e))


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	a = [0] + a
	print('YES' if sum([max(0, a[i - 1] - a[i]) for i in range(1, n + 1)]) <= a[1] else 'NO')

def main():
	t = 1
	t = int(input())
	for _ in range(t):
		solve()
main()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	cur = a[0]
	down = 0
	for c in a[1:]:
		if c - down < 0:
			print('NO')
			break
		elif c - down <= cur:
			cur = c - down
		else:
			down = c - cur
	else:
		print('YES')


T = int(input())
for _ in range(T):
	(n, ls) = (int(input()), list(map(int, input().split())))
	(left, right) = ([-1] * n, [-1] * n)
	left[0] = 0
	for u in range(1, n):
		if ls[u - 1] >= ls[u]:
			if ls[u] < left[u - 1]:
				break
			else:
				left[u] = left[u - 1]
		else:
			left[u] = left[u - 1] + (ls[u] - ls[u - 1])
	right[n - 1] = ls[n - 1]
	for u in reversed(range(n - 1)):
		if ls[u] <= ls[u + 1]:
			right[u] = ls[u]
		else:
			break
	ok = 0
	for u in range(1, n):
		if left[u - 1] == -1 or right[u] == -1:
			continue
		if left[u - 1] <= right[u]:
			ok = 1
			break
	print('YES' if n == 1 or ok else 'NO')


from sys import stdin
input = stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = a.copy()
	x = 0
	for i in range(n - 2, -1, -1):
		if a[i] > b[i + 1]:
			x += a[i] - b[i + 1]
		a[i] -= x
	if a[0] >= 0:
		print('YES')
	else:
		print('NO')


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz/'
M = 1000000007
EPS = 1e-06

def Ceil(a, b):
	return a // b + int(a % b > 0)

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
for _ in range(Int()):
	n = Int()
	a = array()
	ans = 'NO'
	k = 0
	for i in range(1, n):
		a[i] -= k
		if a[i] <= a[i - 1]:
			continue
		else:
			k += a[i] - a[i - 1]
			a[i] = a[i - 1]
	if a[-1] >= 0:
		ans = 'YES'
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	l = 0
	r = n - 1
	maxi = 10 ** 8
	for i in range(n):
		if a[l] <= maxi:
			maxi = a[l]
			l += 1
		else:
			break
	lmax = maxi
	maxi = 10 ** 8
	for i in range(n):
		if a[r] <= maxi:
			maxi = a[r]
			r -= 1
		else:
			break
	rmax = maxi
	a = a[l:r + 1]
	if len(a) == 0:
		print('YES')
		continue
	dec = min(a[0], lmax)
	a[0] -= dec
	lmax = dec
	for i in range(len(a) - 1):
		dec = min(a[i + 1] - a[i], a[i + 1], lmax)
		a[i + 1] -= dec
		lmax = dec
	flag = 1
	if max(a) <= rmax:
		if sorted(a) == a:
			pass
		else:
			flag = 0
	else:
		flag = 0
	if flag == 1:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	ans = 'YES'
	left_min = [0 for _ in range(n)]
	left_min[0] = a[0]
	for i in range(1, n):
		left_min[i] = min(left_min[i - 1], a[i])
	for i in range(0, n - 1):
		if i > 0:
			left_min[i] = min(left_min[i - 1], left_min[i])
		if a[i] > a[i + 1]:
			if a[i] - a[i + 1] > left_min[i]:
				ans = 'NO'
				break
			else:
				left_min[i] = left_min[i] - (a[i] - a[i + 1])
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	d = a[0]
	for i in range(1, n):
		diff = a[i] - a[i - 1]
		if diff < 0 and d >= 0:
			d += diff
	if d < 0:
		print('NO')
	else:
		print('YES')


import sys
from bisect import bisect_left
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	rd = 0
	ld = 0
	for i in range(1, n):
		if a[i] > a[i - 1]:
			rd += a[i] - a[i - 1]
		else:
			ld += a[i - 1] - a[i]
	if ld <= a[0] and rd <= a[-1]:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline

def main():
	n = int(input())
	alst = list(map(int, input().split()))
	up = alst[0]
	down = 0
	for a in alst[1:]:
		if up + down == a:
			continue
		elif up + down < a:
			down = a - up
		else:
			up = a - down
		if up < 0 or down < 0:
			print('NO')
			return
	print('YES')
for _ in range(int(input())):
	main()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	lst = 0
	for i in range(1, n):
		lst += max(a[i] - a[i - 1], 0)
	if lst <= a[-1]:
		print('YES')
	else:
		print('NO')


T = int(input())
for _ in range(T):
	n = int(input())
	a = [int(i) for i in input().split()]
	r = a[0]
	for i in range(1, n):
		if a[i - 1] > a[i]:
			r -= a[i - 1] - a[i]
	print('YES') if r >= 0 else print('NO')


for _ in range(int(input())):
	n = int(input())
	arr = [int(i) for i in input().split()]
	left = arr[0]
	right = 0
	ans = True
	for i in range(1, len(arr)):
		if arr[i] < right:
			ans = False
			break
		rem = arr[i] - right
		left = min(left, rem)
		add = rem - left
		right += add
	if ans:
		print('Yes')
	else:
		print('No')


import math
import sys, bisect
from heapq import *
from itertools import *
from collections import *
sys.setrecursionlimit(10 ** 6)
I = lambda : int(sys.stdin.readline())
neo = lambda : map(int, sys.stdin.readline().split())
Neo = lambda : list(map(int, sys.stdin.readline().split()))
for _ in range(I()):
	n = I()
	A = Neo()
	t = sum((max(0, A[i - 1] - A[i]) for i in range(1, n)))
	if t <= A[0]:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	m = a[0]
	for i in range(n - 1, 0, -1):
		a[i] = a[i] - a[i - 1]
		if a[i] < 0:
			m += a[i]
	if m >= 0:
		print('YES')
	else:
		print('NO')


from sys import stdin, stdout
from math import gcd, sqrt, factorial, pi, inf
from collections import deque, defaultdict
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
L = lambda : list(R())
P = lambda x: stdout.write(str(x) + '\n')
lcm = lambda x, y: x * y // gcd(x, y)
hg = lambda x, y: (y + x - 1) // x * x
pw = lambda x: 1 if x == 1 else 1 + pw(x // 2)
chk = lambda x: chk(x // 2) if not x % 2 else True if x == 1 else False
sm = lambda x: (x ** 2 + x) // 2
N = 10 ** 9 + 7
for _ in range(I()):
	n = I()
	(*a,) = R()
	s = 0
	for i in range(1, n):
		s += max(a[i] - a[i - 1], 0)
	print('YES' if s <= a[-1] else 'NO')


import sys
sys.setrecursionlimit(10 ** 5)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.buffer.readline())

def MI():
	return map(int, sys.stdin.buffer.readline().split())

def LI():
	return list(map(int, sys.stdin.buffer.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def BI():
	return sys.stdin.buffer.readline().rstrip()

def SI():
	return sys.stdin.buffer.readline().rstrip().decode()
inf = 10 ** 9

def solve():
	l = inf
	r = -1
	for a in aa:
		l = min(a, l, a - r)
		r = a - l
		if l < 0 or r < 0:
			return 'NO'
	return 'YES'
for _ in range(II()):
	n = II()
	aa = LI()
	print(solve())


import sys
input = sys.stdin.readline

def li():
	return [int(xx) for xx in input().split()]

def fi():
	return int(input())

def mi():
	return map(int, input().split())
t = fi()
while t > 0:
	t -= 1
	n = fi()
	a = li()
	c = 0
	flag = 0
	for i in range(n - 2, -1, -1):
		c = max(c, a[i] - a[i + 1])
		a[i] -= c
		if a[i] < 0:
			flag = 1
	print('YES' if flag == 0 else 'NO')


def answer():
	(dec, m) = (0, a[0])
	for i in range(1, n):
		if a[i - 1] < a[i]:
			dec += a[i] - a[i - 1]
		m = min(m, a[i] - dec)
		if m < 0:
			return 'NO'
	return 'YES'
for T in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	print(answer())


import sys, math
mod = 10 ** 9 + 7
md = 998244353
input = lambda : sys.stdin.readline().strip()
inp = lambda : list(map(int, input().split()))
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	check = a[n - 1]
	for i in range(n - 1):
		if a[i] - a[i + 1] < 0:
			check += a[i] - a[i + 1]
	if check >= 0:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	a = [0] * n
	a[0] = arr[0]
	b = [0] * n
	fl = True
	for i in range(1, n):
		aMust = min(a[i - 1], arr[i] - b[i - 1])
		bMust = arr[i] - aMust
		a[i] = aMust
		b[i] = bMust
		if aMust < 0 or bMust > arr[i] or a[i] > a[i - 1] or (b[i] < b[i - 1]):
			fl = False
	if fl:
		print('YES')
	else:
		print('NO')


def process(A):
	a0 = A[0]
	b0 = 0
	n = len(A)
	for i in range(n):
		X = A[i]
		if 0 <= X - b0 <= a0:
			b1 = b0
			a1 = X - b0
		elif X - a0 >= b0:
			a1 = a0
			b1 = X - a0
		else:
			return 'NO'
		(a0, b0) = (a1, b1)
	return 'YES'
t = int(input())
for I in range(t):
	n = int(input())
	A = [int(x) for x in input().split()]
	print(process(A))


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	(left, flag) = (a[0], False)
	for i in range(n - 1):
		if a[i] > a[i + 1]:
			left -= a[i] - a[i + 1]
			if left < 0:
				flag = True
				break
		left = min(left, a[i])
	if flag:
		print('NO')
	else:
		print('YES')


I = lambda : map(int, input().split(' '))
for _ in range(int(input())):
	n = int(input())
	arr = [*I()]
	s = 0
	for i in range(n - 1):
		s = s + max(0, arr[i] - arr[i + 1])
	if s <= arr[0]:
		print('YES')
	else:
		print('NO')


from math import ceil

def extreme(arr):
	ans = 0
	for i in range(len(arr) - 1):
		ans += max(arr[i + 1] - arr[i], 0)
	if arr[-1] - ans >= 0:
		return 'YES'
	return 'NO'
for i in range(int(input())):
	a = input()
	lst = list(map(int, input().strip().split()))
	print(extreme(lst))


total = int(input())
for _ in range(total):
	size = int(input())
	arr = [int(c) for c in input().split()]
	preOperationCount = arr[0]
	rightOperationCount = 0
	for val in arr:
		if val < rightOperationCount:
			print('NO')
			break
		else:
			rightOperationCount = max(val - preOperationCount, rightOperationCount)
			preOperationCount = min(preOperationCount, val - rightOperationCount)
	else:
		print('YES')


import bisect
import collections
import copy
import functools
import heapq
import itertools
import math
import random
import re
import sys
import time
import string
from typing import List
sys.setrecursionlimit(99999)

def solve(arr):
	dp = [arr[0], 0]
	for cur in range(1, len(arr)):
		for nq in range(max(dp[1], arr[cur] - dp[0]), arr[cur] + 1):
			if 0 <= arr[cur] - nq <= min(dp[0], arr[cur]):
				dp = [arr[cur] - nq, nq]
				break
			elif arr[cur] - nq < 0:
				return False
		else:
			return False
	return True
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	if solve(arr):
		print('YES')
	else:
		print('NO')


from sys import stdin, stdout
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	arr = list(map(int, stdin.readline().split()))
	minl = arr[0]
	maxl = 0
	for i in range(1, n):
		curr = arr[i]
		arr[i] = min(arr[i - 1], arr[i] - maxl)
		maxl = max(maxl, curr - arr[i])
	if arr[n - 1] < 0:
		print('NO')
	else:
		print('YES')


T = int(input())
for _ in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	(cur, maxn, flag, res) = (0, 0, 0, 1)
	for i in range(1, n):
		if flag == 0 and a[i] > a[i - 1]:
			maxn = a[i - 1]
			cur = a[i] - maxn
			flag = 1
		elif flag == 1 and a[i] >= cur:
			maxn = min(maxn, a[i] - cur)
			cur = a[i] - maxn
		elif flag == 1 and a[i] < cur:
			res = 0
			break
	if res:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split(' ')))
	x = 0
	while x < n - 1 and a[x] >= a[x + 1]:
		x += 1
	if x == n - 1:
		print('YES')
		continue
	else:
		onhold = a[x]
		chk = 0
		x += 1
		a[x] -= onhold
		for y in range(x + 1, n):
			if a[y - 1] > a[y]:
				chk = 1
				break
			if a[y] - onhold < a[y - 1]:
				onhold = a[y] - a[y - 1]
				a[y] = a[y - 1]
			else:
				a[y] -= onhold
		if chk == 1:
			print('NO')
		else:
			print('YES')


def solve():
	n = int(input().strip())
	arr = [int(x) for x in input().strip().split()]
	incr = [0] * n
	decr = [0] * n
	decr[0] = arr[0]
	for i in range(1, n):
		decr[i] = min(arr[i] - incr[i - 1], decr[i - 1])
		incr[i] = arr[i] - decr[i]
	for i in range(1, n):
		if incr[i] < incr[i - 1]:
			return 'NO'
		if incr[i] < 0:
			return 'NO'
	for i in range(1, n):
		if decr[i] > decr[i - 1]:
			return 'NO'
		if decr[i] < 0:
			return 'NO'
	return 'YES'
for _ in range(int(input().strip())):
	print(solve())


import sys
input = sys.stdin.readline
(T,) = map(int, input().split())
for _ in range(T):
	(N,) = map(int, input().split())
	X = list(map(int, input().split()))
	f = 0
	ks = -1
	si = -1
	i = 0
	for (b, x) in zip(X[:], X[1:]):
		if not f and b >= x:
			X[i] = 0
			i += 1
			continue
		if not f and b < x:
			f = 1
			X[i] = 0
			ks = b
			X[i + 1] -= ks
			i += 1
			continue
		if f:
			if X[i] and X[i + 1] >= X[i]:
				ks = min(ks, X[i + 1] - X[i])
				X[i + 1] -= min(ks, X[i + 1] - X[i])
			else:
				X[i + 1] -= ks
			i += 1
			continue
	f = 0
	for i in range(N - 1):
		if X[i] > X[i + 1]:
			print('NO')
			break
	else:
		print('YES')


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import gcd, ceil

def prod(a, mod=10 ** 9 + 7):
	ans = 1
	for each in a:
		ans = ans * each % mod
	return ans

def lcm(a, b):
	return a * b // gcd(a, b)

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
for _ in range(int(input()) if True else 1):
	n = int(input())
	a = list(map(int, input().split()))
	print('YES' if a[0] - sum((max(0, a[i - 1] - a[i]) for i in range(1, n))) >= 0 else 'NO')


import sys
from sys import stdin
tt = int(stdin.readline())
for loop in range(tt):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	r = a[0]
	l = 0
	for i in range(n):
		if r + l < a[i]:
			l = a[i] - r
		elif r + l > a[i]:
			r = a[i] - l
	if r >= 0:
		print('YES')
	else:
		print('NO')


import sys
readline = sys.stdin.readline
T = int(readline())
INF = 10 ** 9 + 7
Ans = [None] * T
for qu in range(T):
	N = int(readline())
	A = list(map(int, readline().split()))
	res = INF
	rem = 0
	for i in range(N):
		res = max(0, min(res, A[i] - rem))
		A[i] -= res
		rem = A[i]
	Ans[qu] = 'YES' if all((a2 - a1 >= 0 for (a1, a2) in zip(A, A[1:]))) else 'NO'
print('\n'.join(map(str, Ans)))


import sys
import os
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
T = int(input())
for _ in range(T):
	n = int(input())
	arr = list(map(int, input().split()))
	(dec, inc) = (10 ** 10, 0)
	ok = True
	for (i, v) in enumerate(arr):
		now = min(v - inc, dec)
		if now < 0:
			print('NO')
			break
		dec = now
		inc = v - dec
	else:
		print('YES')


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	for i in range(n - 1, 0, -1):
		a[i] -= a[i - 1]
	minus = 0
	for i in range(1, n):
		if a[i] < 0:
			minus -= a[i]
	if a[0] - minus >= 0:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline
t = int(input())
for you in range(t):
	n = int(input())
	l = input().split()
	li = [int(i) for i in l]
	l = [0]
	for i in range(1, n):
		z = l[-1]
		z = z + max(li[i] - li[i - 1], 0)
		l.append(z)
	poss = 1
	for i in range(n):
		if l[i] > li[i]:
			poss = 0
			break
	if poss:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	flag = True
	ar = list(map(int, input().split()))
	su = 0
	for i in range(n - 1):
		if ar[i] >= ar[i + 1]:
			su += ar[i] - ar[i + 1]
	if su <= ar[0]:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.buffer.readline

def solution():
	n = int(input())
	l = list(map(int, input().split()))
	pre = [0] * (n + 1)
	for i in range(1, n):
		if l[i] < l[i - 1]:
			pre[0] -= abs(l[i] - l[i - 1])
			pre[i + 1] += abs(l[i] - l[i - 1])
	for i in range(1, n + 1):
		pre[i] += pre[i - 1]
		l[i - 1] += pre[i]
	if l[0] < 0:
		print('NO')
		return
	for i in range(1, n):
		if l[i] < 0 or l[i] < l[i - 1]:
			print('NO')
			return
	print('YES')
t = int(input())
for _ in range(t):
	solution()


t = int(input())
for tt in range(0, t):
	n = int(input())
	p = list(map(int, input().split()))
	d = [0] * n
	for i in range(1, n):
		if p[i] <= p[i - 1]:
			d[0] -= p[i - 1] - p[i]
			d[i] += p[i - 1] - p[i]
	for i in range(1, n):
		d[i] += d[i - 1]
	st = 1
	for i in range(0, n):
		p[i] += d[i]
		if p[i] < 0:
			st = 0
		if i >= 1 and p[i - 1] > p[i]:
			st = 0
	if st == 1:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline

def possible(a):
	if len(a) == 0:
		return 'YES'
	if a[0] < 0:
		return 'NO'
	if len(a) == 1:
		return 'YES'
	if a[0] > a[1]:
		return possible(a[1:])
	if a[-1] > a[-2]:
		return possible(a[:-1])
	return possible([x - a[1] + a[0] for x in a[1:]])
tests = int(input())
for test in range(tests):
	n = int(input())
	a = list(map(int, input().split()))
	if n < 3:
		print('YES')
	else:
		reduceAll = 0
		for item in range(n - 1):
			diff = a[item] - a[item + 1]
			if a[item] - reduceAll < 0:
				a[-1] = -1
				break
			elif diff < 0:
				reduceAll -= diff
		if a[-1] - reduceAll < 0:
			print('NO')
		else:
			print('YES')


from collections import defaultdict as dft, deque, Counter
from heapq import heappush, heappop

def mp():
	return map(int, input().split())

def ml():
	return list(map(int, input().split()))
import sys
sys.setrecursionlimit(10 ** 5)
from math import ceil, log2
INT_MAX = sys.maxsize

def solve():

	def minVal(x, y):
		return x if x < y else y

	def getMid(s, e):
		return s + (e - s) // 2

	def RMQUtil(st, ss, se, qs, qe, index):
		if qs <= ss and qe >= se:
			return st[index]
		if se < qs or ss > qe:
			return INT_MAX
		mid = getMid(ss, se)
		return min(RMQUtil(st, ss, mid, qs, qe, 2 * index + 1), RMQUtil(st, mid + 1, se, qs, qe, 2 * index + 2))

	def RMQ(st, n, qs, qe):
		if qs < 0 or qe > n - 1 or qs > qe:
			print('Invalid Input')
			return -1
		return RMQUtil(st, 0, n - 1, qs, qe, 0)

	def constructSTUtil(arr, ss, se, st, si):
		if ss == se:
			st[si] = arr[ss]
			return arr[ss]
		mid = getMid(ss, se)
		st[si] = min(constructSTUtil(arr, ss, mid, st, si * 2 + 1), constructSTUtil(arr, mid + 1, se, st, si * 2 + 2))
		return st[si]

	def constructST(arr, n):
		x = int(ceil(log2(n)))
		max_size = 2 * int(2 ** x) - 1
		st = [0] * max_size
		constructSTUtil(arr, 0, n - 1, st, 0)
		return st

	def update(i, val):
		while i <= n:
			BIT[i] += val
			i += i & -i

	def getsm(i):
		sm = 0
		while i > 0:
			sm += BIT[i]
			i -= i & -i
		return sm
		mxn = 10 ** 9
	n = int(input())
	arr = list(map(int, input().split()))
	BIT = [0] * (n + 1)
	st = constructST(arr, n)
	pre = mxn
	for i in range(n - 1):
		temp = getsm(i + 1)
		if arr[i] - temp <= pre:
			pre = arr[i] - temp
		else:
			diff = arr[i] - temp - pre
			mn = RMQ(st, n, i + 1, n - 1) - temp
			if mn < diff:
				return 'NO'
			update(i + 1, diff)
	return 'YES'
	print(RMQ(st, n, 0, 0))
mxn = 10 ** 9
for _ in range(int(input())):
	print(solve())


def find_smallest_index(a):
	min_value = min(a)
	max_value = max(a)
	if min_value == max_value:
		return (0, True)
	n = len(a)
	for (i, v) in enumerate(a):
		if i > 0 and a[i - 1] != min_value and (a[i] == min_value):
			return (i, False)
		if i < n - 1 and a[i + 1] != min_value and (a[i] == min_value):
			return (i, False)

def can_make_zero(a):
	n = len(a)
	l = [0] * n
	r = [0] * n
	s = 0
	for i in range(1, n):
		d = a[i] - a[i - 1]
		if d > 0:
			s += d
		l[i] = s
	s = 0
	for i in range(n - 2, -1, -1):
		d = a[i + 1] - a[i]
		if d < 0:
			s -= d
		r[i] = s
	for i in range(n):
		if l[i] + r[i] > a[i]:
			return False
	return True

def can_make_zero_old(a):
	n = len(a)
	while True:
		(i, is_finished) = find_smallest_index(a)
		if a[i] < 0:
			return False
		if is_finished:
			return True
		if i > 0:
			delta = a[i - 1] - a[i]
			for x in range(i):
				a[x] -= delta
		if i < n - 1:
			delta = a[i + 1] - a[i]
			for x in range(i + 1, n):
				a[x] -= delta
n_samples = int(input())
for t in range(n_samples):
	n = int(input())
	a = list(map(int, input().split(' ')))
	print('YES' if can_make_zero(a) else 'NO')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if a[0] - sum((-min(a[i] - a[i - 1], 0) for i in range(1, n))) >= 0:
		print('YES')
	else:
		print('NO')


a = int(input())
for i in range(a):
	s = int(input())
	z = list(map(int, input().split()))
	dec = []
	inc = []
	dec.append(z[0])
	inc.append(0)
	flag = 0
	for i in range(1, len(z)):
		if z[i] == z[i - 1]:
			dec.append(dec[-1])
			inc.append(inc[-1])
		if z[i] > z[i - 1]:
			dec.append(dec[-1])
			inc.append(z[i] - dec[-1])
			if inc[-1] < inc[-2] or inc[-1] < 0:
				flag = 1
				break
		else:
			inc.append(inc[-1])
			dec.append(z[i] - inc[-1])
			if dec[-1] > dec[-2] or dec[-1] < 0:
				flag = 1
				break
	if flag == 0:
		print('YES')
	else:
		print('NO')


import heapq
import sys
input = iter(sys.stdin.read().splitlines()).__next__
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	left_max = 1000001
	right = a.copy() + [1000001]
	right_min = 0
	heapq.heapify(right)
	removed = {}
	i = 0
	while i < n:
		if a[i] > left_max + right[0]:
			print('NO')
			break
		max_ops_left = a[i] - right_min
		right_min = max(right_min, a[i] - left_max)
		left_max = min(left_max, max_ops_left)
		removed[a[i]] = removed.get(a[i], 0) + 1
		while right[0] in removed:
			smallest = heapq.heappop(right)
			removed[smallest] -= 1
			if removed[smallest] == 0:
				del removed[smallest]
		i += 1
	else:
		print('YES')


import sys

def input():
	return sys.stdin.readline().rstrip()

def slv():
	n = int(input())
	a = list(map(int, input().split()))
	(l, r) = (0, 1 << 128)

	def greedy_update(l, r, S):
		y = min(S - l, r)
		x = S - y
		return (x, y)
	for v in a:
		(new_l, new_r) = greedy_update(l, r, v)
		if new_r < 0:
			print('NO')
			return
		else:
			(l, r) = (new_l, new_r)
			continue
	print('YES')
	return

def main():
	t = int(input())
	for i in range(t):
		slv()
	return
main()


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	ans = 'YES'
	if n <= 2:
		print('YES')
	else:
		l1 = [0]
		l2 = [l[0]]
		for j in range(1, n):
			if l[j] <= l[j - 1]:
				l1.append(l1[-1])
				l2.append(l2[-1] - (l[j - 1] - l[j]))
			else:
				l1.append(l1[-1] + l[j] - l[j - 1])
				l2.append(l2[-1])
		for j in l2:
			if j < 0:
				ans = 'NO'
		print(ans)


for nt in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if n == 1:
		print('YES')
		continue
	(p, s) = ([a[0]], [a[-1]])
	for i in range(1, n):
		p.append(min(a[i], p[-1]))
	for i in range(n - 2, -1, -1):
		s.append(min(a[i], s[-1]))
	s = s[::-1]
	ans = 'YES'
	for i in range(1, n - 1):
		if a[i] > p[i - 1] + s[i + 1]:
			ans = 'NO'
			break
	if ans == 'NO':
		print(ans)
		continue
	new = [a[0]]
	for i in range(1, n):
		if a[i] == a[i - 1]:
			continue
		new.append(a[i])
	if len(new) == 1:
		print('YES')
		continue
	(high, low) = (0, 0)
	if new[0] > new[1]:
		high += 0
	else:
		low += new[0]
	if new[-1] > new[-2]:
		high += 0
	else:
		low += new[-1]
	n = len(new)
	for i in range(1, n - 1):
		if new[i] > new[i - 1] and new[i] > new[i + 1]:
			high += new[i]
		if new[i] < new[i - 1] and new[i] < new[i + 1]:
			low += new[i]
	if high > low:
		print('NO')
	else:
		print('YES')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = [0] * (n - 1)
	for i in range(n - 1):
		b[i] = a[i + 1] - a[i]
	mi = 10000000
	c = [0] * (n + 1)
	for i in range(n - 1):
		if b[i] < 0:
			c[i + 1] += b[i]
			c[0] -= b[i]
		else:
			c[i + 1] += b[i]
			c[-1] -= b[i]
	for i in range(n):
		c[i + 1] += c[i]
	for i in range(n):
		if c[i] > a[i]:
			print('NO')
			break
	else:
		print('YES')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	d = a[0]
	k = 1
	while d >= 0 and k < n:
		diff = a[k] - a[k - 1]
		if diff < 0:
			d += diff
		k += 1
	if d < 0:
		print('NO')
	else:
		print('YES')


import sys
from math import gcd, sqrt, ceil, log2
from collections import defaultdict, Counter, deque
from bisect import bisect_left, bisect_right
import math
sys.setrecursionlimit(2 * 10 ** 5 + 10)
import heapq
from itertools import permutations
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
aa = 'abcdefghijklmnopqrstuvwxyz'

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def get_sum(bit, i):
	s = 0
	i += 1
	while i > 0:
		s += bit[i]
		i -= i & -i
	return s

def update(bit, n, i, v):
	i += 1
	while i <= n:
		bit[i] += v
		i += i & -i

def modInverse(b, m):
	g = math.gcd(b, m)
	if g != 1:
		return -1
	else:
		return pow(b, m - 2, m)

def primeFactors(n):
	sa = []
	while n % 2 == 0:
		sa.append(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			sa.append(i)
			n = n // i
	if n > 2:
		sa.append(n)
	return sa

def seive(n):
	pri = [True] * (n + 1)
	p = 2
	while p * p <= n:
		if pri[p] == True:
			for i in range(p * p, n + 1, p):
				pri[i] = False
		p += 1
	return pri

def check_prim(n):
	if n < 0:
		return False
	for i in range(2, int(sqrt(n)) + 1):
		if n % i == 0:
			return False
	return True

def getZarr(string, z):
	n = len(string)
	(l, r, k) = (0, 0, 0)
	for i in range(1, n):
		if i > r:
			(l, r) = (i, i)
			while r < n and string[r - l] == string[r]:
				r += 1
			z[i] = r - l
			r -= 1
		else:
			k = i - l
			if z[k] < r - i + 1:
				z[i] = z[k]
			else:
				l = i
				while r < n and string[r - l] == string[r]:
					r += 1
				z[i] = r - l
				r -= 1

def search(text, pattern):
	concat = pattern + '$' + text
	l = len(concat)
	z = [0] * l
	getZarr(concat, z)
	ha = []
	for i in range(l):
		if z[i] == len(pattern):
			ha.append(i - len(pattern) - 1)
	return ha

def mergeIntervals(arr):
	arr.sort(key=lambda x: x[0])
	m = []
	s = -10000
	max = -100000
	for i in range(len(arr)):
		a = arr[i]
		if a[0] > max:
			if i != 0:
				m.append([s, max])
			max = a[1]
			s = a[0]
		elif a[1] >= max:
			max = a[1]
	if max != -100000 and [s, max] not in m:
		m.append([s, max])
	return m

class SortedList:

	def __init__(self, iterable=[], _load=200):
		values = sorted(iterable)
		self._len = _len = len(values)
		self._load = _load
		self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
		self._list_lens = [len(_list) for _list in _lists]
		self._mins = [_list[0] for _list in _lists]
		self._fen_tree = []
		self._rebuild = True

	def _fen_build(self):
		self._fen_tree[:] = self._list_lens
		_fen_tree = self._fen_tree
		for i in range(len(_fen_tree)):
			if i | i + 1 < len(_fen_tree):
				_fen_tree[i | i + 1] += _fen_tree[i]
		self._rebuild = False

	def _fen_update(self, index, value):
		if not self._rebuild:
			_fen_tree = self._fen_tree
			while index < len(_fen_tree):
				_fen_tree[index] += value
				index |= index + 1

	def _fen_query(self, end):
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		x = 0
		while end:
			x += _fen_tree[end - 1]
			end &= end - 1
		return x

	def _fen_findkth(self, k):
		_list_lens = self._list_lens
		if k < _list_lens[0]:
			return (0, k)
		if k >= self._len - _list_lens[-1]:
			return (len(_list_lens) - 1, k + _list_lens[-1] - self._len)
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		idx = -1
		for d in reversed(range(len(_fen_tree).bit_length())):
			right_idx = idx + (1 << d)
			if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
				idx = right_idx
				k -= _fen_tree[idx]
		return (idx + 1, k)

	def _delete(self, pos, idx):
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len -= 1
		self._fen_update(pos, -1)
		del _lists[pos][idx]
		_list_lens[pos] -= 1
		if _list_lens[pos]:
			_mins[pos] = _lists[pos][0]
		else:
			del _lists[pos]
			del _list_lens[pos]
			del _mins[pos]
			self._rebuild = True

	def _loc_left(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(lo, pos) = (-1, len(_lists) - 1)
		while lo + 1 < pos:
			mi = lo + pos >> 1
			if value <= _mins[mi]:
				pos = mi
			else:
				lo = mi
		if pos and value <= _lists[pos - 1][-1]:
			pos -= 1
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value <= _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def _loc_right(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(pos, hi) = (0, len(_lists))
		while pos + 1 < hi:
			mi = pos + hi >> 1
			if value < _mins[mi]:
				hi = mi
			else:
				pos = mi
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value < _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def add(self, value):
		_load = self._load
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len += 1
		if _lists:
			(pos, idx) = self._loc_right(value)
			self._fen_update(pos, 1)
			_list = _lists[pos]
			_list.insert(idx, value)
			_list_lens[pos] += 1
			_mins[pos] = _list[0]
			if _load + _load < len(_list):
				_lists.insert(pos + 1, _list[_load:])
				_list_lens.insert(pos + 1, len(_list) - _load)
				_mins.insert(pos + 1, _list[_load])
				_list_lens[pos] = _load
				del _list[_load:]
				self._rebuild = True
		else:
			_lists.append([value])
			_mins.append(value)
			_list_lens.append(1)
			self._rebuild = True

	def discard(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_right(value)
			if idx and _lists[pos][idx - 1] == value:
				self._delete(pos, idx - 1)

	def remove(self, value):
		_len = self._len
		self.discard(value)
		if _len == self._len:
			raise ValueError('{0!r} not in list'.format(value))

	def pop(self, index=-1):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		value = self._lists[pos][idx]
		self._delete(pos, idx)
		return value

	def bisect_left(self, value):
		(pos, idx) = self._loc_left(value)
		return self._fen_query(pos) + idx

	def bisect_right(self, value):
		(pos, idx) = self._loc_right(value)
		return self._fen_query(pos) + idx

	def count(self, value):
		return self.bisect_right(value) - self.bisect_left(value)

	def __len__(self):
		return self._len

	def __getitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		return self._lists[pos][idx]

	def __delitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		self._delete(pos, idx)

	def __contains__(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_left(value)
			return idx < len(_lists[pos]) and _lists[pos][idx] == value
		return False

	def __iter__(self):
		return (value for _list in self._lists for value in _list)

	def __reversed__(self):
		return (value for _list in reversed(self._lists) for value in reversed(_list))

	def __repr__(self):
		return 'SortedList({0})'.format(list(self))

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def sol(n):
	seti = set()
	for i in range(1, int(sqrt(n)) + 1):
		if n % i == 0:
			seti.add(n // i)
			seti.add(i)
	return seti

def lcm(a, b):
	return a * b // gcd(a, b)
t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	if n == 1:
		print('YES')
		continue
	flag = 0
	for i in range(1, n):
		if l[i - 1] > l[i]:
			z = l[i - 1] - l[i]
			if l[0] - z < 0:
				flag = 1
				break
			else:
				l[0] -= z
	if flag:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	x = 10 ** 9
	y = 0
	for a in map(int, input().split()):
		if a < x + y:
			x = a - y
			if x < 0:
				print('NO')
				break
		else:
			y = a - x
	else:
		print('YES')


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	diff = [0] * n
	diff[0] = arr[0]
	sum = 0
	for i in range(1, n):
		diff[i] = arr[i] - arr[i - 1]
		if diff[i] < 0:
			sum -= diff[i]
	if sum > diff[0]:
		print('NO')
	else:
		print('YES')


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if n <= 2:
		print('YES')
	else:
		for j in range(1, n):
			if a[j] > a[j - 1]:
				break
		rrr = 0
		x = a[j - 1]
		for jj in range(j, n - 1):
			if a[jj + 1] < a[jj]:
				rrr = rrr + a[jj] - a[jj + 1]
		if x >= rrr:
			print('YES')
		else:
			print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	d = [0] * n
	d[0] = a[0]
	can = True
	for i in range(1, n):
		d[i] = a[i] - a[i - 1]
		if d[i] < 0:
			d[0] += d[i]
			d[i] = 0
			if d[0] < 0:
				can = False
				break
		elif d[i] > 0:
			d[i] -= d[i]
	print('YES') if can else print('NO')


for _ in range(0, int(input())):
	n = int(input())
	arr = [int(x) for x in input().split()]
	lst = arr[0]
	bad = False
	arr[0] = 0
	for i in range(1, n):
		dec = min(lst, arr[i] - arr[i - 1])
		lst = dec
		arr[i] -= dec
		if dec < 0:
			bad = True
	print('NO' if bad else 'YES')


n = int(input())
answer = []
for i in range(n):
	k = int(input())
	list = input().split()
	for j in range(k):
		list[j] = int(list[j])
	result = True
	leftIndex = 0
	leftPoints = list[0]
	rightPoints = 0
	rightMaxPoints = 0
	for j in range(1, k - 1):
		if list[j] < rightPoints:
			result = False
			break
		if list[j] < leftPoints + rightPoints:
			if list[j] < rightPoints:
				result = False
				break
			else:
				leftPoints = list[j] - rightPoints
		else:
			rightPoints = list[j] - leftPoints
	if list[k - 1] < rightPoints:
		result = False
	answer.append(result)
for i in range(n):
	if answer[i]:
		print('YES')
	else:
		print('NO')


t = int(input())
for case in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	x = 0
	low = a[0]
	works = True
	for i in range(1, n):
		if a[i] < x:
			print('NO')
			works = False
			break
		next_low = low
		if a[i] - x < low:
			next_low = a[i] - x
		if a[i] - low > x:
			x = a[i] - low
		low = next_low
	if works:
		print('YES')


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	x = 0
	flag = 1
	for i in range(1, n):
		x = max(x, a[i] - a[i - 1])
		a[i] -= x
		if a[i] < 0:
			flag = 0
			print('NO')
			break
	if flag:
		print('YES')


def solve(n, a):
	s = sum([max(0, a[i] - a[i + 1]) for i in range(n - 1)])
	print('YES') if s <= a[0] else print('NO')
for j in range(int(input())):
	solve(int(input()), list(map(int, input().split())))


import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7

def resolve():
	t = int(input())
	for _ in range(t):
		n = int(input())
		A = list(map(int, input().split()))
		B = [A[i + 1] - A[i] for i in range(n - 1)]
		plus = A[-1]
		need_plus = 0
		for i in range(n - 1):
			if B[i] >= 0:
				need_plus += B[i]
		print('YES' if plus >= need_plus else 'NO')
resolve()


import sys

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c for j in range(b)] for i in range(a)]

def list3d(a, b, c, d):
	return [[[d for k in range(c)] for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e for l in range(d)] for k in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 19
MOD = 10 ** 9 + 7
EPS = 10 ** (-10)
for _ in range(INT()):
	N = INT()
	A = LIST()
	cur = A[0]
	A[0] = 0
	for i in range(1, N):
		use = max(min(cur, A[i] - A[i - 1]), 0)
		A[i] -= use
		cur = use
	ok = True
	for i in range(1, N):
		if A[i - 1] > A[i]:
			ok = False
			break
	if ok:
		YES()
	else:
		NO()


import sys
input = sys.stdin.readline

def fA(n, A):
	flag = 0
	B = [0 for i in range(n)]
	v = A[n - 1]
	for i in range(n - 2, -1, -1):
		v = min(A[i], v)
		B[i] = A[i] - v
	v = A[0]
	flag = 0
	f1 = 0
	vm = 0
	for i in range(1, n):
		(v1, v2) = (A[i], B[i])
		if v1 <= v and f1 == 0:
			v = v1
		elif v2 <= v:
			f1 = 1
			v = min(v, v1 - vm)
			vm = max(vm, v1 - v)
		else:
			flag = 1
			break
	return flag
T = int(input())
for _ in range(T):
	n = int(input())
	A = list(map(int, input().split()))
	flag = fA(n, A)
	if flag == 0:
		print('YES')
	else:
		print('NO')


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=2 ** 32, func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: max(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] <= key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater

class TrieNode:

	def __init__(self):
		self.children = [None] * 26
		self.isEndOfWord = False

class Trie:

	def __init__(self):
		self.root = self.getNode()

	def getNode(self):
		return TrieNode()

	def _charToIndex(self, ch):
		return ord(ch) - ord('a')

	def insert(self, key):
		pCrawl = self.root
		length = len(key)
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				pCrawl.children[index] = self.getNode()
			pCrawl = pCrawl.children[index]
		pCrawl.isEndOfWord = True

	def search(self, key):
		pCrawl = self.root
		length = len(key)
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				return False
			pCrawl = pCrawl.children[index]
		return pCrawl != None and pCrawl.isEndOfWord

class Node:

	def __init__(self, data):
		self.data = data
		self.count = 0
		self.left = None
		self.right = None

class BinaryTrie:

	def __init__(self):
		self.root = Node(0)

	def insert(self, pre_xor):
		self.temp = self.root
		for i in range(31, -1, -1):
			val = pre_xor & 1 << i
			if val:
				if not self.temp.right:
					self.temp.right = Node(0)
				self.temp = self.temp.right
				self.temp.count += 1
			if not val:
				if not self.temp.left:
					self.temp.left = Node(0)
				self.temp = self.temp.left
				self.temp.count += 1
		self.temp.data = pre_xor

	def query(self, xor):
		self.temp = self.root
		for i in range(31, -1, -1):
			val = xor & 1 << i
			if not val:
				if self.temp.left and self.temp.left.count > 0:
					self.temp = self.temp.left
				elif self.temp.right:
					self.temp = self.temp.right
			elif self.temp.right and self.temp.right.count > 0:
				self.temp = self.temp.right
			elif self.temp.left:
				self.temp = self.temp.left
			self.temp.count -= 1
		return xor ^ self.temp.data
for ik in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	ans = 0
	f = 0
	for i in range(n - 2, -1, -1):
		if l[i] - ans < 0:
			print('NO')
			f = 1
			break
		l[i] -= ans
		ans += max(0, l[i] - l[i + 1])
		l[i] = min(l[i], l[i + 1])
	if f == 1:
		continue
	print('YES')


import sys
sys.setrecursionlimit(10 ** 5)
from collections import defaultdict as dft, deque, Counter
from heapq import heappush, heappop

def mp():
	return map(int, input().split())

def ml():
	return list(map(int, input().split()))

def solve():
	n = int(input())
	arr = ml()
	mini = [0] * n
	mn = mxn
	for i in range(n - 1, -1, -1):
		mini[i] = mn
		mn = min(mn, arr[i])
	delkiye = 0
	pre = mxn
	for i in range(n - 1):
		if arr[i] - delkiye <= pre:
			pre = arr[i] - delkiye
		else:
			diff = arr[i] - delkiye - pre
			mn = mini[i] - delkiye
			if mn < diff:
				return 'NO'
			delkiye += diff
	return 'YES'
mxn = 10 ** 9
for _ in range(int(input())):
	print(solve())


T = int(input())
for _ in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	s = 0
	for i in range(n - 1):
		s += max(0, a[i] - a[i + 1])
	if s <= a[0]:
		print('YES')
		continue
	print('NO')


import os
import sys
from io import BytesIO, IOBase
import heapq as h
from bisect import bisect_left, bisect_right
from types import GeneratorType
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import defaultdict as dd, deque as dq
import math, string

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())
MOD = 10 ** 9 + 7

def solve():
	N = getInt()
	A = getInts()
	count = 0
	min_left = []
	min_right = []
	curr_left = curr_right = 10 ** 9
	for j in range(N):
		if j == 0:
			max_sub = A[j]
		else:
			max_sub = min(max_sub, A[j] - A[j - 1])
		max_sub = min(max_sub, A[j])
		max_sub = max(max_sub, 0)
		A[j] -= max_sub
	for j in range(N - 1):
		if A[j] > A[j + 1]:
			return 'NO'
	return 'YES'
for _ in range(getInt()):
	print(solve())


T = int(input())
for _ in range(0, T):
	n = int(input())
	s = [int(x) for x in input().split()]
	l = [1000000000]
	r = [0]
	ans = 'YES'
	for i in range(0, len(s)):
		if r[-1] > s[i]:
			ans = 'NO'
			break
		mn = r[-1]
		rem = s[i] - mn
		mx = l[-1]
		if rem <= l[-1]:
			r.append(mn)
			l.append(rem)
		else:
			rq = rem - l[-1]
			r.append(mn + rq)
			l.append(l[-1])
		if r[-1] < 0 or l[-1] < 0:
			ans = 'NO'
			break
	print(ans)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	if n == 1:
		print('YES')
		continue
	d = [a[0]] + [a[i] - a[i - 1] for i in range(1, n)] + [-a[n - 1]]
	need_plus = 0
	for i in range(1, len(d) - 1):
		if d[i] > 0:
			need_plus += d[i]
	if need_plus <= a[n - 1]:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline
import random
t = int(input())
for tests in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	REST = [-1] * n
	MIN = 1 << 60
	RESTMAX = 0
	for i in range(n):
		MIN = min(MIN, A[i])
		if A[i] - MIN < RESTMAX:
			MIN = max(0, A[i] - RESTMAX)
			REST[i] = A[i] - MIN
			RESTMAX = max(RESTMAX, REST[i])
		else:
			REST[i] = A[i] - MIN
			RESTMAX = max(RESTMAX, REST[i])
	for i in range(1, n):
		if REST[i - 1] == 0:
			continue
		if REST[i - 1] > REST[i]:
			print('NO')
			break
	else:
		print('YES')


def satyam(a, n):
	i = 0
	sum = 0
	t = a[0]
	while i < n - 1 and sum <= t:
		s = a[i] - a[i + 1]
		if s > 0:
			sum += s
		i += 1
	if sum <= t:
		return 'YES'
	return 'NO'
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(p) for p in input().split()]
	print(satyam(a, n))


from sys import *
for _ in range(int(input())):
	n = int(stdin.readline())
	m = list(map(int, iter(stdin.readline().split())))
	A = m[0] - sum((max(0, m[i - 1] - m[i]) for i in range(1, n)))
	if A >= 0:
		stdout.write(str('YES') + '\n')
	else:
		stdout.write(str('NO') + '\n')


def read_ints():
	return map(int, input().split())
t_n = int(input())
for i_t in range(t_n):
	n = int(input())
	a = list(read_ints())
	deltas = [x2 - x1 for (x1, x2) in zip(a, a[1:])]
	r = [0] * n
	acc = 0
	for (i, delta) in enumerate(deltas):
		if delta > 0:
			acc += delta
		r[i + 1] += acc
	acc = 0
	for (i, delta) in list(enumerate(deltas))[::-1]:
		if delta < 0:
			acc += abs(delta)
		r[i] += acc
	if all((x >= rx for (x, rx) in zip(a, r))):
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	m = arr[0]
	i = 1
	broke = False
	while i < n:
		if arr[i] < arr[i - 1]:
			if arr[i - 1] - arr[i] <= m:
				m -= arr[i - 1] - arr[i]
				m = min(m, arr[i])
			else:
				broke = True
				break
		i += 1
	if broke:
		print('NO')
	else:
		print('YES')


for s in [*open(0)][2::2]:
	(x, *l) = map(int, s.split())
	a = 'YES'
	y = 0
	for i in l:
		x = min(x, i - y)
		y = max(y, i - x)
		if x < 0:
			a = 'NO'
			break
	print(a)


import sys, io, os
Z = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
for _ in range(int(Z())):
	n = int(Z())
	a = [*map(int, Z().split())]
	l = a[0]
	r = 0
	for i in range(1, n):
		if a[i] > l + r:
			r += a[i] - l - r
		else:
			l += a[i] - l - r
		if l < 0:
			break
	else:
		print('YES')
		continue
	print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	b = list(map(int, input().split()))
	j = 1
	s = 0
	while j < n:
		s += max(b[j] - b[j - 1], 0)
		j += 1
	if b[-1] >= s:
		print('YES')
	else:
		print('NO')


def rangeUpdate(t, node, tl, tr, l, r, val):
	if tl == l and tr == r:
		t[node][1] += val
		return
	mid = (tl + tr) // 2
	if r <= mid:
		rangeUpdate(t, 2 * node, tl, mid, l, r, val)
	elif l > mid:
		rangeUpdate(t, 2 * node + 1, mid + 1, tr, l, r, val)
	else:
		rangeUpdate(t, 2 * node, tl, mid, l, mid, val)
		rangeUpdate(t, 2 * node + 1, mid + 1, tr, mid + 1, r, val)

def pointQuery(t, node, tl, tr, index):
	if tl == tr:
		return t[node][0] + t[node][1]
	mid = (tl + tr) // 2
	if index <= mid:
		return t[node][1] + pointQuery(t, 2 * node, tl, mid, index)
	return t[node][1] + pointQuery(t, 2 * node + 1, mid + 1, tr, index)

def solve(arr, n, ans):
	t = [[0 for j in range(2)] for i in range(4 * n + 1)]
	for i in range(n):
		rangeUpdate(t, 1, 0, n - 1, i, i, arr[i])
	for i in range(1, n):
		curr = pointQuery(t, 1, 0, n - 1, i)
		left = pointQuery(t, 1, 0, n - 1, i - 1)
		if curr > left:
			diff = curr - left
			rangeUpdate(t, 1, 0, n - 1, i, n - 1, -diff)
		elif left > curr:
			diff = left - curr
			rangeUpdate(t, 1, 0, n - 1, 0, i - 1, -diff)
	for i in range(n):
		if pointQuery(t, 1, 0, n - 1, i) < 0:
			ans.append('NO')
			return
	ans.append('YES')

def main():
	t = int(input())
	ans = []
	for i in range(t):
		n = int(input())
		arr = list(map(int, input().split()))
		solve(arr, n, ans)
	print('\n'.join(ans))
main()


import sys

def eprint(*args):
	print(*args, file=sys.stderr)
zz = 1
if zz:
	input = sys.stdin.readline

def li():
	return [int(xx) for xx in input().split()]

def fi():
	return int(input())

def mi():
	return map(int, input().split())
t = fi()
while t > 0:
	t -= 1
	n = fi()
	a = li()
	pre = [10 ** 18] * (n + 1)
	suf = [10 ** 18] * (n + 1)
	for i in range(n):
		pre[i] = min(pre[i - 1], a[i])
	for i in range(n - 1, -1, -1):
		suf[i] = min(suf[i + 1], a[i])
	flag = 0
	r = [0] * (n + 1)
	l = [0] * (n + 1)
	for i in range(n):
		if pre[i - 1] + suf[i + 1] < a[i]:
			flag = 1
			break
	for i in range(n):
		c = max(0, a[i] - pre[i - 1])
		l[i] = max(l[i - 1], c)
	for i in range(n - 1, -1, -1):
		d = max(0, a[i] - suf[i + 1])
		r[i] = max(r[i + 1], d)
	for i in range(n - 1, -1, -1):
		suf[i] = min(suf[i + 1], a[i] - r[i])
	for i in range(n):
		pre[i] = min(pre[i - 1], a[i] - l[i])
		if l[i] + r[i] > a[i] or pre[i - 1] + suf[i + 1] < a[i]:
			flag = 1
			break
	print('YES' if flag == 0 else 'NO')


inf = 10 ** 9

def solve():
	l = inf
	r = -1
	for a in aa:
		l = min(a, l, a - r)
		r = a - l
		if l < 0 or r < 0:
			return 'NO'
	return 'YES'
for _ in range(int(input())):
	n = int(input())
	aa = list(map(int, input().split()))
	print(solve())


tests = int(input())
for test in range(tests):
	n = int(input())
	a = list(map(int, input().split()))
	l = [0] * n
	r = [0] * n
	for i in range(n):
		if i > 0 and a[i] > a[i - 1]:
			l[i] = a[i] - a[i - 1]
		if i < n - 1 and a[i] > a[i + 1]:
			r[i] = a[i] - a[i + 1]
	rr = 0
	for i in range(n):
		rr += l[i]
		a[i] -= rr
	ll = 0
	for i in range(n - 1, -1, -1):
		ll += r[i]
		a[i] -= ll
	if a[0] >= 0 and sum(a) == a[0] * n:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	curr = A[0]
	for j in range(1, n):
		curr = min(curr, A[j] - (A[j - 1] - curr))
		if curr < 0:
			print('NO')
			break
	else:
		print('YES')


def read_generator():
	while True:
		tokens = input().split(' ')
		for t in tokens:
			yield t
reader = read_generator()

def readword():
	return next(reader)

def readint():
	return int(next(reader))

def readfloat():
	return float(next(reader))

def readline():
	return input()

def solve(a, n):
	l = [a[0]]
	for i in range(1, n):
		l.append(min(l[i - 1], a[i - 1]))
	r = [a[-1]]
	j = 0
	for i in range(n - 2, -1, -1):
		r.append(min(r[j], a[i + 1]))
		j += 1
	r = list(reversed(r))
	for i in range(n):
		if l[i] + r[i] < a[i]:
			return 'NO'
	b = a[:]
	m = b[0]
	d = 0
	for i in range(1, n):
		b[i] -= d
		if b[i] > m:
			d += b[i] - m
			b[i] = m
		else:
			m = b[i]
	if b[-1] >= 0:
		return 'YES'
	b = list(reversed(a[:]))
	m = b[0]
	d = 0
	for i in range(1, n):
		b[i] -= d
		if b[i] > m:
			d += b[i] - m
			b[i] = m
		else:
			m = b[i]
	return 'YES' if b[-1] >= 0 else 'NO'
tests = readint()
for t in range(tests):
	n = readint()
	a = [readint() for _ in range(n)]
	b = [a[0]]
	for i in range(1, n):
		if a[i] != b[len(b) - 1]:
			b.append(a[i])
	print(solve(b, len(b)))


import sys
input = sys.stdin.buffer.readline
ri = lambda : int(input())
rl = lambda : list(map(int, input().split()))
rs = lambda : input().decode().rstrip('\n\r')
wrt = sys.stdout.write
pr = lambda *args, end='\n': wrt(' '.join([str(x) for x in args]) + end)
xrange = lambda args: reversed(range(args))
cdiv = lambda x, y: -(-x // y)
enum = enumerate
inf = float('inf')
mod = 10 ** 9 + 7

class LazySegmentTree:

	def __init__(self, data, default=0, func=max):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self._lazy = [0] * (2 * _size)
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __len__(self):
		return self._len

	def _push(self, idx):
		(q, self._lazy[idx]) = (self._lazy[idx], 0)
		self._lazy[2 * idx] += q
		self._lazy[2 * idx + 1] += q
		self.data[2 * idx] += q
		self.data[2 * idx + 1] += q

	def _update(self, idx):
		for i in reversed(range(1, idx.bit_length())):
			self._push(idx >> i)

	def _build(self, idx):
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1]) + self._lazy[idx]
			idx >>= 1

	def add(self, start, stop, value):
		start = start_copy = start + self._size
		stop = stop_copy = stop + self._size
		while start < stop:
			if start & 1:
				self._lazy[start] += value
				self.data[start] += value
				start += 1
			if stop & 1:
				stop -= 1
				self._lazy[stop] += value
				self.data[stop] += value
			start >>= 1
			stop >>= 1
		self._build(start_copy)
		self._build(stop_copy - 1)

	def query(self, start, stop, default=0):
		start += self._size
		stop += self._size
		self._update(start)
		self._update(stop - 1)
		res = default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'LazySegmentTree({0})'.format(self.data)
Cases = ri()
for Case in range(Cases):
	n = ri()
	a = rl()
	a = LazySegmentTree(a, func=lambda x, y: x + y)
	for i in range(n - 1):
		now = a.query(i, i + 1)
		nex = a.query(i + 1, i + 2)
		if now < 0 or nex < 0:
			print('NO')
			break
		diff = abs(now - nex)
		if now >= nex:
			a.add(0, i + 1, -diff)
		else:
			a.add(i + 1, n, -diff)
	else:
		print('YES')


import sys
from copy import *
from bisect import *
from math import gcd, ceil, sqrt
from itertools import permutations as prm, product

def eprint(*args):
	print(*args, file=sys.stderr)
zz = 1
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('all.txt', 'w')
di = [[-1, 0], [1, 0], [0, 1], [0, -1]]

def string(s):
	return ''.join(s)

def fori(n):
	return [fi() for i in range(n)]

def inc(d, c, x=1):
	d[c] = d[c] + x if c in d else x

def bo(i):
	return ord(i) - ord('A')

def li():
	return [int(xx) for xx in input().split()]

def fli():
	return [float(x) for x in input().split()]

def comp(a, b):
	if a > b:
		return 2
	return 2 if a == b else 0

def gi():
	return [xx for xx in input().split()]

def cil(n, m):
	return n // m + int(n % m > 0)

def fi():
	return int(input())

def pro(a):
	return reduce(lambda a, b: a * b, a)

def swap(a, i, j):
	(a[i], a[j]) = (a[j], a[i])

def si():
	return list(input().rstrip())

def mi():
	return map(int, input().split())

def gh():
	sys.stdout.flush()

def isvalid(i, j, n, m):
	return 0 <= i < n and 0 <= j < m

def bo(i):
	return ord(i) - ord('a')

def graph(n, m):
	for i in range(m):
		(x, y) = mi()
		a[x].append(y)
		a[y].append(x)
t = fi()
while t > 0:
	t -= 1
	n = fi()
	a = li()
	pre = [10 ** 18] * (n + 1)
	suf = [10 ** 18] * (n + 1)
	for i in range(n):
		pre[i] = min(pre[i - 1], a[i])
	for i in range(n - 1, -1, -1):
		suf[i] = min(suf[i + 1], a[i])
	flag = 0
	r = [0] * (n + 1)
	l = [0] * (n + 1)
	for i in range(n):
		if pre[i - 1] + suf[i + 1] < a[i]:
			flag = 1
			break
	for i in range(n):
		c = max(0, a[i] - pre[i - 1])
		l[i] = max(l[i - 1], c)
	for i in range(n - 1, -1, -1):
		d = max(0, a[i] - suf[i + 1])
		r[i] = max(r[i + 1], d)
	for i in range(n - 1, -1, -1):
		suf[i] = min(suf[i + 1], a[i] - r[i])
	for i in range(n):
		pre[i] = min(pre[i - 1], a[i] - l[i])
		if l[i] + r[i] > a[i] or pre[i - 1] + suf[i + 1] < a[i]:
			flag = 1
			break
	print('YES' if flag == 0 else 'NO')


import sys
input = sys.stdin.buffer.readline
ri = lambda : int(input())
rl = lambda : list(map(int, input().split()))
rs = lambda : input().decode().rstrip('\n\r')
wrt = sys.stdout.write
pr = lambda *args, end='\n': wrt(' '.join([str(x) for x in args]) + end)
xrange = lambda args: reversed(range(args))
cdiv = lambda x, y: -(-x // y)
enum = enumerate
inf = float('inf')
mod = 10 ** 9 + 7
Cases = ri()
for Case in range(Cases):
	n = ri()
	a = rl()
	update = 0
	for i in range(n - 1):
		if update > a[i] or update > a[i + 1]:
			print('NO')
			break
		update += max(0, a[i + 1] - a[i])
	else:
		print('YES')


for y in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	cnt = 0
	for i in range(n - 1):
		if lst[i] > lst[i + 1]:
			cnt += lst[i] - lst[i + 1]
	if cnt <= lst[0]:
		print('YES')
	else:
		print('NO')


import os
from io import BytesIO, IOBase
import sys
from collections import defaultdict, deque, Counter
from bisect import *
from math import sqrt, pi, ceil, log, inf, gcd
from itertools import permutations
from copy import deepcopy
from heapq import *
from sys import setrecursionlimit

def main():
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		d = 0
		for i in range(n - 1):
			if a[i] < d:
				d = -1
				break
			if a[i] < a[i + 1]:
				d += a[i + 1] - a[i]
		if d > a[-1]:
			d = -1
		print('NO' if d == -1 else 'YES')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
import math
import heapq
import bisect
from collections import Counter
from collections import defaultdict
from io import BytesIO, IOBase
import string

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None
		self.BUFSIZE = 8192

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, self.BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, self.BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def get_int():
	return int(input())

def get_ints():
	return list(map(int, input().split(' ')))

def get_int_grid(n):
	return [get_ints() for _ in range(n)]

def get_str():
	return input().split(' ')

def yes_no(b):
	if b:
		return 'YES'
	else:
		return 'NO'

def binary_search(good, left, right, delta=1, right_true=False):
	limits = [left, right]
	while limits[1] - limits[0] > delta:
		if delta == 1:
			mid = sum(limits) // 2
		else:
			mid = sum(limits) / 2
		if good(mid):
			limits[int(right_true)] = mid
		else:
			limits[int(~right_true)] = mid
	if good(limits[int(right_true)]):
		return limits[int(right_true)]
	else:
		return False

def prefix_sums(a):
	p = [0]
	for x in a:
		p.append(p[-1] + x)
	return p

def solve_a():
	n = get_int()
	x = get_ints()
	a = [x[0]]
	b = [0]
	for i in range(1, n):
		a.append(max(0, min(a[-1], x[i] - b[-1])))
		b.append(x[i] - a[-1])
	for i in range(1, n):
		if b[i] < b[i - 1]:
			return False
	return True
t = get_int()
for _ in range(t):
	print(yes_no(solve_a()))


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	a += [a[-1], a[0]]
	min_a = a[0]
	min_i = 0
	for i in range(n):
		if a[i] < min_a:
			min_i = i
			min_a = a[i]
	need = 0
	for i in range(n):
		if i == min_i:
			break
		if a[i] > a[i - 1]:
			need += a[i] - a[i - 1]
	for i in range(n - 1, -1, -1):
		if i == min_i:
			break
		if a[i] > a[i + 1]:
			need += a[i] - a[i + 1]
	print('YES' if need <= min_a else 'NO')


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	l = a[0]
	r = 0
	for i in range(1, n):
		x = a[i]
		x -= r
		if x < 0:
			return 'NO'
		if x > l:
			r += x - l
		else:
			l = x
	return 'YES'
t = int(input())
i = 0
while i < t:
	print(solve())
	i += 1


import sys
import random
input = sys.stdin.readline

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def lcm(a, b):
	return a * b / gcd(a, b)

def main():
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		f = 0
		maxx = float('inf')
		sub = 0
		for i in range(n - 1, -1, -1):
			if a[i] - sub < 0:
				f = 1
			if a[i] - sub <= maxx:
				maxx = a[i] - sub
			else:
				sub += -maxx + (a[i] - sub)
		if f:
			print('NO')
		else:
			print('YES')
	return
main()


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline()

def RL():
	return map(int, sys.stdin.readline().split())

def RLL():
	return list(map(int, sys.stdin.readline().split()))

def N():
	return int(input())

def print_list(l):
	print(' '.join(map(str, l)))
for _ in range(N()):
	n = N()
	a = RLL()
	count = 0
	b = [0, a[0]] + [a[i] for i in range(1, n) if a[i] != a[i - 1]] + [100000000]
	c = [b[i] for i in range(1, len(b) - 1) if b[i] > b[i - 1] and b[i] > b[i + 1] or (b[i] < b[i - 1] and b[i] < b[i + 1])]
	s = sum((c[i] - c[i + 1] for i in range(0, len(c), 2)))
	print('YES' if a[0] >= s else 'NO')


import bisect
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ind = -1
	flag = 0
	mini = a[0]
	d = []
	d.append([0, a[0]])
	for i in range(1, len(a)):
		mini = min(mini, a[i])
		rem = max(0, a[i] - mini)
		d.append([rem, a[i]])
	prev = d[len(d) - 1][1]
	diff = 0
	for i in range(len(d) - 2, -1, -1):
		x = range(d[i][0], d[i][1] - diff + 1)
		ans = bisect.bisect_right(x, prev)
		if ans == 0:
			flag = 1
			break
		else:
			prev = x[ans - 1]
			diff = a[i] - prev
	if flag == 1:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	a = [*map(int, input().split())]
	ans = sum((max(a[i] - a[i + 1], 0) for i in range(n - 1)))
	print('YES' if ans <= a[0] else 'NO')


import sys
import math
from collections import defaultdict, Counter
input = sys.stdin.readline

def print(x):
	sys.stdout.write(str(x) + '\n')
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	left = a[0]
	for j in range(n - 1):
		if a[j] > a[j + 1]:
			left += a[j + 1] - a[j]
	if left >= 0:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	A = map(int, input().split())
	(l, r) = (10000000000, 0)
	possible = True
	for a in A:
		if a < r:
			possible = False
			break
		a -= r
		l = min(l, a)
		r += a - l
	if possible:
		print('YES')
	else:
		print('NO')


def modinv(n, p):
	return pow(n, p - 2, p)

def solve():
	n = int(input())
	arr = [int(x) for x in input().split()]
	d = 0
	for i in range(1, n):
		arr[i] -= d
		if arr[i] < arr[i - 1]:
			continue
		d += arr[i] - arr[i - 1]
		arr[i] = arr[i - 1]
	for x in arr:
		if x < 0:
			print('NO')
			return
	print('YES')

def main():
	for case in range(int(input())):
		solve()
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = [0 for i in range(n)]
	c = [0 for i in range(n)]
	b[0] = a[0]
	flag = 0
	for i in range(1, n):
		if a[i] > a[i - 1]:
			c[i] = c[i - 1] + a[i] - a[i - 1]
			b[i] = b[i - 1]
		elif a[i] < a[i - 1]:
			b[i] = b[i - 1] + a[i] - a[i - 1]
			c[i] = c[i - 1]
		else:
			b[i] = b[i - 1]
			c[i] = c[i - 1]
		if b[i] < 0 or c[i] < 0:
			flag = -1
			break
	if flag == -1:
		print('NO')
	else:
		print('YES')


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import ceil, floor
from copy import *
from collections import deque, defaultdict
from collections import Counter as counter
from itertools import combinations
from itertools import permutations as permutate
from bisect import bisect_left as bl
from operator import *
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192
from sys import stderr

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def fsep():
	return map(float, inp().split())

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def pow(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res
from functools import reduce

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

def gcd(a, b):
	if a == b:
		return a
	while b > 0:
		(a, b) = (b, a % b)
	return a

def prefix_sum(ar):
	return list(accumulate(ar))

def suffix_sum(ar):
	return list(accumulate(ar[::-1]))[::-1]

def N():
	return int(inp())
dx = [0, 0, 1, -1]
dy = [1, -1, 0, 0]

def YES():
	print('YES')

def NO():
	print('NO')

def Yes():
	print('Yes')

def No():
	print('No')
from collections import defaultdict

def numberOfSetBits(i):
	i = i - (i >> 1 & 1431655765)
	i = (i & 858993459) + (i >> 2 & 858993459)
	return ((i + (i >> 4) & 252645135) * 16843009 & 4294967295) >> 24

class MergeFind:

	def __init__(self, n):
		self.parent = list(range(n))
		self.size = [1] * n
		self.num_sets = n

	def find(self, a):
		to_update = []
		while a != self.parent[a]:
			to_update.append(a)
			a = self.parent[a]
		for b in to_update:
			self.parent[b] = a
		return self.parent[a]

	def merge(self, a, b):
		a = self.find(a)
		b = self.find(b)
		if a == b:
			return
		self.num_sets -= 1
		self.parent[a] = b
		self.size[b] += self.size[a]

	def set_size(self, a):
		return self.size[self.find(a)]

	def __len__(self):
		return self.num_sets

def solve():
	n = N()
	happens = 1
	for wrw in range(1):
		ar = lis()
		sar = ar[::-1]
		dec = [0] * n
		dec[0] = 1
		for i in range(1, n):
			if ar[i] > ar[i - 1]:
				break
			else:
				dec[i] = 1
		inc = [0] * n
		inc[n - 1] = 1
		for i in range(n - 2, -1, -1):
			if ar[i] > ar[i + 1]:
				break
			else:
				inc[i] = 1
		have = [ar[0]]
		for i in range(1, n):
			have.append(min(have[-1], ar[i]))
		st = en = -1
		for i in range(n):
			if inc[i] == 0 and dec[i] == 0:
				st = i
				break
		for i in range(n - 1, -1, -1):
			if inc[i] == 0 and dec[i] == 0:
				en = i
				break
		if st == -1 and en == -1:
			YES()
			return
		M = ar[en + 1]
		sub = 0
		for i in range(en, st - 1, -1):
			ar[i] -= sub
			if ar[i] < 0:
				happens = 0
				break
			if ar[i] <= M:
				M = ar[i]
			else:
				d = ar[i] - M
				have[i] -= sub
				if d > have[i]:
					happens = 0
					break
				sub += d
		if happens == 0:
			break
		YES()
		return
	for wrw in range(1):
		ar = sar
		dec = [0] * n
		dec[0] = 1
		for i in range(1, n):
			if ar[i] > ar[i - 1]:
				break
			else:
				dec[i] = 1
		inc = [0] * n
		inc[n - 1] = 1
		for i in range(n - 2, -1, -1):
			if ar[i] > ar[i + 1]:
				break
			else:
				inc[i] = 1
		have = [ar[0]]
		for i in range(1, n):
			have.append(min(have[-1], ar[i]))
		st = en = -1
		for i in range(n):
			if inc[i] == 0 and dec[i] == 0:
				st = i
				break
		for i in range(n - 1, -1, -1):
			if inc[i] == 0 and dec[i] == 0:
				en = i
				break
		if st == -1 and en == -1:
			YES()
			return
		M = ar[en + 1]
		sub = 0
		for i in range(en, st - 1, -1):
			ar[i] -= sub
			if ar[i] < 0:
				happens = 0
				break
			if ar[i] <= M:
				M = ar[i]
			else:
				d = ar[i] - M
				have[i] -= sub
				if d > have[i]:
					happens = 0
					break
				sub += d
		if happens == 0:
			break
		YES()
		return
	NO()
testcase(int(inp()))


from itertools import accumulate

def read_ints():
	return map(int, input().split())
t_n = int(input())
for i_t in range(t_n):
	n = int(input())
	a = list(read_ints())
	min_from_left = list(accumulate(a, min))
	min_from_right = list(accumulate(a[::-1], min))[::-1]
	deltas = [x2 - x1 for (x1, x2) in zip(a, a[1:])]
	r = [0] * n
	acc = 0
	for (i, delta) in list(enumerate(deltas)):
		if delta > 0:
			acc += delta
		r[i + 1] += acc
	acc = 0
	for (i, delta) in list(enumerate(deltas))[::-1]:
		if delta < 0:
			acc += abs(delta)
		r[i] += acc
	if all((x >= rx for (rx, x) in zip(r, a))):
		print('YES')
	else:
		print('NO')


from math import *
from bisect import *
from collections import *
from random import *
from decimal import *
import sys
input = sys.stdin.readline

def inp():
	return int(input())

def st():
	return input().rstrip('\n')

def lis():
	return list(map(int, input().split()))

def ma():
	return map(int, input().split())
t = inp()
while t:
	t -= 1
	n = inp()
	a = lis()
	if n <= 2:
		print('YES')
		continue
	ha = [0]
	for i in range(1, n):
		ha.append(max(0, a[i] - a[i - 1]) + ha[-1])
	fl = 0
	for i in range(n):
		if ha[i] <= a[i]:
			continue
		fl = 1
	s = 'YES'
	if fl:
		s = 'NO'
	print(s)


for s in [*open(0)][2::2]:
	(x, *l) = map(int, s.split())
	a = y = 0
	for i in l:
		x = min(x, i - y)
		y = max(y, i - x)
		a |= x < 0
	print('YNEOS'[a::2])


def solve(n, arr):
	x = arr[0] - sum((max(arr[i - 1] - arr[i], 0) for i in range(1, n)))
	if x >= 0:
		return 'YES'
	else:
		return 'NO'
t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	print(solve(n, arr))


from os import path
import sys
from heapq import heappush, heappop
from functools import cmp_to_key as ctk
from collections import deque, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input().rstrip()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
mod = 998244353
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def bo(i):
	return ord(i) - ord('a')
file = 1

def solve():
	n = ii()
	a = li()
	suff = [inf] * n
	b = a[:]
	for i in range(n - 1, -1, -1):
		suff[i] = a[i]
		if i < n - 1:
			suff[i] = min(suff[i], suff[i + 1])
		a[i] -= suff[i]
	x = 0
	mx = 0
	for i in range(n - 1, -1, -1):
		a[i] += x
		if b[i] < a[i]:
			print('NO')
			return
		mx = max(mx, a[i])
		if a[i] < mx:
			if b[i] < mx:
				print('NO')
				return
			x += mx - a[i]
	print('YES')
if file:
	if path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	else:
		input = sys.stdin.readline
for _ in range(ii()):
	solve()


import sys, io, os
BUFSIZE = 8192

class FastIO(io.IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = io.BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(io.IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
T = int(input())
for _ in range(T):
	N = int(input())
	A = list(map(int, input().split()))
	decr = 1 << 62
	a_old = 0
	for idx_A in range(N):
		a = A[idx_A]
		if a_old > a:
			print('NO')
			break
		decr = min(a - a_old, decr)
		A[idx_A] = a - decr
		a_old = a - decr
	else:
		print('YES')


import os, sys
from io import BytesIO, IOBase
from collections import deque

def update(seg_tree, value, l, r, x):
	curr = deque([(1, 1, x)])
	while len(curr):
		y = curr.popleft()
		if l <= y[1] <= y[2] <= r:
			seg_tree[y[0]] += value
		elif y[1] != y[2] and (not (y[1] > r or y[2] < l)):
			curr.append((2 * y[0], y[1], (y[1] + y[2]) // 2))
			curr.append((2 * y[0] + 1, (y[1] + y[2]) // 2 + 1, y[2]))

def traversal(seg_tree, x):
	curr = deque([(1, 1, x)])
	while len(curr):
		y = curr.popleft()
		if y[1] != y[2]:
			seg_tree[2 * y[0]] += seg_tree[y[0]]
			seg_tree[2 * y[0] + 1] += seg_tree[y[0]]
			curr.append((2 * y[0], y[1], (y[1] + y[2]) // 2))
			curr.append((2 * y[0] + 1, (y[1] + y[2]) // 2 + 1, y[2]))

def main():
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		vv = 1 << n.bit_length()
		seg_tree = [0] * (2 * vv)
		for i in range(1, n):
			if a[i - 1] > a[i]:
				update(seg_tree, a[i - 1] - a[i], 1, i - 1, vv)
		traversal(seg_tree, vv)
		ans = 'YES'
		for i in range(n):
			if a[i] - seg_tree[i + vv] < 0:
				ans = 'NO'
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	aa = 0
	bb = a[0]
	for i in range(1, n):
		if a[i] <= a[i - 1]:
			bb -= a[i - 1] - a[i]
		else:
			aa += a[i] - a[i - 1]
	ok = True
	ok &= bb >= 0
	ok &= aa <= a[-1]
	print('YES' if ok else 'NO')


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def msi():
	return map(str, input().strip().split(' '))

def li():
	return list(mi())

def dmain():
	sys.setrecursionlimit(1000000)
	threading.stack_size(1024000)
	thread = threading.Thread(target=main)
	thread.start()
import sys
input = sys.stdin.readline
scanner = lambda : int(input())
string = lambda : input().rstrip()
get_list = lambda : list(read())
read = lambda : map(int, input().split())
get_float = lambda : map(float, input().split())

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def factorial(x, m):
	val = 1
	while x > 0:
		val = val * x % m
		x -= 1
	return val

def fact(x):
	val = 1
	while x > 0:
		val *= x
		x -= 1
	return val

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b // math.gcd(a, b)

def is_integer(n):
	return math.ceil(n) == math.floor(n)

def nCr(n, k):
	if k > n:
		return 0
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	if y == 0:
		return 1
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	(prime[0], prime[1]) = (False, False)
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def phi(n):
	result = n
	p = 2
	while p * p <= n:
		if n % p == 0:
			while n % p == 0:
				n = n // p
			result = result * (1.0 - 1.0 / float(p))
		p = p + 1
	if n > 1:
		result = result * (1.0 - 1.0 / float(n))
	return int(result)

def is_prime(n):
	if n == 0:
		return False
	if n == 1:
		return True
	for i in range(2, int(n ** (1 / 2)) + 1):
		if not n % i:
			return False
	return True

def next_prime(n, primes):
	while primes[n] != True:
		n += 1
	return n
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
spf = [0 for i in range(MAXN)]

def factoriazation(x):
	res = []
	for i in range(2, int(x ** 0.5) + 1):
		while x % i == 0:
			res.append(i)
			x //= i
	if x != 1:
		res.append(x)
	return res

def factors(n):
	res = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			res.append(i)
			res.append(n // i)
	return list(set(res))

def int_array():
	return list(map(int, input().strip().split()))

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()

def binary_search(low, high, w, h, n):
	while low < high:
		mid = low + (high - low) // 2
		if check(mid, w, h, n):
			low = mid + 1
		else:
			high = mid
	return low

def check(moves, n):
	val = (moves + 1) // 2
	rem = moves - val
	sol = (val + 1) * (rem + 1)
	return sol < n

def sortSecond(val):
	return val[1]
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
alphs = 'abcdefghijklmnopqrstuvwxyz'
from itertools import permutations
import math
import bisect as bis
import random
import sys
import collections as collect
import functools as fnt
from decimal import Decimal

def solve():
	n = scanner()
	a = get_list()
	r = a[0]
	for i in range(1, n):
		if a[i - 1] > a[i]:
			r -= a[i - 1] - a[i]
	print(['NO', 'YES'][r >= 0])
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
t = scanner()
for i in range(t):
	solve()


from bisect import *
from collections import *
from math import gcd, ceil, sqrt, floor, inf
from heapq import *
from itertools import *
from operator import add, mul, sub, xor, truediv, floordiv
from functools import *
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())
farr = [1]
ifa = []

def fact(x, mod=0):
	if mod:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr) % mod)
	else:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr))
	return farr[x]

def ifact(x, mod):
	global ifa
	ifa.append(pow(farr[-1], mod - 2, mod))
	for i in range(x, 0, -1):
		ifa.append(ifa[-1] * i % mod)
	ifa = ifa[::-1]

def per(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return fact(i) // fact(i - j)
	return farr[i] * ifa[i - j] % mod

def com(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return per(i, j) // fact(j)
	return per(i, j, mod) * ifa[j] % mod

def catalan(n):
	return com(2 * n, n) // (n + 1)

def linc(f, t, l, r):
	while l < r:
		mid = (l + r) // 2
		if t > f(mid):
			l = mid + 1
		else:
			r = mid
	return l

def rinc(f, t, l, r):
	while l < r:
		mid = (l + r + 1) // 2
		if t < f(mid):
			r = mid - 1
		else:
			l = mid
	return l

def ldec(f, t, l, r):
	while l < r:
		mid = (l + r) // 2
		if t < f(mid):
			l = mid + 1
		else:
			r = mid
	return l

def rdec(f, t, l, r):
	while l < r:
		mid = (l + r + 1) // 2
		if t > f(mid):
			r = mid - 1
		else:
			l = mid
	return l

def isprime(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return False
	return True

def binfun(x):
	c = 0
	for w in arr:
		c += ceil(w / x)
	return c

def lowbit(n):
	return n & -n

def inverse(a, m):
	a %= m
	if a <= 1:
		return a
	return (1 - inverse(m, a) * m) // a % m

class BIT:

	def __init__(self, arr):
		self.arr = arr
		self.n = len(arr) - 1

	def update(self, x, v):
		while x <= self.n:
			self.arr[x] += v
			x += x & -x

	def query(self, x):
		ans = 0
		while x:
			ans += self.arr[x]
			x &= x - 1
		return ans

class smt:

	def __init__(self, l, r, arr):
		self.l = l
		self.r = r
		self.value = (1 << 31) - 1 if l < r else arr[l]
		mid = (l + r) // 2
		if l < r:
			self.left = smt(l, mid, arr)
			self.right = smt(mid + 1, r, arr)
			self.value &= self.left.value & self.right.value

	def setvalue(self, x, val):
		if self.l == self.r:
			self.value = val
			return
		mid = (self.l + self.r) // 2
		if x <= mid:
			self.left.setvalue(x, val)
		else:
			self.right.setvalue(x, val)
		self.value = self.left.value & self.right.value

	def ask(self, l, r):
		if l <= self.l and r >= self.r:
			return self.value
		val = (1 << 31) - 1
		mid = (self.l + self.r) // 2
		if l <= mid:
			val &= self.left.ask(l, r)
		if r > mid:
			val &= self.right.ask(l, r)
		return val

class DSU:

	def __init__(self, n):
		self.c = [-1] * n

	def same(self, x, y):
		return self.find(x) == self.find(y)

	def find(self, x):
		if self.c[x] < 0:
			return x
		self.c[x] = self.find(self.c[x])
		return self.c[x]

	def union(self, u, v):
		(u, v) = (self.find(u), self.find(v))
		if u == v:
			return False
		if self.c[u] < self.c[v]:
			(u, v) = (v, u)
		self.c[u] += self.c[v]
		self.c[v] = u
		return True

	def size(self, x):
		return -self.c[self.find(x)]

class UFS:

	def __init__(self, n):
		self.parent = [i for i in range(n)]
		self.ranks = [0] * n

	def find(self, x):
		if x != self.parent[x]:
			self.parent[x] = self.find(self.parent[x])
		return self.parent[x]

	def union(self, u, v):
		(pu, pv) = (self.find(u), self.find(v))
		if pu == pv:
			return False
		if self.ranks[pu] >= self.ranks[pv]:
			self.parent[pv] = pu
			if self.ranks[pv] == self.ranks[pu]:
				self.ranks[pu] += 1
		else:
			self.parent[pu] = pv

def Prime(n):
	c = 0
	prime = []
	flag = [0] * (n + 1)
	for i in range(2, n + 1):
		if not flag[i]:
			prime.append(i)
			c += 1
		for j in range(c):
			if i * prime[j] > n:
				break
			flag[i * prime[j]] = prime[j]
			if i % prime[j] == 0:
				break
	return prime

def dij(s, graph):
	d = {}
	d[s] = 0
	heap = [(0, s)]
	seen = set()
	while heap:
		(dis, u) = heappop(heap)
		if u in seen:
			continue
		for v in graph[u]:
			if v not in d or d[v] > d[u] + graph[u][v]:
				d[v] = d[u] + graph[u][v]
				heappush(heap, (d[v], v))
	return d

def GP(it):
	res = []
	for (ch, g) in groupby(it):
		res.append((ch, len(list(g))))
	return res
t = N()
for i in range(t):
	n = N()
	a = RLL()
	b = [0]
	for i in range(1, n):
		if a[i] > a[i - 1]:
			b.append(a[i] - a[i - 1] + b[-1])
		else:
			b.append(b[-1])
	for i in range(n):
		a[i] -= b[i]
	ans = 'YES' if all((a[i] >= 0 for i in range(n))) and all((a[i] >= a[i + 1] for i in range(n - 1))) else 'NO'
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	d = [a[i] if i == 0 else a[i] - a[i - 1] for i in range(n)]
	if abs(sum((x for x in d if x < 0))) <= d[0]:
		print('YES')
	else:
		print('NO')


import sys
(*data,) = map(int, sys.stdin.read().split()[::-1])

def inp():
	return data.pop()

def solve(arr):
	mn = arr[0]
	mx = 0
	for i in range(n):
		mn = min(mn, arr[i] - mx)
		arr[i] -= mn
		mx = max(mx, arr[i])
	return mn >= 0
ans = []
for _ in range(inp()):
	n = inp()
	arr = [inp() for _ in range(n)]
	ans.append('YES' if solve(arr) else 'NO')
print('\n'.join(ans))


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	if n == 1 or n == 2:
		print('Yes')
	else:
		arr = [10 ** 18] + arr + [10 ** 18]
		imos = [0] * (n + 2)
		for i in range(1, n + 1):
			if arr[i] > arr[i - 1]:
				d = arr[i] - arr[i - 1]
				imos[i] += d
				imos[n + 1] -= d
		for i in range(1, n + 1):
			imos[i] += imos[i - 1]
		for i in range(1, n + 1):
			arr[i] -= imos[i]
			if arr[i] < 0:
				print('No')
				break
		else:
			print('Yes')


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	s = p = a[0]
	for i in range(1, n):
		if a[i] < p:
			s -= p - a[i]
		p = a[i]
	if s < 0:
		print('NO')
	else:
		print('YES')


import sys, time
from os import path
from collections import *
from heapq import *
from math import *

def solve(kkkk):
	n = inp()
	arr = ina()
	pref = list(arr)
	suff = crarr(0, n)
	for i in range(1, n):
		pref[i] = min(pref[i], pref[i - 1])
		suff[i] = arr[i] - pref[i]
		if suff[i] < suff[i - 1]:
			if pref[i] < suff[i - 1] - suff[i]:
				out('NO')
				return
			pref[i] -= suff[i - 1] - suff[i]
			suff[i] = suff[i - 1]
	out('YES')

def main():
	t = 1
	t = inp()
	for i in range(t):
		solve(i + 1)
localsys = 0
start_time = time.time()
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
	localsys = 1
cin = sys.stdin.readline
cout = sys.stdout.write

def inp():
	return int(cin().strip())

def ins():
	return list(cin().strip())

def inm():
	return map(int, cin().strip().split())

def ina():
	return list(map(int, cin().strip().split()))

def out(a):
	cout(str(a) + '\n')

def outa(a):
	cout(' '.join(map(str, a)) + '\n')

def outm(a, b, c=None, d=None):
	cout(str(a) + ' ' + str(b))
	if c != None:
		cout(' ' + str(c))
	if d != None:
		cout(' ' + str(d))
	cout('\n')

def crarr(a, n):
	return [a for i in range(n)]
main()
if localsys:
	print('\n\nTime Elapsed :', time.time() - start_time, 'seconds')


t = int(input())

def solve(n, arr):
	cur = arr[0]
	transformed = [0]
	for i in range(1, n):
		transformed.append(max(transformed[i - 1], arr[i] - cur))
		cur = min(cur, arr[i] - transformed[i])
	cur = arr[-1]
	for i in range(n - 1, -1, -1):
		if arr[i] < transformed[i]:
			return False
	return True
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	can = solve(n, arr)
	if can:
		print('YES')
	else:
		print('NO')


import sys
from array import array
from typing import List, Tuple, TypeVar, Generic, Sequence, Union

def input():
	return sys.stdin.buffer.readline().decode('utf-8')

def main():
	from itertools import groupby
	t = int(input())
	ans = ['YES'] * t
	for ti in range(t):
		n = int(input())
		a = [k for (k, _) in groupby(map(int, input().split()))]
		n = len(a)
		if n <= 2:
			continue
		dec = array('b', [1] + [0] * (n - 1))
		min_left = array('i', [a[0]]) * n
		for i in range(1, n):
			if a[i - 1] >= a[i]:
				dec[i] = dec[i - 1]
			min_left[i] = min(min_left[i - 1], a[i])
		flag = 0
		for i in range(1, n - 1):
			if not dec[i - 1]:
				break
			flow = min_left[i]
			height = a[i] - flow
			for j in range(i + 1, n):
				if a[j] < height:
					break
				flow = min(flow, a[j] - height)
				height = a[j] - flow
			else:
				flag = 1
				break
		if not flag:
			ans[ti] = 'NO'
	sys.stdout.buffer.write(('\n'.join(ans) + '\n').encode('utf-8'))
main()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	(dec, flag) = (0, 1)
	for i in range(n - 1):
		if a[i] < dec:
			flag = 0
			break
		if a[i] < a[i + 1]:
			dec += a[i + 1] - a[i]
	if a[-1] < dec:
		flag = 0
	print('YES' if flag else 'NO')


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
import threading
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
for ik in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	ans = 0
	f = 0
	for i in range(n - 2, -1, -1):
		if l[i] - ans < 0:
			print('NO')
			f = 1
			break
		l[i] -= ans
		ans += max(0, l[i] - l[i + 1])
		l[i] = min(l[i], l[i + 1])
	if f == 1:
		continue
	print('YES')


mod = 10 ** 9 + 7
INF = float('inf')

def getlist():
	return list(map(int, input().split()))

def main():
	T = int(input())
	for _ in range(T):
		N = int(input())
		A = getlist()
		B = [0] * N
		leftminus = [None] * N
		B[0] = 0
		leftminus[0] = A[0]
		jud = 1
		for i in range(1, N):
			val = min(leftminus[i - 1], A[i] - B[i - 1])
			if val < 0:
				jud = 0
				break
			B[i] = A[i] - val
			leftminus[i] = val
		for i in range(N - 2, -1, -1):
			if B[i] > B[i + 1]:
				jud = 0
		if jud == 0:
			print('NO')
		else:
			print('YES')
main()


import sys
import math

def II():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def MI():
	return map(int, sys.stdin.readline().split())

def SI():
	return sys.stdin.readline().strip()
t = II()
for q in range(t):
	n = II()
	a = LI()
	s = 0
	boo = True
	for i in range(1, n):
		if a[i] > a[i - 1]:
			s += a[i] - a[i - 1]
		if s > a[i]:
			boo = False
			break
	print('YES' if boo else 'NO')


t = int(input())
for t1 in range(0, t):
	n = int(input())
	a = list(map(int, input().split()))
	last = 0
	flag = 1
	diff = []
	for i in range(1, n):
		diff.append(a[i - 1] - a[i])
	s = 0
	for i in range(0, n - 1):
		s = s + max(0, a[i] - a[i + 1])
	if s <= a[0]:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
n = inp()
b = [0] * 100000
c = [0] * 100000
for j in range(n):
	t = inp()
	a = list(invr())
	b[0] = a[0]
	c[0] = 0
	chk = True
	for i in range(1, t):
		b[i] = min(a[i] - c[i - 1], b[i - 1])
		c[i] = max(a[i] - b[i - 1], c[i - 1])
		if b[i] + c[i] != a[i] or b[i] < 0 or c[i] < 0:
			chk = False
			print('NO')
			break
	if chk:
		print('YES')


import sys
import itertools as it
import math as mt
import bisect as bi
import collections as cc
import itertools as it
sys.setrecursionlimit(10 ** 4)
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
for tc in range(int(input())):
	(n,) = I()
	l = I()
	temp = l[0]
	for i in range(n - 1):
		temp -= max(0, -l[i + 1] + l[i])
	print('YNEOS'[not temp >= 0::2])


import sys
input = sys.stdin.readline
t = int(input())
for test in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	temp = []
	temp.append(a[0])
	d = 0
	for i in range(1, n):
		if a[i] > a[i - 1]:
			d = d + a[i] - a[i - 1]
		temp.append(a[i] - d)
	d = 0
	for i in reversed(range(n - 1)):
		if a[i] > a[i + 1]:
			d = d + a[i] - a[i + 1]
		temp[i] = temp[i] - d
	if temp[0] < 0:
		print('NO')
	else:
		print('YES')


from sys import stdin
t = int(stdin.readline())
for case in range(t):
	n = int(stdin.readline())
	a = [int(x) for x in stdin.readline().split()]
	left = [a[0]]
	right = [a[-1]]
	for x in range(1, n):
		left.append(min(left[-1], a[x]))
		right.append(min(right[-1], a[-x - 1]))
	right = right[::-1]
	good = 'YES'
	cLeft = a[0]
	rightVein = 0
	for x in range(n):
		if cLeft + rightVein >= a[x]:
			cLeft = min(cLeft, a[x] - rightVein)
		elif right[x] + cLeft >= a[x]:
			rightVein = max(rightVein, a[x] - cLeft)
			cLeft = min(cLeft, a[x] - rightVein)
		else:
			good = 'NO'
			break
	print(good)


import sys
input = sys.stdin.readline
R = lambda : map(int, input().split())
(t,) = R()
for _ in [0] * t:
	R()
	(pre, sur) = (float('inf'), 0)
	for a in R():
		if sur > a:
			print('NO')
			break
		if pre + sur < a:
			sur = a - pre
		else:
			pre = a - sur
	else:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	i = 1
	while i < n:
		if A[i] > A[i - 1]:
			break
		else:
			i += 1
	j = n - 1
	while j > 0:
		if A[j] < A[j - 1]:
			break
		else:
			j -= 1
	x = A[i - 1]
	y = 0
	for k in range(i, j):
		if A[k] > x + y:
			y = A[k] - x
		else:
			x = A[k] - y
	if x >= 0 and y <= A[j]:
		print('YES')
	else:
		print('NO')


import os
import sys
from io import BytesIO, IOBase
_str = str
BUFSIZE = 8192

def str(x=b''):
	return x if type(x) is bytes else _str(x).encode()

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def inp():
	return sys.stdin.readline().rstrip()

def mpint():
	return map(int, inp().split(' '))

def itg():
	return int(inp())

def solve():
	n = itg()
	arr = tuple(mpint())
	d = 0
	for i in range(1, n):
		if arr[i] < d:
			return False
		if arr[i] > arr[i - 1]:
			d += arr[i] - arr[i - 1]
	return True

def main():
	for _ in range(itg()):
		print('YES' if solve() else 'NO')
DEBUG = 0
URL = 'https://codeforces.com/contest/1443/problem/D'
if DEBUG == 1:
	import requests
	from ACgenerator.Y_Test_Case_Runner import TestCaseRunner
	runner = TestCaseRunner(main, URL, 2)
	inp = runner.input_stream
	print = runner.output_stream
	runner.checking()
elif DEBUG == 2:
	main()
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
	main()


for w in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	x = -1
	p = -1
	ans = 1
	k = n + 1
	for i in range(n - 1):
		if a[i] >= a[i + 1]:
			continue
		else:
			x = a[i]
			p = i + 1
			a[i + 1] -= x
			break
	for k in range(p + 1, n):
		if a[k] >= a[k - 1] and a[k] - a[k - 1] <= x:
			x = a[k] - a[k - 1]
			a[k] = a[k - 1]
		elif a[k] >= a[k - 1]:
			a[k] -= x
		elif a[k] < a[k - 1]:
			break
	for j in range(k - 1, n - 1, 1):
		if a[j] <= a[j + 1]:
			continue
		else:
			ans = 0
			break
	if ans == 1 or x == -1:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	flag = 1
	for i in range(1, n):
		if l[i] > l[i - 1]:
			if i == n - 1:
				pass
			else:
				d = l[i] - l[i - 1]
				for j in range(i, n):
					if l[j] >= d:
						l[j] -= d
					else:
						flag = 0
						break
	if flag:
		print('YES')
	else:
		print('NO')


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from functools import cmp_to_key
from heapq import *
from math import gcd, factorial, floor, ceil, sqrt
from copy import deepcopy
from collections import deque
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for pp in range(t):
		solve(pp)

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def google(p):
	print('Case #' + str(p) + ': ', end='')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(x, y, p):
	y %= p - 1
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
inf = pow(10, 20)
mod = 10 ** 9 + 7

def solve(case):
	n = int(inp())
	a = lis()
	new = deepcopy(a)
	l = a[0]
	r = a[n - 1]
	am = 0
	i = 1
	while i < n - 1:
		if a[i] - am == l:
			i += 1
			continue
		if a[i] - am > l:
			j = i + 1
			prev = a[i] - am
			while j < n - 1 and a[j] - am >= prev:
				prev = a[j] - am
				j += 1
			r -= prev - l
			am += prev - l
			i = j
		else:
			j = i + 1
			prev = a[i] - am
			while j < n - 1 and a[j] - am <= prev:
				prev = a[j] - am
				j += 1
			l = prev
			i = j
	if l >= 0 and r >= 0:
		ans1 = 'YES'
	else:
		ans1 = 'NO'
	print(ans1)
testcase(int(inp()))


import sys
input = sys.stdin.readline

def prog():
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		decrease1 = 0
		decrease2 = 0
		for i in range(1, n):
			decrease1 += max(0, a[i] - a[i - 1])
		for i in range(n - 2, -1, -1):
			decrease2 += max(0, a[i] - a[i + 1])
		if a[n - 1] >= decrease1 or a[0] >= decrease2:
			print('YES')
		else:
			print('NO')
prog()