ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2060D - Subtract Min Sort
Language: python

Solution 1 (runtime: 202 ms):
#include <bits/stdc++.h>
using namespace std;
void solve()
{
    int n;
    cin >> n;
    vector<int> A(n);
    for(int i=0;i<n;i++) {
        cin >> A[i];
    }

    for(int i=1;i<n;i++) {
        int min_v=min(A[i-1],A[i]);
        A[i-1]-=min_v;
        A[i]-=min_v;
    }

    for(int i=0;i<n-1;i++) {
        if(A[i]) {
            cout << "NO\n";
            return;
        }
    }
    cout << "YES\n";
}
int main()
{
    int t;
    cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}

Solution 2 (runtime: 249 ms):
# Vaibhav Varshney
import math
import bisect
 
def li():
    return list(map(int,input().split()))
def mi():
    return map(int,input().split())
 
def solve():
    n = int(input())
    a = li()
    diff = a[1]-a[0]
    if (diff<0):
        print("NO")
        return
    for i in range(2,n):
        diff = a[i]-diff
        if(diff<0):
            print("NO")
            return
    print("YES")    
        
    
def main():
    t = int(input())
    for _ in range(t):
        solve()
 
if __name__ == "__main__":
    main()
Problem: 2060D - Subtract Min Sort
Language: python

Solution 1 (runtime: 202 ms):
#include <bits/stdc++.h>
using namespace std;
void solve()
{
    int n;
    cin >> n;
    vector<int> A(n);
    for(int i=0;i<n;i++) {
        cin >> A[i];
    }

    for(int i=1;i<n;i++) {
        int min_v=min(A[i-1],A[i]);
        A[i-1]-=min_v;
        A[i]-=min_v;
    }

    for(int i=0;i<n-1;i++) {
        if(A[i]) {
            cout << "NO\n";
            return;
        }
    }
    cout << "YES\n";
}
int main()
{
    int t;
    cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}

Solution 2 (runtime: 217 ms):
# -*- coding: utf-8 -*-
"""
Created on Fri Feb 21 21:15:24 2025

@author: hp
"""

case = input()

ans = []
for i in range(int(case)):
    value = input()
    v = input().split()
    if int(len(v)) == int(value):
        flag = 1
        answer = 0 
        for j in range(len(v)):
            if j < int(value)-1:
                if j == 0:
                    answer = int(v[j+1]) - int(v[j])
                else:
                    answer = int(v[j+1]) - answer
            
            if answer < 0:
                flag=-1
                
        if flag == 1:
            ans.append("yes")
        
        else:
            ans.append("no")
            

for m in ans:
    print(m)
Problem: 2060D - Subtract Min Sort
Language: python

Solution 1 (runtime: 202 ms):
#include <bits/stdc++.h>
using namespace std;
void solve()
{
    int n;
    cin >> n;
    vector<int> A(n);
    for(int i=0;i<n;i++) {
        cin >> A[i];
    }

    for(int i=1;i<n;i++) {
        int min_v=min(A[i-1],A[i]);
        A[i-1]-=min_v;
        A[i]-=min_v;
    }

    for(int i=0;i<n-1;i++) {
        if(A[i]) {
            cout << "NO\n";
            return;
        }
    }
    cout << "YES\n";
}
int main()
{
    int t;
    cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}

Solution 2 (runtime: 202 ms):
t = int(input())

for i in range(t):
    n = int(input())
    a = list(map(int, input().split()))

    k = 0
    while k < n - 1 and a[k] <= a[k + 1]:
        a[k + 1] -= a[k]
        a[k] = 0
        k += 1

    if k == n - 1:
        print('yes')
    else:
        print('no')
Problem: 2060D - Subtract Min Sort
Language: python

Solution 1 (runtime: 202 ms):
#include <bits/stdc++.h>
using namespace std;
void solve()
{
    int n;
    cin >> n;
    vector<int> A(n);
    for(int i=0;i<n;i++) {
        cin >> A[i];
    }

    for(int i=1;i<n;i++) {
        int min_v=min(A[i-1],A[i]);
        A[i-1]-=min_v;
        A[i]-=min_v;
    }

    for(int i=0;i<n-1;i++) {
        if(A[i]) {
            cout << "NO\n";
            return;
        }
    }
    cout << "YES\n";
}
int main()
{
    int t;
    cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}

Solution 2 (runtime: 249 ms):
def c(a):
    for i in range(len(a)-1):
        if a[i] > a[i+1]:
            return False
    return True


t = int(input())
for _ in range(t):
    n = int(input())
    l = list(map(int, input().split()))
    f = c(l)
    if f:
        print('yes')
        continue
    for i in range(len(l)-2):
        m = min(l[i], l[i+1])
        if l[i] - m <= l[i+1] - m and l[i+1] - m <= l[i+2]:
            l[i] -=m
            l[i+1] -=m
    f = c(l)
    if f:
        print('yes')
    else:    
        print("no")
Problem: 2060D - Subtract Min Sort
Language: python

Solution 1 (runtime: 202 ms):
#include <bits/stdc++.h>
using namespace std;
void solve()
{
    int n;
    cin >> n;
    vector<int> A(n);
    for(int i=0;i<n;i++) {
        cin >> A[i];
    }

    for(int i=1;i<n;i++) {
        int min_v=min(A[i-1],A[i]);
        A[i-1]-=min_v;
        A[i]-=min_v;
    }

    for(int i=0;i<n-1;i++) {
        if(A[i]) {
            cout << "NO\n";
            return;
        }
    }
    cout << "YES\n";
}
int main()
{
    int t;
    cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}

Solution 2 (runtime: 171 ms):
t = int(input())

for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))

    possible = True

    for i in range(1, n):
        curr = a[i-1]
        next_num = a[i]

        a[i-1] -= curr
        a[i] -= curr

        if a[i-1] > a[i]:
            possible = False

    if possible:
        print("YES")
    else:
        print("NO")
Problem: 2060D - Subtract Min Sort
Language: python

Solution 1 (runtime: 202 ms):
#include <bits/stdc++.h>
using namespace std;
void solve()
{
    int n;
    cin >> n;
    vector<int> A(n);
    for(int i=0;i<n;i++) {
        cin >> A[i];
    }

    for(int i=1;i<n;i++) {
        int min_v=min(A[i-1],A[i]);
        A[i-1]-=min_v;
        A[i]-=min_v;
    }

    for(int i=0;i<n-1;i++) {
        if(A[i]) {
            cout << "NO\n";
            return;
        }
    }
    cout << "YES\n";
}
int main()
{
    int t;
    cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}

Solution 2 (runtime: 155 ms):
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())

def main():
    t = inp()
    
    def solve():
        n = invr()
        a = inlt()

        """
        use the op when a_i+1 <= a_i
        can use the op at most n - 1 times

        the op doesn't change the relationship between a_i and a_i+1
        but can change the relationship between a_i+1 and a_i+2

        if a_i+1 > a_i+2
            then use op(a_i)

        if a_i+1 still > a_i+2 then not possible
        else continue with new a
        """
        if a[1] < a[0]:
            print("NO")
        else:
            for i in range(1, len(a) - 1):
                if a[i] - a[i-1] > a[i+1]:
                    print("NO")
                    break
                a[i] = a[i] - a[i-1]
            else:
                print("YES")
    
    for _ in range(t):
        solve()

main()
Problem: 2060D - Subtract Min Sort
Language: python

Solution 1 (runtime: 202 ms):
#include <bits/stdc++.h>
using namespace std;
void solve()
{
    int n;
    cin >> n;
    vector<int> A(n);
    for(int i=0;i<n;i++) {
        cin >> A[i];
    }

    for(int i=1;i<n;i++) {
        int min_v=min(A[i-1],A[i]);
        A[i-1]-=min_v;
        A[i]-=min_v;
    }

    for(int i=0;i<n-1;i++) {
        if(A[i]) {
            cout << "NO\n";
            return;
        }
    }
    cout << "YES\n";
}
int main()
{
    int t;
    cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}

Solution 2 (runtime: 233 ms):
for _ in range(int(input())):

    n=int(input())

    l=list(map(int,input().split()))

    



    f=1

    for i in range(n-1):

        

        if l[i]>l[i+1]:

            f=0

            break

    

        l[i+1]-=l[i]

        

                

                

                

        

    if f:

        print("YES")

    else:

        print("NO")
Problem: 2060D - Subtract Min Sort
Language: python

Solution 1 (runtime: 202 ms):
#include <bits/stdc++.h>
using namespace std;
void solve()
{
    int n;
    cin >> n;
    vector<int> A(n);
    for(int i=0;i<n;i++) {
        cin >> A[i];
    }

    for(int i=1;i<n;i++) {
        int min_v=min(A[i-1],A[i]);
        A[i-1]-=min_v;
        A[i]-=min_v;
    }

    for(int i=0;i<n-1;i++) {
        if(A[i]) {
            cout << "NO\n";
            return;
        }
    }
    cout << "YES\n";
}
int main()
{
    int t;
    cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}

Solution 2 (runtime: 389 ms):
import sys

from collections import defaultdict, Counter



number = lambda: int(sys.stdin.readline().strip())

numbers = lambda: list(map(int, sys.stdin.readline().strip().split()))

words = lambda: sys.stdin.readline().strip().split()

word = lambda: sys.stdin.readline().strip()

yn = lambda condition: 'YES' if condition else 'NO'



def solve():

    n =number()

    arr = numbers()

    check = sorted(arr)

    if check == arr:

        print('YES')

        return 

    elif n == 1:

        print('YES')

        return

    else:

        for i in range(n-1):

            if arr[i] <= arr[i+1]:

                m = min(arr[i],arr[i+1])

                arr[i] -= m

                arr[i+1] -= m

            else:

                print('NO')

                return 

    print('YES')

        

    

    return





test_cases = number()

for _ in range(test_cases):

    solve()
Problem: 2060D - Subtract Min Sort
Language: python

Solution 1 (runtime: 202 ms):
#include <bits/stdc++.h>
using namespace std;
void solve()
{
    int n;
    cin >> n;
    vector<int> A(n);
    for(int i=0;i<n;i++) {
        cin >> A[i];
    }

    for(int i=1;i<n;i++) {
        int min_v=min(A[i-1],A[i]);
        A[i-1]-=min_v;
        A[i]-=min_v;
    }

    for(int i=0;i<n-1;i++) {
        if(A[i]) {
            cout << "NO\n";
            return;
        }
    }
    cout << "YES\n";
}
int main()
{
    int t;
    cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}

Solution 2 (runtime: 203 ms):
t = int(input())

for _ in range(t):

    n = int(input())

    nums = list(map(int,input().split()))

    flag = False

    first = nums[0]

    for i in range(n-1):

        res = min(nums[i],nums[i+1])

        nums[i] = nums[i] - res

        nums[i+1] = nums[i+1] - res

    temp = sorted(nums)

    if temp != nums:

        print('NO')

    else:

        print('YES')
Problem: 2060D - Subtract Min Sort
Language: python

Solution 1 (runtime: 202 ms):
#include <bits/stdc++.h>
using namespace std;
void solve()
{
    int n;
    cin >> n;
    vector<int> A(n);
    for(int i=0;i<n;i++) {
        cin >> A[i];
    }

    for(int i=1;i<n;i++) {
        int min_v=min(A[i-1],A[i]);
        A[i-1]-=min_v;
        A[i]-=min_v;
    }

    for(int i=0;i<n-1;i++) {
        if(A[i]) {
            cout << "NO\n";
            return;
        }
    }
    cout << "YES\n";
}
int main()
{
    int t;
    cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}

Solution 2 (runtime: 171 ms):
import sys,random,cmath

from math import inf,factorial,gcd

from collections import defaultdict, Counter



xors = random.randint(1, 1000000000)

con = lambda x: x^xors

number = lambda: int(sys.stdin.readline().strip())

numbers = lambda: list(map(int, sys.stdin.readline().strip().split()))

words = lambda: sys.stdin.readline().strip().split()

word = lambda: sys.stdin.readline().strip()

yn = lambda condition: 'YES' if condition else 'NO'



def solve():

    n = number()

    nums = numbers()

    arr = [0]

    for i in range(1,len(nums)):

        if nums[i] >= nums[i-1]:

            if i>1:

                arr.append(nums[i]-arr[-1])

                arr[-2] = 0

            else:

                arr.append(nums[i]-nums[i-1])

        elif i < 2 or arr[-1] > nums[i]:

            print('NO')

            return

        else:

            arr.append(nums[i]-arr[-1]) 

            arr[-2] = 0

    print('YES')        

    

    return



test_cases = number()

for _ in range(test_cases):

    solve()
Problem: 2060D - Subtract Min Sort
Language: python

Solution 1 (runtime: 202 ms):
#include <bits/stdc++.h>
using namespace std;
void solve()
{
    int n;
    cin >> n;
    vector<int> A(n);
    for(int i=0;i<n;i++) {
        cin >> A[i];
    }

    for(int i=1;i<n;i++) {
        int min_v=min(A[i-1],A[i]);
        A[i-1]-=min_v;
        A[i]-=min_v;
    }

    for(int i=0;i<n-1;i++) {
        if(A[i]) {
            cout << "NO\n";
            return;
        }
    }
    cout << "YES\n";
}
int main()
{
    int t;
    cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}

Solution 2 (runtime: 217 ms):
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())





def is_sort(arr):

    for i in range(len(arr) - 1):

        curr_min = min(arr[i], arr[i + 1])

        arr[i] -= curr_min

        arr[i + 1] -= curr_min

        if arr[i] > arr[i + 1]:

            return "NO"

    return "YES"

    # count_up = 0

    # count_down = 0

    # for i in range(1, len(arr)):

    #     if arr[i] >= arr[i - 1]:

    #         count_up += 1

    #     else:

    #         count_down += 1

    # if count_up > count_down:

    #     print("YES")

    # else:

    #     print("NO")





def main():

    t = inp()

    games = []

    for _ in range(t):

        _ = inp()

        games.append(inlt())



    for game in games:

        print(is_sort(game))





main()
Problem: 2060D - Subtract Min Sort
Language: python

Solution 1 (runtime: 202 ms):
#include <bits/stdc++.h>
using namespace std;
void solve()
{
    int n;
    cin >> n;
    vector<int> A(n);
    for(int i=0;i<n;i++) {
        cin >> A[i];
    }

    for(int i=1;i<n;i++) {
        int min_v=min(A[i-1],A[i]);
        A[i-1]-=min_v;
        A[i]-=min_v;
    }

    for(int i=0;i<n-1;i++) {
        if(A[i]) {
            cout << "NO\n";
            return;
        }
    }
    cout << "YES\n";
}
int main()
{
    int t;
    cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}

Solution 2 (runtime: 249 ms):
'''

import sys

sys.stdin = open('input.txt', 'r')

'''



for _ in range(int(input())):

    n = int(input())

    x = list(map(int, input().split()))

    action = False

    for i in range(n-1):

        m = min(x[i], x[i+1])

        x[i] -=m

        x[i+1] -=m

    if x == sorted(x):

        print('YES')

    else:

        print('NO')

    #print(x)

    #print()
Problem: 2060D - Subtract Min Sort
Language: python

Solution 1 (runtime: 202 ms):
#include <bits/stdc++.h>
using namespace std;
void solve()
{
    int n;
    cin >> n;
    vector<int> A(n);
    for(int i=0;i<n;i++) {
        cin >> A[i];
    }

    for(int i=1;i<n;i++) {
        int min_v=min(A[i-1],A[i]);
        A[i-1]-=min_v;
        A[i]-=min_v;
    }

    for(int i=0;i<n-1;i++) {
        if(A[i]) {
            cout << "NO\n";
            return;
        }
    }
    cout << "YES\n";
}
int main()
{
    int t;
    cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}

Solution 2 (runtime: 218 ms):
t = int(input())



for _ in range(t):

    n = int(input())

    a = list(map(int, input().split()))

    j = 0 

    i = 1

    while i < n:

        if a[i-1] > a[i]:

            j = i 

        i += 1

    if j == 0:

        print("YES")

        continue

    for i in range(0, j):

        minN = min(a[i], a[i+1])

        a[i] -= minN

        a[i+1] -= minN

    if a == sorted(a):

        print("YES")

    else:

        print("NO")
Problem: 2060D - Subtract Min Sort
Language: python

Solution 1 (runtime: 202 ms):
#include <bits/stdc++.h>
using namespace std;
void solve()
{
    int n;
    cin >> n;
    vector<int> A(n);
    for(int i=0;i<n;i++) {
        cin >> A[i];
    }

    for(int i=1;i<n;i++) {
        int min_v=min(A[i-1],A[i]);
        A[i-1]-=min_v;
        A[i]-=min_v;
    }

    for(int i=0;i<n-1;i++) {
        if(A[i]) {
            cout << "NO\n";
            return;
        }
    }
    cout << "YES\n";
}
int main()
{
    int t;
    cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}

Solution 2 (runtime: 437 ms):
num = int(input())



for _ in range(num):

    eh_possivel = True

    tam_array = int(input()) 

    lista = list(map(int, input().split()))

 

    for i in range(len(lista) - 1):

        menor = min(lista[i], lista[i + 1])

        lista[i] = lista[i] - menor

        lista[i + 1] = lista[i + 1] - menor

        if lista[i] > lista[i + 1]:

            eh_possivel = False

            break 

    if eh_possivel:

        print("YES")

    else:

        print("NO")
Problem: 2060D - Subtract Min Sort
Language: python

Solution 1 (runtime: 202 ms):
#include <bits/stdc++.h>
using namespace std;
void solve()
{
    int n;
    cin >> n;
    vector<int> A(n);
    for(int i=0;i<n;i++) {
        cin >> A[i];
    }

    for(int i=1;i<n;i++) {
        int min_v=min(A[i-1],A[i]);
        A[i-1]-=min_v;
        A[i]-=min_v;
    }

    for(int i=0;i<n-1;i++) {
        if(A[i]) {
            cout << "NO\n";
            return;
        }
    }
    cout << "YES\n";
}
int main()
{
    int t;
    cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}

Solution 2 (runtime: 311 ms):
t=int(input())

for i in range(t):

    n=int(input())

    a=list(map(int, input().split()))

    i=0

    ans='YES'

    while i<len(a)-1:

        s=min(a[i],a[i+1])

        a[i]=a[i]-s

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

        if a[i]<=a[i+1]:

           ans='YES'

        else:

            ans='NO'

            break

        i+=1

    print(ans)
Problem: 2060D - Subtract Min Sort
Language: python

Solution 1 (runtime: 202 ms):
#include <bits/stdc++.h>
using namespace std;
void solve()
{
    int n;
    cin >> n;
    vector<int> A(n);
    for(int i=0;i<n;i++) {
        cin >> A[i];
    }

    for(int i=1;i<n;i++) {
        int min_v=min(A[i-1],A[i]);
        A[i-1]-=min_v;
        A[i]-=min_v;
    }

    for(int i=0;i<n-1;i++) {
        if(A[i]) {
            cout << "NO\n";
            return;
        }
    }
    cout << "YES\n";
}
int main()
{
    int t;
    cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}

Solution 2 (runtime: 202 ms):


for _ in range(int(input())):

	n = int(input())

	a = list(map(int,input().split(' ')))

	minim = float('-inf')

	complete = False



	for i in range(n-1):

		curr = a[i]

		nx = a[i+1]

		if nx-curr>=0:

			a[i+1] = nx-curr

		else:

			print("NO")

			complete = True

			break

	if not complete:

		print("YES")
Problem: 2060D - Subtract Min Sort
Language: python

Solution 1 (runtime: 202 ms):
#include <bits/stdc++.h>
using namespace std;
void solve()
{
    int n;
    cin >> n;
    vector<int> A(n);
    for(int i=0;i<n;i++) {
        cin >> A[i];
    }

    for(int i=1;i<n;i++) {
        int min_v=min(A[i-1],A[i]);
        A[i-1]-=min_v;
        A[i]-=min_v;
    }

    for(int i=0;i<n-1;i++) {
        if(A[i]) {
            cout << "NO\n";
            return;
        }
    }
    cout << "YES\n";
}
int main()
{
    int t;
    cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}

Solution 2 (runtime: 218 ms):
for _ in range(int(input())):

    n=int(input())

    a=list(map(int,input().split()))

    ans='yes'

    for i in range(n-1):

        if a[i+1]<a[i]:

            ans = 'NO'

            break

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

        a[i]=0

    print(ans)
Problem: 2060D - Subtract Min Sort
Language: python

Solution 1 (runtime: 202 ms):
#include <bits/stdc++.h>
using namespace std;
void solve()
{
    int n;
    cin >> n;
    vector<int> A(n);
    for(int i=0;i<n;i++) {
        cin >> A[i];
    }

    for(int i=1;i<n;i++) {
        int min_v=min(A[i-1],A[i]);
        A[i-1]-=min_v;
        A[i]-=min_v;
    }

    for(int i=0;i<n-1;i++) {
        if(A[i]) {
            cout << "NO\n";
            return;
        }
    }
    cout << "YES\n";
}
int main()
{
    int t;
    cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}

Solution 2 (runtime: 234 ms):
t = int(input())

answers = []

for _ in range(t):

n =  int(input())

seq = list(map(int, input().split()))

answer = 'YES'

i = 0

while i < len(seq):

if i == len(seq) - 1:

if seq[i] < seq[i-1]:

answer = 'NO'

break

min_val = min(seq[i], seq[i + 1])

seq[i] -= min_val

seq[i + 1] -= min_val

if (seq[i] < seq[i-1] or seq[i] > seq[i+1]) and i > 0:

answer = 'NO'

break

i += 1

answers.append(answer)



for answer in answers:

print(answer)
Problem: 2060D - Subtract Min Sort
Language: python

Solution 1 (runtime: 202 ms):
#include <bits/stdc++.h>
using namespace std;
void solve()
{
    int n;
    cin >> n;
    vector<int> A(n);
    for(int i=0;i<n;i++) {
        cin >> A[i];
    }

    for(int i=1;i<n;i++) {
        int min_v=min(A[i-1],A[i]);
        A[i-1]-=min_v;
        A[i]-=min_v;
    }

    for(int i=0;i<n-1;i++) {
        if(A[i]) {
            cout << "NO\n";
            return;
        }
    }
    cout << "YES\n";
}
int main()
{
    int t;
    cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}

Solution 2 (runtime: 203 ms):
t = int(input())



while t > 0:

n = int(input())

solved = False

arr = list(map(int, input().split()))

for i in range(n-1):

q = min(arr[i], arr[i+1])

arr[i] = arr[i]- q

arr[i+1] = arr[i+1]- q

for i in range(n-1):

if arr[i+1]<arr[i]:

solved = True

print("NO")

break

if not solved:

print("YES")





t -= 1
Problem: 2060D - Subtract Min Sort
Language: python

Solution 1 (runtime: 202 ms):
#include <bits/stdc++.h>
using namespace std;
void solve()
{
    int n;
    cin >> n;
    vector<int> A(n);
    for(int i=0;i<n;i++) {
        cin >> A[i];
    }

    for(int i=1;i<n;i++) {
        int min_v=min(A[i-1],A[i]);
        A[i-1]-=min_v;
        A[i]-=min_v;
    }

    for(int i=0;i<n-1;i++) {
        if(A[i]) {
            cout << "NO\n";
            return;
        }
    }
    cout << "YES\n";
}
int main()
{
    int t;
    cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}

Solution 2 (runtime: 233 ms):
'''********************* بسم الله الرحمن الرحيم ***********************'''



def listinp(): #list of integers

return list(map(int,input().split()))

def mulint(): #consecutive integers

return map(int,input().split())

def mulstr(): #consecutive str

return map(str,input().split())

def strlist():  #str list

return list(input())

def intinp():  #integer

return int(input())

def inp():   #string

return input()



from collections import defaultdict,deque

from bisect import bisect_left,bisect_right

from heapq import heappop,heappush,heapify

from math import ceil,isqrt



def solution():

x = intinp()

arr = listinp()

for i in range(1,x):

if arr[i-1]<=arr[i]:

arr[i] -= arr[i-1]

arr[i-1] = 0

elif arr[i-1] > arr[i]:

arr[i-1] -= arr[i]

arr[i] = 0

print('YnEoS'[not(arr == sorted(arr))::2])

for _ in range(intinp()):

solution()