#include <bits/stdc++.h>

using namespace std;

#define endl "\n"

#define int long long

void s1() {

    int n; cin >> n;

    vector<int> a(n);

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

        cin >> a[i];

    }

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

        cout << "NO" << endl;

        return;

    }

    bool flag = true;

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

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

            flag = false;

            break;

        }

    }

    if (flag) {

        cout << "YES" << endl;

        return;

    }

    int sdd = 0, dup = a[0];

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

        if (a[i] != dup) {

            sdd = i - 1;

            break;

        }

    }

    // if (sdd != 0 && a[sdd] > a[sdd + 1]) {

    //     sdd++;

    // }

    // cerr << sdd << endl;

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

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

            // cout << i << endl;

            cout << "NO" << endl;

            return;

        }

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

        a[i] -= temp;

        a[i + 1] -= temp;

        // cout << a[i] << " " << a[i + 1] << endl;

    }

    cout << "YES" << endl;

    return;

}

signed main() {

    ios::sync_with_stdio(0);

    cin.tie(0);

    int t; cin >> t;

    while (t--) {

        s1();

    }

    // s1();

    return 0;

}

#include <bits/stdc++.h>

using namespace std;

#define endl "\n"

#define int long long

void s1() {

    int n; cin >> n;

    vector<int> a(n);

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

        cin >> a[i];

    }

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

        cout << "NO" << endl;

        return;

    }

    bool flag = true;

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

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

            flag = false;

            break;

        }

    }

    if (flag) {

        cout << "YES" << endl;

        return;

    }

    int sdd = 0, dup = a[0];

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

        if (a[i] != dup) {

            sdd = i - 1;

            break;

        }

    }

    if (sdd > 0 && sdd % 2 == 1) sdd--;

    // if (sdd != 0 && a[sdd] > a[sdd + 1]) {

    //     sdd++;

    // }

    // cerr << sdd << endl;

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

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

            // cout << i << endl;

            cout << "NO" << endl;

            return;

        }

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

        a[i] -= temp;

        a[i + 1] -= temp;

        // cout << a[i] << " " << a[i + 1] << endl;

    }

    cout << "YES" << endl;

    return;

}

signed main() {

    ios::sync_with_stdio(0);

    cin.tie(0);

    int t; cin >> t;

    while (t--) {

        s1();

    }

    // s1();

    return 0;

}

Answer: 2


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll int
#define lli long long int
#define vi vector<int>
#define vll vector<long long>
#define rev(all) reverse(v.begin(),v.end())
#define pb push_back

void solve()
{
    ll n;
    cin >> n;
    vll v(n);
    for(int i = 0; i<n; i++) cin >> v[i];

    ll f = 0,c = 0;
    for(int i = n-1; i>0; i--)
    {
        if(v[i] < v[i-1] && v[i-1] - v[i] == 1)
        {

        }
        else
        {
            c = 1;
            break;
        }
    }

    if(c == 0)
    {
        cout << "NO\n";
        return;
    }
    for(int i = 0; i<n-1; i++)
    {
        if(v[i] == v[i+1])
        {
            if(v[i+2] < v[i])
            {
                f = 1;
                break;
            }
        }
    }
    if(f) cout << "NO\n";
    else cout << "YES\n";
}
int32_t main()
{
    ll t = 1;
    cin >> t;
    while(t--)
    {
        solve();
    }
}

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll int
#define lli long long int
#define vi vector<int>
#define vll vector<long long>
#define rev(all) reverse(v.begin(),v.end())
#define pb push_back

void solve()
{
    ll n;
    cin >> n;
    vll ve(n);
    for (ll &i : ve) cin >> i;
    ll j = 0;
    for (ll i = 1; i < n; i++) {
        if (ve[i-1] > ve[i]) j = i;
    }
    if (j == 0) {
        cout << "YES\n";
        return;
    }
    auto fop = [&](ll i) {
        ll minN = min(ve[i], ve[i+1]);
        ve[i] -= minN;
        ve[i+1] -= minN;
    };
    for (ll i = 0; i < j; i++) {
        fop(i);
    }
    cout << (is_sorted(ve.begin(), ve.end()) ? "YES" : "NO") << '\n';
}
int32_t main()
{
    ll t = 1;
    cin >> t;
    while(t--)
    {
        solve();
    }
}

Answer: 2


/*

وَهُوَ مَعَكُمْ أَيْنَ مَا كُنْتُم

_       _                           _          _               _   _

/ \     | |                         | |        | |             | | (_)

/   \    | |         |FREE|          | |   ___  | |__     __ _  | |  _

/ / \ \   | |       |PALESTINE|   _   | |  / _ \ | '_ \   / _` | | | | |

/ __ __ \  | |____                | |__| | |  __/ | |_) | | (_| | | | | |

/_/     \_\ |______|                \____/   \___| |_.__/   \__,_| |_| |_|

*/

#include <bits/stdc++.h>

using namespace std;

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

#define endl '\n'

#define int long long

void tracking(vector<int> v) {

for (int i = 0; i < v.size(); i++) {

cout << v[i] << " ";

}

cout << endl;

}

void Input(vector<int> &v) {

for (int &x : v) {

cin >> x;

}

}

#define posative(a) max(a, 0LL);

#define FAST                                                                   \

ios_base::sync_with_stdio(0);                                                \

cin.tie(nullptr);                                                            \

cout.tie(nullptr);

#define fileIO                                                                 \

freopen("input.txt", "r", stdin);                                            \

freopen("output.txt", "w", stdout)

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

void solve() {

int n;

cin >> n;

vector<int> a(n);

vector<int> case1(n);

vector<int> case2(n);

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

cin >> a[i];

}

case2 = a;

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

int mn = min(case2[i], case2[i - 1]);

case2[i - 1] -= mn;

case2[i] -= mn;

}

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

if (!(case2[i] >= case2[i - 1])) {

cout << "NO" << endl;

return;

}

}

cout << "YES" << endl;

}

signed main() {

FAST;

#ifndef ONLINE_JUDGE

fileIO;

#endif

int t = 1;

cin >> t;

for (int i = 1; i <= t; i++) {

// cout<<"Case "<<i<<": ";

solve();

}

return 0;

}

Answer: 1


#include<bits/stdc++.h>

#define ll long long

using namespace std;

void solve(){

int n;

cin>>n;

vector<int>temp(n);

for(int i=0;i<n;i++) cin>>temp[i];

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

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

cout<<"NO"<<endl;

return;

}

}

for(int i=n-1;i>0;i-=2){

if(temp[i]<temp[i-1]){

cout<<"NO"<<endl;

return;

}

}

cout<<"YES"<<endl;

return;

}

int main(){

int t;

cin >> t;

while(t--)

solve();

return 0;

}

#include<bits/stdc++.h>

#define ll long long

using namespace std;

void solve(){

int n;

cin>>n;

vector<int>temp(n);

for(int i=0;i<n;i++) cin>>temp[i];

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

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

if(temp[i+1]<0){

cout<<"NO"<<endl;

return;

}

}

cout<<"YES"<<endl;

return;

}

int main(){

int t;

cin >> t;

while(t--)

solve();

return 0;

}

Answer: 2


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define beoli ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int t,n;int a[1000069];int x;
int main(){
	beoli
	cin>>t;
	while(t--){
		cin>>n;
		for(int i=0;i<n;i++){
			cin>>a[i];
		}
		for(int i=0;i<n;i++){
			int temp=a[i];
			a[i]-=min(temp,a[i+1]);
			a[i+1]-=min(temp,a[i+1]);
		}
		for(int i=0;i<n-1;i++){
			if(a[i]>0){
				cout<<"NO"<<endl;
				break;
			}
			if(i==n-2) cout<<"YES"<<endl;
		}
	}
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define beoli ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int t,n;int a[1000069];int x;
int main(){
	beoli
	cin>>t;
	while(t--){
		cin>>n;
		for(int i=0;i<n;i++){
			cin>>a[i];
		}
		for(int i=1;i<n;i++){
			if(a[i]>a[i-1]){
				cout<<"YES"<<endl;
				break;
			}else if(a[i]<a[i-1]){
				cout<<"NO"<<endl;
				break;
			}
		}
	}
}

Answer: 1


#include<bits/stdc++.h>

using namespace std;

using ll = long long;

int main(){

    int t; cin >> t;

    while(t--){

        int n; cin >> n;

        ll a[n];

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

            cin >> a[i];

        }

        ll k = a[1] - a[0];

        ll sum=0;

        if(k < 0) cout << "NO" << endl;

        else{

            for(int i=2; i<n; i++){

                if(a[i] >= k){

                    sum += 1;

                    k = a[i] - k;

                }

        }

            if(sum == n-2){

                cout << "YES" << endl;

        }

            else cout << "NO" << endl;

        }

    }

}

#include<bits/stdc++.h>

using namespace std;

using ll = long long;

int main(){

    int t; cin >> t;

    while(t--){

        int n; cin >> n;

        ll a[n];

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

            cin >> a[i];

        }

        ll k = a[1] - a[0];

        ll sum=0;

        if(k < 0) cout << "NO" << endl;

        else{

            for(int i=2; i<n; i++){

                if(a[i] > k){

                    sum += 1;

                    k = a[i] - k;

                }

        }

            if(sum == n-2){

                cout << "YES" << endl;

        }

            else cout << "NO" << endl;

        }

    }

}

Answer: 1


#include<bits/stdc++.h>

using namespace std;

void solve(){

	int n,t=0;

	cin>>n;

	int a[n];

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

		cin>>a[i];

	}

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

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

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

			t=1;

			break;

		}

		a[i]-=mi;

		a[i+1]-=mi;

	}

	if (t==1){

		cout<<"NO"<<endl;

	}

	if (t==0){

		cout<<"YES"<<endl;

	}

}

int main(){

	int T;

	cin>>T;

	while (T--){

		solve();

	}

	return 0;

}

#include<bits/stdc++.h>

using namespace std;

void solve(){

	int n,t=0;

	cin>>n;

	int a[n];

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

		cin>>a[i];

	}

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

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

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

			t=1;

			break;

		}

		if (a[i+2]<=a[i+1]){

			a[i]-=mi;

			a[i+1]-=mi;

		}

	}

	if (t==1){

		cout<<"NO"<<endl;

	}

	if (t==0){

		cout<<"YES"<<endl;

	}

}

int main(){

	int T;

	cin>>T;

	while (T--){

		solve();

	}

	return 0;

}

Answer: 1


t = int(input())
for i in range(t):
    n = int(input())
    nums = list(map(int, input().split()))
    left = 0
    right = 2
    check = True
    while right < n:
        if nums[left] > nums[left+1]:
            check = False
            break
        elif nums[right] < nums[left+1]:
            nums[left+1] -= nums[left]
            nums[left] = 0
            left += 1
            right += 1
        else:
            left += 1
            right += 1

    if check:
        print('Yes')
    else:
        print('No')

t = int(input())
for i in range(t):
    n = int(input())
    nums = list(map(int, input().split()))
    left = 0
    check = True
    while left < n-1:
        if nums[left] > nums[left+1]:
            check = False
            break
        else:
            nums[left+1] -= nums[left]
            nums[left] = 0
            left += 1

    if check:
        print('Yes')
    else:
        print('No')

Answer: 2


#include<iostream>

#include<vector>

#include<string>

using namespace std;

int main(){

    int t; cin >> t;

    while(t--){

        int n; cin >> n;

        int arr[n+1]; arr[0]=0;

        string answer = "YES";

        for(int i = 1; i <= n; i++) cin >> arr[i];

        for(int i = 2; i <= n; i++){

            if(arr[i] < abs(arr[i-1] - arr[i-2])) {

                answer = "NO"; break;

            } else arr[i-1] = abs(arr[i-1] - arr[i-2]);

        }

        cout << answer << "\n";

    }

}

#include<iostream>

#include<vector>

#include<string>

using namespace std;

int main(){

    int t; cin >> t;

    while(t--){

        int n; cin >> n;

        int arr[n+1]; arr[0]=0;

        string answer = "YES";

        for(int i = 1; i <= n; i++) cin >> arr[i];

        for(int i = 2; i <= n; i++){

            if(arr[i] < abs(arr[i-1] - arr[i-2])) {

                answer = "NO"; break;

            }

        }

        cout << answer << "\n";

    }

}

Answer: 1


#include<bits/stdc++.h>
using namespace std;
void solve()
{
    int n;
    cin>>n;
    vector<int>a(n+1);
    for(int i=1;i<=n;i++)\
    {
        cin>>a[i];
    }
    for(int i=1;i<n;i++)
    {
        int k=min(a[i],a[i+1]);
        a[i]=a[i]-k;
        a[i+1]=a[i+1]-k;
        if(a[i]>0){
            cout<<"NO"<<endl;
            return;
        }
    }
    if(a[n]>=0)cout<<"YES"<<endl;
     else cout<<"NO"<<endl;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie();
    int t;
    cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
void solve()
{
    int n;
    cin>>n;
    vector<int>a(n+1);
    for(int i=1;i<=n;i++)\
    {
        cin>>a[i];
    }
    for(int i=1;i<n;i++)
    {
        int k=min(a[i],a[i+1]);
        a[i]=a[i]-k;
        a[i+1]=a[i+1]-k;
        if(a[i]>0){
            cout<<"NO"<<endl;
            return;
        }
    }
    if(a[n]>0)cout<<"YES"<<endl;
     else cout<<"NO"<<endl;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie();
    int t;
    cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}

Answer: 1


#include<bits/stdc++.h>

using namespace std;

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

#define allr(a) a.rbegin(),a.rend()

#define ll long long

const ll mod = 1000000007;

void solve()

{

    int n;

    cin>>n;

    vector<int> v(n);

    for(auto &it:v) cin>>it;

    if(v[0] >= v[1]){

        cout << "NO" << endl;

        return ;

    }

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

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

        v[i]-=sub;

        v[i+1]-=sub;

    }

    int f = 1;

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

        if(v[i] > v[i+1]) f = 0;

    }

    if(f) cout << "YES" << endl;

    else cout << "NO" << endl;

}

int main()

{

    ios::sync_with_stdio(false);

    cin.tie(0);

    int t = 1;

    cin>>t;

    while(t--){

        solve();

    }

    return 0;

}

#include<bits/stdc++.h>

using namespace std;

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

#define allr(a) a.rbegin(),a.rend()

#define ll long long

const ll mod = 1000000007;

void solve()

{

    int n;

    cin>>n;

    vector<int> v(n);

    for(auto &it:v) cin>>it;

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

        cout << "NO" << endl;

        return ;

    }

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

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

        v[i]-=sub;

        v[i+1]-=sub;

    }

    int f = 1;

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

        if(v[i] > v[i+1]) f = 0;

    }

    if(f) cout << "YES" << endl;

    else cout << "NO" << endl;

}

int main()

{

    ios::sync_with_stdio(false);

    cin.tie(0);

    int t = 1;

    cin>>t;

    while(t--){

        solve();

    }

    return 0;

}

Answer: 2


/* In the Name of ALLAH, the most gracious, the most merciful  */
/* Watch the solve video on -> youtube.com/@MythologicalCoding */
#include <bits/stdc++.h>
using namespace std;
#define nl endl
#define ll long long
#define cy cout<<"YES"<<nl
#define cn cout<<"NO"<<nl
#define dis(x) cerr<<#x<<" = "<<x<<nl
#define all(v) (v).begin(),(v).end()
#define si(v) int((v).size())
#define pb push_back
const int inf = 1e9;
const ll INF = 1e18;
const int mod = 998244353;
const int Big = 2e5 + 5;
// Formula X:
ll findIndex(const vector<ll>& v, ll e) { auto it =find(all(v),e);
    if(it!=v.end()){return distance(v.begin(),it);}return -1; }
ll gcd(ll a,ll b) { if(b==0)return a;return gcd(b,a%b); }//__gcd
ll lcm(ll a,ll b) { return(1LL*a*b)/__gcd(a, b); }
ll sumFrom_IToJ(ll i,ll j) { return((j - i + 1LL)*(i + j))/2; }
bool sorta_2nd(const pair<int,int>&a,const pair<int,int>&b)
    { return(a.second<b.second); /* Use : sort(all(vec),sorta_2nd);*/ }
bool isPrime(ll n) { if(n<=1)return false;if(n<=3)return true;if(n%2==0||n%3==0)return false;
    for(ll i=5;i*i<=n;i=i+6) if(n%i==0||n%(i+2)==0)return false;return true; }
bool isPowerOfTwo(ll n) { return(n>0) && (n&(n-1))==0; }

void solve() {
    ll n;cin>>n;
    vector<ll>v(n);

    for(auto &i:v)
    cin>>i;

    if(is_sorted(all(v)))
    {
        cy;return;
    }
    ll b=0,ix=1;
    for(ll i=1;i<n;i++)
    {
        if(v[i-1]>v[i])
        b=i;
    }
    // dis(b);
    for(ll i=0;i<b;i++)
    {
        ll mn=min(v[i],v[i+1]);
        v[i]-=mn;v[i+1]-=mn;
    }

    is_sorted(all(v))?cy:cn;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int T = 1;
    cin >> T;
    for (int i = 1; i <= T; i++) {
        //cout << "Case " << i << ": ";
        solve();
    }
 return 0;
}

/* In the Name of ALLAH, the most gracious, the most merciful  */
/* Watch the solve video on -> youtube.com/@MythologicalCoding */
#include <bits/stdc++.h>
using namespace std;
#define nl endl
#define ll long long
#define cy cout<<"YES"<<nl
#define cn cout<<"NO"<<nl
#define dis(x) cerr<<#x<<" = "<<x<<nl
#define all(v) (v).begin(),(v).end()
#define si(v) int((v).size())
#define pb push_back
const int inf = 1e9;
const ll INF = 1e18;
const int mod = 998244353;
const int Big = 2e5 + 5;
// Formula X:
ll findIndex(const vector<ll>& v, ll e) { auto it =find(all(v),e);
    if(it!=v.end()){return distance(v.begin(),it);}return -1; }
ll gcd(ll a,ll b) { if(b==0)return a;return gcd(b,a%b); }//__gcd
ll lcm(ll a,ll b) { return(1LL*a*b)/__gcd(a, b); }
ll sumFrom_IToJ(ll i,ll j) { return((j - i + 1LL)*(i + j))/2; }
bool sorta_2nd(const pair<int,int>&a,const pair<int,int>&b)
    { return(a.second<b.second); /* Use : sort(all(vec),sorta_2nd);*/ }
bool isPrime(ll n) { if(n<=1)return false;if(n<=3)return true;if(n%2==0||n%3==0)return false;
    for(ll i=5;i*i<=n;i=i+6) if(n%i==0||n%(i+2)==0)return false;return true; }
bool isPowerOfTwo(ll n) { return(n>0) && (n&(n-1))==0; }

void solve() {
    ll n;cin>>n;
    vector<ll>v(n);

    for(auto &i:v)
    cin>>i;

    if(v[0]==*max_element(all(v)))
    cn;
    else cy;

}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int T = 1;
    cin >> T;
    for (int i = 1; i <= T; i++) {
        //cout << "Case " << i << ": ";
        solve();
    }
 return 0;
}

Answer: 1


#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 = n-2; i >= 1; i--) {

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

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

            a[i] -= jar;

            if(a[i-1] - jar < 0) {

                cout << "no\n"; return;

            }

            a[i-1] -= jar;

            i--;

        }

    }

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

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

            cout << "no\n"; return;

        }

    }

    cout << "yes\n";

}

int main()

{

    ios::sync_with_stdio(false); cin.tie(0);

    int t; cin >> t;

    while(t--) solve();

    return 0;

}

#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 = n-2; i >= 1; i--) {

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

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

            a[i] -= jar;

            if(a[i-1] - jar < 0) {

                cout << "no\n"; return;

            }

            a[i-1] -= jar;

        }

    }

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

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

            cout << "no\n"; return;

        }

    }

    cout << "yes\n";

}

int main()

{

    ios::sync_with_stdio(false); cin.tie(0);

    int t; cin >> t;

    while(t--) solve();

    return 0;

}

Answer: 2


#include <bits/stdc++.h>

using namespace std;

#define ll long long

#define vi vector<int>

#define vll vector<long long>

int main()

{

ios_base::sync_with_stdio(false);

cin.tie(nullptr);

cout.tie(nullptr);

int t;

cin>>t;

while(t--)

{

int n,diff;

string ans="YES";

cin>>n;

int arr[n];

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

{

cin>>arr[i];

}

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

{

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

arr[i] = arr[i]-diff;

arr[i+1]= arr[i+1] - diff;

if ((arr[i]>0) || (arr[i+1] == 0))

{

ans="NO";

break;

}

}

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

//  {

//     cout<<arr[i]<<' ';

//  }

//  cout<<endl;

cout<<ans<<endl;

}

return 0;

}

#include <bits/stdc++.h>

using namespace std;

#define ll long long

#define vi vector<int>

#define vll vector<long long>

int main()

{

ios_base::sync_with_stdio(false);

cin.tie(nullptr);

cout.tie(nullptr);

int t;

cin>>t;

while(t--)

{

int n,diff;

string ans="YES";

cin>>n;

int arr[n];

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

{

cin>>arr[i];

}

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

{

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

arr[i] = arr[i]-diff;

arr[i+1]= arr[i+1] - diff;

if ((arr[i]>0) && (arr[i+1] == 0))

{

ans="NO";

break;

}

}

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

//  {

//     cout<<arr[i]<<' ';

//  }

//  cout<<endl;

cout<<ans<<endl;

}

return 0;

}

Answer: 2


#include <bits/stdc++.h>

using namespace std;

int main() {

int t;

cin >> t;

while (t--) {

int n;

cin>>n;

vector<int>v(n);

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

cin>>v[i];

}

bool valid = true;

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

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

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

v[i] = 0;

}else {

valid = false;

break;

}

}

if (valid) {

cout<<"YES"<<endl;

}else {

cout<<"NO"<<endl;

}

}

return 0;

}

#include <bits/stdc++.h>

using namespace std;

int main() {

int t;

cin >> t;

while (t--) {

int n;

cin>>n;

vector<int>v(n);

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

cin>>v[i];

}

bool valid = true;

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

if (v[i]<=v[i+1]) {

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

v[i] = 0;

}else {

valid = false;

break;

}

}

if (valid) {

cout<<"YES"<<endl;

}else {

cout<<"NO"<<endl;

}

}

return 0;

}

Answer: 2


#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
typedef long long ll;
ll n,a[N];
void solve(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    int flag=0;
    for(int i=1;i<n;i++){
        ll t=min(a[i],a[i+1]);
        a[i]-=t,a[i+1]-=t;
        if(a[i+1]==0){
            cout<<"NO"<<endl;
            return ;
        }
    }
    cout<<"YES"<<endl;
    return ;
}

int main(){
    int _;
    cin>>_;
    while(_--){
        solve();
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
typedef long long ll;
ll n,a[N];
void solve(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(int i=1;i<n;i++){
        if(a[i]>a[i+1]){
            cout<<"NO"<<endl;
            return ;
        }
        ll t=min(a[i],a[i+1]);
        a[i]-=t,a[i+1]-=t;

    }
    cout<<"YES"<<endl;
    return ;
}

int main(){
    int _;
    cin>>_;
    while(_--){
        solve();
    }
    return 0;
}

Answer: 2


#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mod=1e9+7;
int dx[8]={-1,0,0,1,-1,-1,1,1};
int dy[8]={0,-1,1,0,-1,1,-1,1};

void nishant2526(){
  int n;
  cin>>n;
  vector<int> arr(n);
  for(int i=0;i<n;i++){
    cin>>arr[i];
  }
  for(int i=0;i<n;i+=2){
    if((arr[i+1]-arr[i])<1){
       cout<<"NO"<<endl;
       return;
    }
  }
  cout<<"YES"<<endl;

}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  int tt;
  cin >> tt;
  while (tt--)
  {
    nishant2526();
  }

  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mod=1e9+7;
int dx[8]={-1,0,0,1,-1,-1,1,1};
int dy[8]={0,-1,1,0,-1,1,-1,1};

void nishant2526(){
  int n;
  cin>>n;
  vector<int> arr(n);
  for(int i=0;i<n;i++){
    cin>>arr[i];
  }
  for(int i=1;i<n;i++){
    if(arr[i-1]>arr[i]){
      cout<<"NO"<<endl;
      return;
    }
    else{
      arr[i]-=arr[i-1];
      arr[i-1]=0;
    }
  }
  cout<<"YES"<<endl;

}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  int tt;
  cin >> tt;
  while (tt--)
  {
    nishant2526();
  }

  return 0;
}

Answer: 2


#include <bits/stdc++.h>
using namespace std;
#define loop(i,a,b) for(int i = a; i < b; i += 1)
#define ll long long
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t;
    label:
    while(t--)
    {
        int n;
        cin >> n;
        vector<int> arr(n);
        loop(i,0,n) cin >> arr[i];
        int dif = arr[1]-arr[0];
        if(dif < 0)
            {
                cout << "NO" << endl;
                goto label;
            }
        loop(i,2,n)
        {
            dif = arr[i]-dif;
            if(dif < 0)
            {
                cout << "NO" << endl;
                goto label;
            }
        }
        cout << "YES"<< endl;
    }
}

#include <bits/stdc++.h>
using namespace std;
#define loop(i,a,b) for(int i = a; i < b; i += 1)
#define ll long long
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t;
    label:
    while(t--)
    {
        int n;
        cin >> n;
        vector<int> arr(n);
        loop(i,0,n) cin >> arr[i];
        int dif = arr[1]-arr[0];
        loop(i,2,n)
        {
            dif = arr[i]-dif;
            if(dif < 0)
            {
                cout << "NO" << endl;
                goto label;
            }
        }
        cout << "YES"<< endl;
    }
}

Answer: 1


#include<bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin >> n;
        vector<int> a;
        int flag=0;
        for(int i=0;i<n;++i){
            int x;
            cin >> x;
            a.push_back(x);
        }
        if(a[0]>a[1]) {
            cout<<"NO"<<endl;
            flag=1;
        }
        else{
            for(int i=0;i<n-1;++i){
                int x = min(a[i],a[i+1]);
                a[i]-=x;
                a[i+1]-=x;
                if(a[i]>a[i+1]){
                    cout<<"NO"<<endl;
                    flag=1;
                    break;
                }
            }
        }
        if(flag==0)cout<<"YES"<<endl;
    }
}

#include<bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin >> n;
        vector<int> a;
        int flag=0;
        for(int i=0;i<n;++i){
            int x;
            cin >> x;
            a.push_back(x);
        }
        if(a[0]>a[1]) {
            cout<<"NO"<<endl;
            flag=1;
        }
        else{
            for(int i=1;i<n-1;++i){
                if(a[i]>a[i+1]){
                    int x = min(a[i],a[i-1]);
                    if((a[i]-x)>a[i+1]){
                        cout<<"NO"<<endl;
                        flag=1;
                        break;
                    }
                    else{
                        a[i]-=x;
                        a[i-1]-=x;
                    }
                }
            }
        }
        if(flag==0)cout<<"YES"<<endl;
    }
}

Answer: 1


#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int arr[n];
        for(int i=0;i<n;i++){
            cin>>arr[i];
        }
        int flag=0;
        for(int i=0;i<n-1;i++){
            if(arr[i]<=arr[i+1]){
                arr[i+1]-=arr[i];
                arr[i]=0;
            }else{
                flag=1;
                break;
            }
        }
        if(flag==0){
            cout<<"Yes\n";
        }else{
            cout<<"No\n";
        }
    }
}

#include <bits/stdc++.h>
using namespace std;
int MOD=1e9+7;

void solve(){
    int n;
    cin>>n;
    vector<int> v(n);
    bool sorted = true;
    for(int i = 0; i<n; i++){
        int a;
        cin>>a;
        v[i] = a;
        if(i > 0 && v[i-1] > v[i]){
            sorted = false;
        }
    }
    if(sorted){
        cout<<"YES"<<endl;
        return;
    }
    if(v[0] > v[1]){
        cout<<"NO"<<endl;
        return;
    }

    int b = 1;
    for(int i = 0; i<n-1; i++){
        if(v[i] > v[i+1]){
            b = 0;
            break;
        }else{
            v[i+1] -= v[i];
        }
    }
    if(b == 1){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }

    // 4 5 4 5 4 5 4 5

}

int main(){

    int T = 1;
    cin >> T;
    while (T--)
    {
        solve();
    }

    return 0;
}

Answer: 1


#include<bits/stdc++.h>
using namespace std;

#define X first
#define Y second
#define pb push_back
#define pii pair<int,int>
#define spacce cerr << "====" << endl
const int maxn = 2e5 + 5;
const int INF = 1e9;
const int MOD = 998244353;
void solve()
{
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++)
        cin>>a[i];
    for(int i = 0; i < n-2; i++)
    {
        if(a[i] > a[i+1] && a[i+1] > a[i+2])
        {
            cout << "NO" << endl;
            return;
        }
    }
    cout << "YES" << endl;
}

int32_t main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    bool tc = 1;
    int ttt = tc ? (cin >> ttt, ttt) : 1;

    while(ttt--)
        solve(), spacce;

    return 0;
}

//    _  __   ________   _      _____
//   / |/ /__/_  __/ /  (_)__  / ___/
//  /    / _ \/ / / _ \/ / _ \/ (_ /
// /_/|_/\___/_/ /_//_/_/_//_/\___/   is real.
//

#include<bits/stdc++.h>
using namespace std;

#define X first
#define Y second
#define pb push_back
#define pii pair<int,int>
#define spacce cerr << "====" << endl
const int maxn = 2e5 + 5;
const int INF = 1e9;
const int MOD = 998244353;
void solve()
{
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++)
        cin>>a[i];
    for(int i = 0; i < n-1; i++)
    {
        if(a[i] > a[i+1])
        {
            cout << "NO" << endl;
            return;
        }
        a[i+1] -= a[i];
        a[i] = 0;
    }
    cout << "YES" << endl;
}

int32_t main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    bool tc = 1;
    int ttt = tc ? (cin >> ttt, ttt) : 1;

    while(ttt--)
        solve(), spacce;

    return 0;
}

//    _  __   ________   _      _____
//   / |/ /__/_  __/ /  (_)__  / ___/
//  /    / _ \/ / / _ \/ / _ \/ (_ /
// /_/|_/\___/_/ /_//_/_/_//_/\___/   is real.
//

Answer: 2


def solve():
    import sys

    input_data = sys.stdin.read().strip().split()
    t = int(input_data[0])
    index = 1

    results = []
    for _ in range(t):
        n = int(input_data[index])
        index += 1

        # Read the array of integers
        a = list(map(int, input_data[index:index+n]))
        index += n

        # Perform the "subtract min" operation in a single left-to-right pass
        for i in range(n - 1):
            if a[i] <= a[i + 1]:
                # Subtract a[i] from a[i+1], and make a[i] zero
                a[i+1] -= a[i]
                a[i] = 0

        # Check if the final array is non-decreasing
        if all(a[i] <= a[i+1] for i in range(n-1)):
            results.append("YES")
        else:
            results.append("NO")

    # Output one result per test case
    print("\n".join(results))

solve()

def solve():
    import sys
    input_data = sys.stdin.read().strip().split()

    t = int(input_data[0])
    idx = 1
    answers = []

    for _ in range(t):
        n = int(input_data[idx]); idx += 1
        a = list(map(int, input_data[idx: idx+n]))
        idx += n

        # Single pass from left to right
        for i in range(n-1):
            if a[i] <= a[i+1]:
                # Subtract a[i] from a[i+1], set a[i] to 0
                a[i+1] -= a[i]
                a[i] = 0

        # Check if final array is non-decreasing
        possible = all(a[i] <= a[i+1] for i in range(n-1))
        answers.append("YES" if possible else "NO")

    print("\n".join(answers))

Answer: 1


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int t;
	cin >> t;
	while(t--)
	{
		int n;
		cin >> n;
		vector<int> a(n + 1);
		for(int i = 0; i < n; i++)
		{
			cin >> a[i];
		}
		for(int i = 0; i < n - 1; i++)
		{
			if(a[i] <= a[i + 1])
			{
				int t = min(a[i], a[i + 1]);
				a[i] -= t;
				a[i + 1] -= t;
			}
		}
		cout << (is_sorted(a.begin(), a.end()) ? "YES" : "NO");
		cout << endl;
	}
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int t;
	cin >> t;
	while(t--)
	{
		int n;
		cin >> n;
		vector<int> a(n + 1);
		for(int i = 0; i < n; i++)
		{
			cin >> a[i];
		}
		for(int i = 0; i < n - 1; i++)
		{
			if(a[i] <= a[i + 1])
			{
				int t = min(a[i], a[i + 1]);
				a[i] -= t;
				a[i + 1] -= t;
			}
		}
		bool f = 1;
		for(int i = 0; i < n - 1; i++)
		{
			if(a[i + 1] < a[i])
			f = 0;
		}
		if(f) cout << "YES";
		else cout << "NO";
		cout << endl;
	}
	return 0;
}

Answer: 2


#include <bits/stdc++.h>

using namespace std;

const int N=2e5+10;

void solve()

{

int n;

cin>>n;

int a[N];

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

{

cin>>a[i];

}

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

{

int mn=min(a[i],a[i-1]);

a[i]-=mn;

a[i-1]-=mn;

}

if(is_sorted(a,a+n))

{

cout<<"YES\n";

}

else cout<<"NO\n";

}

int main()

{

ios::sync_with_stdio(0);

cin.tie(0);

int t;

cin>>t;

while(t--)

{

solve();

}

return 0;

}

#include <bits/stdc++.h>

using namespace std;

const int N=2e5+10;

void solve()

{

int n;

cin>>n;

int a[N];

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

{

cin>>a[i];

}

int flag=1;

int flag1=0;

int mn=1e9+10;

int i=1;

while(i<n)

{

int q=a[i-1];

mn=min(q,a[i]);

if(q>a[i])

{

if(flag1)

{

if(q>=a[i-2])

{

i++;

mn=min(q,a[i-2]);

a[i-1]-=mn;

a[i-2]-=mn;

}

else

{

flag=0;

break;

}

}

else

{

flag=0;

break;

}

}

else

{

flag1=1;

a[i-1]-mn;

a[i]-=mn;

i+=2;

}

}

if(flag) cout<<"YES\n";

else cout<<"NO\n";

}

int main()

{

ios::sync_with_stdio(0);

cin.tie(0);

int t;

cin>>t;

while(t--)

{

solve();

}

return 0;

}

Answer: 1


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] >= 0:

            if i>1:

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

                arr[-1] = 0

            else:

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

        elif len(arr) < 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()

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()

Answer: 2


#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define ll long long
#define ld long double
#define uld unsigned long double
#define all(x) (x).begin(), (x).end()
#define dsort(x) sort(all(x), greater<>())
#define rev(x) reverse(all(x))
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define ff first
#define ss second
#define vec vector
#define uset unordered_set
#define umap unordered_map
#define ummap unordered_multimap
#define pb push_back
#define pf push_front
#define str string
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return (a * b) / gcd(a, b);}

int main() {
    cin.tie(0)->sync_with_stdio(0);

	int t;
	cin >> t;
	while(t--) {
		int n;
		cin>>n;
		vec<int> a(n);
		vec<int> id{};
		for(int i=0;i<n;i++){
			cin>>a[i];
			if(i>0&&a[i]<a[i-1]) id.pb(i-1);
		}
		if(a[1]<a[0]) {
			cout<<"NO"<<"\n";
			continue;
		}
		bool no=false;
		while(id.size()!=0) {
			int idx=id[0];
			// for(int i:id) cout << i << " ";
			// cout << "\n";
			// for(int i:a) cout << i << " ";
			// cout << "\n";
			if(a[idx-1]==0) {
				cout<<"NO"<<"\n";
				no=true;
				break;
			}
			for(int i=idx;i>=0;i--) {
				if(a[i]==0) {
					int m=min(a[i+1],a[i+2]);
					a[i+1]-=m;
					a[i+2]-=m;
					break;
				} else if(i==0) {
					int m=min(a[i],a[i+1]);
					a[i]-=m;
					a[i+1]-=m;
					break;
				}
			}
			if(a[idx]<=a[idx+1]) id.erase(id.begin());
		}

		if(!no) cout<<"YES"<<"\n";

		// for(int i: a) cout << i << " ";
		// cout << "\n";

	}

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define ll long long
#define ld long double
#define uld unsigned long double
#define all(x) (x).begin(), (x).end()
#define dsort(x) sort(all(x), greater<>())
#define rev(x) reverse(all(x))
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define ff first
#define ss second
#define vec vector
#define uset unordered_set
#define umap unordered_map
#define ummap unordered_multimap
#define pb push_back
#define pf push_front
#define str string
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return (a * b) / gcd(a, b);}

int main() {
    cin.tie(0)->sync_with_stdio(0);

	int t;
	cin >> t;
	while(t--) {
		int n;
		cin>>n;
		vec<int> a(n);
		for(int i=0;i<n;i++){
			cin>>a[i];
			if(i>0) {
				int m=min(a[i-1],a[i]);
				a[i-1]-=m;
				a[i]-=m;
			}
		}

		bool no=false;
		for(int i=0;i<n-1;i++){
			if(a[i]>a[i+1]) {
				no=true;
				break;
			}
		}
		if(!no) cout<<"YES\n";
		else cout<<"NO\n";

	}

    return 0;
}

Answer: 2


#include<bits/stdc++.h>

using namespace std;

#define debug(x) cout << '[' << #x << " is: " << x << "] " << endl;
#define imod(a , n) (a % n + n ) % n

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
#define inF freopen("ladder.in","r",stdin );
#define outF freopen("ladder.out" , "w" , stdout ) ;
#define sor(v) sort(v.begin() , v.end());
//#define print(v) for(auto f : v ) cout << f << " " ;
#define rsor(v) sort(v.rbegin() , v.rend());
#define rev(v) reverse(v.begin() , v.end());
#define scan(v) for(auto &it : v)cin >> it ;

#define logar(x , y) log(x) / log(y)
#define __sum(n) n * (n + 1) / 2
#define __lcm(a , b) a / __gcd(a , b) * b
#define pii pair<int , int >
#define ll long long
#define int ll
#define matrix vector<vector<ll>>
#define pii pair<int , int >

const int di[] = {1 , -1 , 0 , 0};
const int dj[] = {0 , 0 , 1 , -1};

const int mod = 1e9 + 7;
const int N = 1e6 + 6 ;

int check(int a1 ,int a2 ,int  a3 ,int  a4 ,int a5){

    return (a1 + a2 == a3) + (a2 + a3 == a4 )+ (a3 + a4 == a5) ;

}

int32_t main()

{   //inF;
    //inF;outF;
    fastio;

    int t ;
    cin >> t ;

    while(t--){

        int n ;
        cin >> n ;

        vector<int> v(n);
        for(auto &it : v)cin >> it ;
        if(v[1] < v[0])cout << "NO";
        else {
            string ans = "YES";
            int mn = min(v[1] , v[0]);
            v[1] -= mn , v[0] -= mn ;

            for(int i = 2 ; i < n ; i ++){
                if(v[i] < v[i - 1]){
                    v[i - 1] -= min(v[i - 1] , v[i - 2]);

                }
                if(v[i] < v[i - 1]){
                    ans = "NO";
                    break;
                }

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

            }
            cout << ans ;
        }

        cout << '\n';
    }

}

#include<bits/stdc++.h>

using namespace std;

#define debug(x) cout << '[' << #x << " is: " << x << "] " << endl;
#define imod(a , n) (a % n + n ) % n

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
#define inF freopen("ladder.in","r",stdin );
#define outF freopen("ladder.out" , "w" , stdout ) ;
#define sor(v) sort(v.begin() , v.end());
//#define print(v) for(auto f : v ) cout << f << " " ;
#define rsor(v) sort(v.rbegin() , v.rend());
#define rev(v) reverse(v.begin() , v.end());
#define scan(v) for(auto &it : v)cin >> it ;

#define logar(x , y) log(x) / log(y)
#define __sum(n) n * (n + 1) / 2
#define __lcm(a , b) a / __gcd(a , b) * b
#define pii pair<int , int >
#define ll long long
#define int ll
#define matrix vector<vector<ll>>
#define pii pair<int , int >

const int di[] = {1 , -1 , 0 , 0};
const int dj[] = {0 , 0 , 1 , -1};

const int mod = 1e9 + 7;
const int N = 1e6 + 6 ;

int check(int a1 ,int a2 ,int  a3 ,int  a4 ,int a5){

    return (a1 + a2 == a3) + (a2 + a3 == a4 )+ (a3 + a4 == a5) ;

}

int32_t main()

{   //inF;
    //inF;outF;
    fastio;

    int t ;
    cin >> t ;

    while(t--){

        int n ;
        cin >> n ;

        vector<int> v(n);
        for(auto &it : v)cin >> it ;
        if(v[1] < v[0])cout << "NO";
        else {
            string ans = "YES";
            for(int i = 2 ; i < n ; i ++){
                if(v[i] < v[i - 1]){
                    v[i - 1] -= min(v[i - 1] , v[i - 2]);

                }
                if(v[i] < v[i - 1]){
                    ans = "NO";
                    break;
                }
            }
            cout << ans ;
        }

        cout << '\n';
    }

}

Answer: 1


#include <bits/stdc++.h>

using namespace std;

#define endl '\n'

#define ll long long

void solve() {

int n;

cin >> n;

vector<int> a(n + 1, 0);

bool is_no = false;

for (int i = 1;i <= n;i++) cin >> a[i];

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

if (i == 1) {

if (a[i + 1] >= a[i]) continue;

else {

is_no = true;

break;

}

}

else {

if (a[i + 1] >= abs(a[i] - a[i - 1])) continue;

else {

is_no = true;

break;

}

}

}

if (!is_no) cout << "YES" << endl;

else cout << "NO" << endl;

}

int main() {

ios::sync_with_stdio(false);

cin.tie(nullptr);

int t;

cin >> t;

while (t--) solve();

return 0;

}

#include <bits/stdc++.h>

using namespace std;

#define endl '\n'

#define ll long long

void solve() {

int n;

cin >> n;

vector<int> a(n + 1, 0);

bool is_no = false;

for (int i = 1;i <= n;i++) cin >> a[i];

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

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

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

a[i] = 0;

continue;

}

else {

is_no = true;

break;

}

}

if (!is_no) cout << "YES" << endl;

else cout << "NO" << endl;

}

int main() {

ios::sync_with_stdio(false);

cin.tie(nullptr);

int t;

cin >> t;

while (t--) solve();

return 0;

}

Answer: 2


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

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

    ok = True

    for i in range(n-1):
        if nums[i]>nums[i+1]:
            ok = False
            break
        nums[i+1]-=nums[i]

    if ok:
        print("YES")
    else:
        print("NO")

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

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

    ok = True

    for i in range(n-1):
        if nums[i]>nums[i+1]:
            ok = False
            break
        nums[i+1]-=nums[i]

    if ok:
        print("YES")
    else:
        print("NO")

Answer: 1


#include <bits/stdc++.h>
#include <string>
#include <vector>

using namespace std;

int main()
{
    int t;
    cin >> t;

    while(t--)
    {
        int n;
        cin >> n;
        int d[n];
        for(int i = 0; i < n; i++)
            cin >> d[i];

        bool fl = 1;
        for(int i = 0; i < n; i+=2)
        {
            if(d[i] > d[i+1])fl = 0;
        }
        if(fl)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
}

#include <bits/stdc++.h>
#include <string>
#include <vector>

using namespace std;

int main()
{
    int t;
    cin >> t;

    while(t--)
    {
        int n;
        cin >> n;
        int d[n];
        for(int i = 0; i < n; i++)
            cin >> d[i];

        bool fl = 1;
        for(int i = 0; i < n; i+=2)
        {
            if(i == n-1)break;
            if(d[i] > d[i+1])fl = 0;
        }
        if(fl)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
}

Answer: 2


#include<bits/stdc++.h>

#define ll long long

using namespace std;

int main(){

	int t;cin>>t;

    while(t--){

    ll n;cin>>n;

    string ans="YES";

    ll a[n];

    for(ll i=041;i<n;i++){

        cin>>a[i];

        if(i>=1){

        if(a[i]>=a[i-1]){

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

            a[i-1]=0;

        }

        }

    }

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

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

            ans="NO";

            break;

        }

    }

    cout<<ans<<endl;

    }

    return 0;

}

#include<bits/stdc++.h>

#define ll long long

using namespace std;

int main(){

	int t;cin>>t;

    while(t--){

    ll n;cin>>n;

    string ans="YES";

    ll a[n];

    for(ll i=0;i<n;i++){

        cin>>a[i];

        if(i>=1){

        if(a[i]>=a[i-1]){

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

            a[i-1]=0;

        }

        }

    }

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

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

            ans="NO";

            break;

        }

    }

    cout<<ans<<endl;

    }

    return 0;

}

Answer: 2


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int t;
	cin >> t;
	while(t--)
	{
		int n;
		cin >> n;
		vector<int> a(n + 1);
		for(int i = 0; i < n; i++)
		{
			cin >> a[i];
		}
		for(int i = 0; i < n - 1; i++)
		{
			if(a[i] <= a[i + 1])
			{
				int t = min(a[i], a[i + 1]);
				a[i] -= t;
				a[i + 1] -= t;
			}
		}
		bool f = 1;
		for(int i = 0; i < n - 1; i++)
		{
			if(a[i + 1] < a[i])
			f = 0;
		}
		if(f) cout << "YES";
		else cout << "NO";
		cout << endl;
	}
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int t;
	cin >> t;
	while(t--)
	{
		int n;
		cin >> n;
		vector<int> a(n + 1);
		for(int i = 0; i < n; i++)
		{
			cin >> a[i];
		}
		for(int i = 0; i < n - 1; i++)
		{
			if(a[i] <= a[i + 1])
			{
				a[i] -= min(a[i], a[i + 1]);
				a[i + 1] -= min(a[i], a[i + 1]);
			}
		}
		cout << (is_sorted(a.begin(), a.end())) ? "YES" : "NO";
		cout << endl;
	}
	return 0;
}

Answer: 1


#include "bits/stdc++.h"

using namespace std;

using ll= long long int;

#define f(i,a,b) for(ll i=a;i<(ll)(b);i++)

#define fr(i,a,b) for(ll i=a;i>(ll)(b);--i)

#define pb push_back

#define vi vector<ll>

void solve(){

ll n;cin>>n;

vi v(n);

f(i,0,n){

    cin>>v[i];

}

if(n==2){

    if(v[0]>v[1])

    cout<<"no"<<end;

    else cout<<"yes"<<endl;

}

else{

int modda=0;

f(i,0,n-2){

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

    modda=1;break;}

}

if(modda)

cout<<"no"<<endl;

else cout<<"yes"<<endl;}

 }

int main(){ll t;cin>>t;while(t--){

    solve();

}}

#include "bits/stdc++.h"

using namespace std;

using ll= long long int;

#define f(i,a,b) for(ll i=a;i<(ll)(b);i++)

#define fr(i,a,b) for(ll i=a;i>(ll)(b);--i)

#define pb push_back

#define vi vector<ll>

void solve(){

ll n;cin>>n;

vi v(n);

f(i,0,n){

    cin>>v[i];

}int modda=0;

 f(i,0,n-1){

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

     modda=1;break;}

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

 }

 if(modda)

 cout<<"no"<<endl;

 else cout<<"yes"<<endl;

 }

int main(){ll t;cin>>t;while(t--){

    solve();

}}

Answer: 2


#include <bits/stdc++.h>

using namespace std;

void solve() {

int n;

cin >> n;

vector<int> a(n);

for(int &x : a) cin >> x;

int down = 0;

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

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

down++;

if(down > 1) break;

}

else down=0;

}

if(n==2 & a[1]>=a[0])cout<<"YES"<<endl;

else if(down <= 1) cout << "YES\n";

else cout << "NO\n";

}

int main() {

ios_base::sync_with_stdio(false);

cin.tie(nullptr);

int t;

cin >> t;

while (t--) solve();

}

#include<bits/stdc++.h>

using namespace std;

#define ll long long

void solve()

{

ll n;cin>>n;vector<ll>v(n);

for(auto &x:v)cin>>x;

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

{

if(v[i]>v[i+1]) {cout<<"NO"<<'\n';return;}

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

v[i]=0;

}

for(ll i=0;i<n-1;i++) {if(v[i]>v[i+1]){cout<<"NO"<<'\n';return;}}

cout<<"YES"<<'\n';

}

int main()

{

ll t;

cin>>t;

while(t--) 	solve();

return 0;

}

Answer: 2


#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long
#define dbl double
#define yes cout << "YES\n"
#define no cout << "NO\n"
constexpr dbl PI = 3.14159265359;
constexpr ll mod = 1e9 + 7;

using namespace std;

void solve() {
    int n;
    cin >> n;

    int j = 0;
    vector<int> vec(n);
    for (int i = 0; i < n; ++i) {
        cin >> vec[i];
        if (i > 0 && vec[i] < vec[i - 1]) j = i;
    }
    if (j == 0) {
        cout << "YES\n";
        return;
    }

    for (int i = 0; i < j; ++i) {
        ll minN = min(vec[i], vec[i+1]);
        vec[i] -= minN;
        vec[i+1] -= minN;
    }

    cout << (is_sorted(vec.begin(), vec.end()) ? "YES" : "NO") << '\n';
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int t;
    cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}

#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long
#define dbl double
#define yes cout << "YES\n"
#define no cout << "NO\n"
constexpr dbl PI = 3.14159265359;
constexpr ll mod = 1e9 + 7;

using namespace std;

void solve() {
    int n;
    cin >> n;

    vector<int> vec(n);
    for (int i = 0; i < n; ++i) {
        cin >> vec[i];
    }

    if (vec[0] > vec[1]) {
        cout << "NO\n";
        return;
    }
    if (vec[n - 2] > vec[n - 1]) {
        cout << "NO\n";
        return;
    }
    cout << "YES\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int t;
    cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}

Answer: 1


#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    // freopen("TALENT.INP","r",stdin);
    // freopen("TALENT.OUT","w",stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll t;
    cin >> t;
    for(ll u=1;u<=t;u++)
    {
        ll n;
        cin >> n;
        ll a[n+1];
        for(ll i=1;i<=n;i++)
        {
            cin >> a[i];
        }
        bool check=false;
        for(ll i=1;i<n;i++)
        {
            if(a[i]>a[i+1])
            {
                check=true;
                break;
            }
            else
            {
                a[i+1]-=a[i];
                a[i]=0;
            }
        }
        if(check==true)
        {
            cout << "NO";
        }
        else
        {
            cout << "YES";
        }
        cout << '\n';
    }
    return 0;
}

#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    // freopen("TALENT.INP","r",stdin);
    // freopen("TALENT.OUT","w",stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll t;
    cin >> t;
    for(ll u=1;u<=t;u++)
    {
        ll n;
        cin >> n;
        ll a[n+1];
        ll maxA=0;
        ll minA=1e18;
        for(ll i=1;i<=n;i++)
        {
            cin >> a[i];
            maxA=max(maxA,a[i]);
            minA=min(minA,a[i]);
        }
        if(maxA==a[1] or minA==a[n])
        {
            cout << "NO";
        }
        else
        {
            cout << "YES";
        }
        cout << '\n';
    }
    return 0;
}

Answer: 1


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define DedSec ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define in(x,n) for(int i=0;i<(n);i++) cin>>(x)[i]
#define out(x,n) for(int z=0;z<(n);z++) cout<<(x)[z]<<" \n"[z==(n)-1]
#define clr(x) memset((x), 0, sizeof (x))
#define nom(x) ((x) - '0')
int dr[] = {-1,1,0,0, -1,-1,1, 1};
int dc[] = {0,0,1,-1, 1, -1, 1, -1};
template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template<typename T>
using multi_ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

void solve(){
    int n; cin >> n;
    vector<int>a(n); in(a, n);
    if(a[1] < a[0]) return cout << "NO\n", void();
    a[1] -= min(a[1], a[0]);
    for(int i = 2; i < n; i++){
        if(a[i] < a[i - 1]){
            return cout << "NO\n", void();
        }
        a[i] -= min(a[i], a[i - 1]);
    }
    cout << "YES\n";
}

int main(){
    DedSec
//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
    int t=1;
    cin>>t;
    while (t--) solve();
//    for(int i = 1; i <= t; i++) solve(i);
    return 0;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define DedSec ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define in(x,n) for(int i=0;i<(n);i++) cin>>(x)[i]
#define out(x,n) for(int z=0;z<(n);z++) cout<<(x)[z]<<" \n"[z==(n)-1]
#define clr(x) memset((x), 0, sizeof (x))
#define nom(x) ((x) - '0')
int dr[] = {-1,1,0,0, -1,-1,1, 1};
int dc[] = {0,0,1,-1, 1, -1, 1, -1};
template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template<typename T>
using multi_ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

void solve(){
    int n; cin >> n;
    vector<int>a(n); in(a, n);
    if(a[1] < a[0]) return cout << "NO\n", void();
    for(int i = 2; i < n; i++){
        if(a[i] < a[i - 1]){
            a[i - 1] -= min(a[i - 1], a[i - 2]);
            if(a[i] < a[i - 1]) return cout << "NO\n", void();
        }
    }
    cout << "YES\n";
}

int main(){
    DedSec
//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
    int t=1;
    cin>>t;
    while (t--) solve();
//    for(int i = 1; i <= t; i++) solve(i);
    return 0;
}

Answer: 1


#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];

  int last=0;

  int p=0;

  int ans=1;

  int gap;

  while(p<n){

    if(a[p]>=last){

      gap=a[p]-last;

      last=a[p];

    }

    else if(a[p]>=gap){

        last=gap;

        gap=a[p]-last;

    }

    else ans=0;

    p++;

  }

  cout<<(ans?"YES\n":"NO\n");

}

int main(){

  int t;

  cin>>t;

  while(t--) solve();

  return 0;

}

//#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];

//  int last=0;

//  int p=0;

//  int ans=1;

//  int gap;

//  while(p<n){

//    if(a[p]>=last){

//      gap=a[p]-last;

//      last=a[p];

//    }

//    else if(a[p]>=gap){

//        last=gap;

//        gap=a[p]-last;

//    }

//    else ans=0;

//    p++;

//  }

//  cout<<(ans?"YES\n":"NO\n");

//}

//int main(){

//  int t;

//  cin>>t;

//  while(t--) solve();

//  return 0;

//}

#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];

  int ans=1;

  vector<int>v;

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

    if(v.empty()){

      v.push_back(a[i]);

    }

    else if(a[i]>=v.back()){

      int t=a[i]-v.back();

      v.clear();

      v.push_back(t);

//      v.push_back(a[i]);

    }

  else ans=0;

//    else{

//      int tt=v.back()-v.front();

//      if(a[i]>=tt){

//        v.clear();

//        v.push_back(tt);

//        v.push_back(a[i]);

//      }

//      else{

//        ans=0;

//      }

//    }

  }

  cout<<(ans?"YES\n":"NO\n");

}

int main(){

  int t=1;

  cin>>t;

  while(t--) solve();

  return 0;

}

Answer: 2


#ifndef LOCAL
#pragma GCC optimize("O3")
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

const int inf = 1'000'000'007;
const ll llinf = 1'000'000'000'000'000'007LL;

void precalc() {

}

void solve() {
    int n;
    cin >> n;
    vector <int> arr(n);
    for (auto &i : arr) {
        cin >> i;
    }
    for (int i = 1; i < n; i++) {
        int val = min(arr[i], arr[i - 1]);
        arr[i] -= val;
        arr[i - 1] -= val;
    }
    for (int i = 1; i < n; i++) {
        if (arr[i] < arr[i - 1]) {
            cout << "NO";
            return;
        }
    }
    cout << "YES";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin.sync_with_stdio(false);
    cout.sync_with_stdio(false);
    srand(time(0));
    cout.precision(10);

#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    // freopen("fragmentation.in", "r", stdin);
    // freopen("fragmentation.out", "w", stdout);
#endif

    clock_t start_time = clock();
    precalc();
#ifdef LOCAL
    cerr << "Precalc spent " << 1.0 * (clock() - start_time) / CLOCKS_PER_SEC << " seconds\n";
#endif

    int tt = 1;
    cin >> tt;
    for (int i = 0; i < tt; i++) {
        start_time = clock();
        solve();
        cout << "\n";
#ifdef LOCAL
        cerr << "Testcase #" << i + 1 << " spent " << 1.0 * (clock() - start_time) / CLOCKS_PER_SEC << " seconds\n";
#endif
    }
    return 0;
}

#ifndef LOCAL
#pragma GCC optimize("O3")
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

const int inf = 1'000'000'007;
const ll llinf = 1'000'000'000'000'000'007LL;

void precalc() {

}

void solve() {
    int n;
    cin >> n;
    vector <int> arr(n);
    for (auto &i : arr) {
        cin >> i;
    }
    if (arr[0] > arr[1]) {
        cout << "NO";
        return;
    }
    for (int i = 1; i + 1 < n; i++) {
        if (arr[i] > arr[i + 1]) {
            arr[i] -= arr[i - 1];
        }
        if (arr[i] > arr[i + 1]) {
            cout << "NO";
            return;
        }
    }

    cout << "YES";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin.sync_with_stdio(false);
    cout.sync_with_stdio(false);
    srand(time(0));
    cout.precision(10);

#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    // freopen("fragmentation.in", "r", stdin);
    // freopen("fragmentation.out", "w", stdout);
#endif

    clock_t start_time = clock();
    precalc();
#ifdef LOCAL
    cerr << "Precalc spent " << 1.0 * (clock() - start_time) / CLOCKS_PER_SEC << " seconds\n";
#endif

    int tt = 1;
    cin >> tt;
    for (int i = 0; i < tt; i++) {
        start_time = clock();
        solve();
        cout << "\n";
#ifdef LOCAL
        cerr << "Testcase #" << i + 1 << " spent " << 1.0 * (clock() - start_time) / CLOCKS_PER_SEC << " seconds\n";
#endif
    }
    return 0;
}

Answer: 1


#include <bits/stdc++.h>

using namespace std;

// Header files, namespaces,

// macros as defined above

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

using ll = long long;

using ull = unsigned long long;

#define pb(v) push_back(v)

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

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

#define MSET(c, v) memset(c, v, sizeof(c))

#define debug(x) cout << #x << " is " << x << endl

const int NEGINF = 0xC0C0C0C0;

const int NULO = -1;

const double EPS = 1e-10;

const ll mod = 1e9 + 7;

const ll llInf = 4e17;

const int inf = 2e9;

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

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

template <typename T,typename U>

std::pair<T,U> operator+(const std::pair<T,U> & l,const std::pair<T,U> & r) {

return {l.first+r.first,l.second+r.second};

}

const int maxn = 2e5 + 100;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

int a[maxn];

void solveTestCase(int test) {

int n;

cin >> n;

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

cin >> a[i];

}

int last = a[n];

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

if(a[i] > last) {

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

cout << "NO" << endl;

return;

} else {

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

a[i] = 0;

//cout << a[i] << " " << a[i + 1] << endl;

}

}

}

cout << "YES" << endl;

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

//     cout << a[i] << " ";

// }

// cout << endl;

}

int main() {

ios::sync_with_stdio(false);

int test = 1;

cin >> test;

for (int t = 1; t <= test; t++) {

solveTestCase(t);

}

return 0;

}

#include <bits/stdc++.h>

using namespace std;

// Header files, namespaces,

// macros as defined above

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

using ll = long long;

using ull = unsigned long long;

#define pb(v) push_back(v)

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

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

#define MSET(c, v) memset(c, v, sizeof(c))

#define debug(x) cout << #x << " is " << x << endl

const int NEGINF = 0xC0C0C0C0;

const int NULO = -1;

const double EPS = 1e-10;

const ll mod = 1e9 + 7;

const ll llInf = 4e17;

const int inf = 2e9;

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

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

template <typename T,typename U>

std::pair<T,U> operator+(const std::pair<T,U> & l,const std::pair<T,U> & r) {

return {l.first+r.first,l.second+r.second};

}

const int maxn = 2e5 + 100;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

ll a[maxn];

void solveTestCase(int test) {

int n;

cin >> n;

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

cin >> a[i];

}

bool ok = true;

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

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

ok = false;

break;

} else {

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

a[i] = 0;

}

}

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

}

int main() {

ios::sync_with_stdio(false);

int test = 1;

cin >> test;

for (int t = 1; t <= test; t++) {

solveTestCase(t);

}

return 0;

}

Answer: 2


#include <bits/stdc++.h>

using namespace std;

#define int long long int

#define endl "\n"

#define fori(a, n) for(int i = a; i < n; i++)

#define vi vector<int>

void solve() {

	int n; cin >> n;

	vi a(n);

	for(auto &x : a) {

		cin >> x;

	}

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

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

			cout << "NO" << endl;

			return;

		}

	}

	cout << "YES" << endl;

	return;

}

signed main() {

	ios_base::sync_with_stdio(false);

	cin.tie(NULL); cout.tie(NULL);

	int t = 1;

	cin >> t;

	while(t--)

		solve();

	return 0;

}

#include <bits/stdc++.h>

using namespace std;

#define int long long int

#define endl "\n"

#define fori(a, n) for(int i = a; i < n; i++)

#define vi vector<int>

void solve() {

	int n; cin >> n;

	bool flag = true;

	deque<int> dq(n);

	for(auto &x : dq)

		cin >> x;

	while((int)dq.size() > 1) {

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

			flag = false;

			break;

		} else if(dq[0] < dq[1]) {

			dq[1] -= dq[0];

			dq.pop_front();

		} else {

			dq.pop_front();

			dq.pop_front();

		}

	}

	cout << (flag ? "YES" : "NO");

	cout << endl;

	return;

}

signed main() {

	ios_base::sync_with_stdio(false);

	cin.tie(NULL); cout.tie(NULL);

	int t = 1;

	cin >> t;

	while(t--)

		solve();

	return 0;

}

Answer: 2


#include <bits/stdc++.h>

using namespace std;

bool is(int * a, int n) {

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

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

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

a[i] = 0;

}

else {

return false;

}

}

return true;

}

int main() {

int t;

cin>>t;

while(t--) {

int n;

cin>>n;

int arr[n];

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

cin>>arr[i];

}

if(is(arr, n)) {

cout<<"yes";

}

else {

cout<<"no";

}

}

return 0;

}

#include <bits/stdc++.h>

using namespace std;

bool is(int * a, int n) {

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

if(a[i] <= a[i + 1]) {

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

a[i] = 0;

}

else {

return false;

}

}

return true;

}

int main() {

int t;

cin>>t;

while(t--) {

int n;

cin>>n;

int arr[n];

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

cin>>arr[i];

}

if(is(arr, n)) {

cout<<"yes";

}

else {

cout<<"no";

}

cout<<"\n";

}

return 0;

}

Answer: 2


#include "bits/stdc++.h"
using namespace std;
#include "vector"
#include "map"
#include "set"
#include "queue"
#include "stack"
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD 1000000007
#define MOD1 998244353
#define INF 1e18
#define nline "\n"
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ff first
#define ss second
#define PI 3.141592653589793238462
#define set_bits __builtin_popcountll
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
// typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update > pbds; // find_by_order, order_of_key

#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#else
#define debug(x)
#endif

void _print(ll t) {cerr << t;}
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(lld t) {cerr << t;}
void _print(double t) {cerr << t;}
void _print(ull t) {cerr << t;}

template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}

int main() {
fastio();
int tc;cin>>tc;
while(tc--){
 int n;cin>>n;
 vector<int> a(n);
 for(int i=0;i<n;i++)cin>>a[i];

 int f=1;

 for(int i=n-2;i>=0;i--){
    if(a[i]<=a[i+1])continue;
    if(i==0){
        f=0;break;
    }
    int t=min(a[i],a[i-1]);
    a[i-1]-=t;
    a[i]-=t;

    if(a[i-1]>a[i+1]){
        f=0;break;
    }
 }
 if(f)cout<<"YES"<<endl;
 else cout<<"NO"<<endl;
  }
}

#include "bits/stdc++.h"
using namespace std;
#include "vector"
#include "map"
#include "set"
#include "queue"
#include "stack"
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD 1000000007
#define MOD1 998244353
#define INF 1e18
#define nline "\n"
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ff first
#define ss second
#define PI 3.141592653589793238462
#define set_bits __builtin_popcountll
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
// typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update > pbds; // find_by_order, order_of_key

#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#else
#define debug(x)
#endif

void _print(ll t) {cerr << t;}
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(lld t) {cerr << t;}
void _print(double t) {cerr << t;}
void _print(ull t) {cerr << t;}

template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}

int main() {
fastio();
int tc;cin>>tc;
while(tc--){
 int n;cin>>n;
 vector<int> a(n);
 for(int i=0;i<n;i++)cin>>a[i];

int f=1;
for(int i=1;i<n;i++){
    if(a[i]<a[i-1])f=0;
}

if(f){
    cout<<"YES"<<endl;continue;
}
f=1;
for(int i=0;i<n-1;i++){
    if(a[i]<=a[i+1]){
        a[i+1]-=a[i];
    }
    else f=0;
}
if(f)cout<<"YES"<<endl;
else cout<<"NO"<<endl;
  }
}

Answer: 2


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(a) a.begin(), a.end()
typedef vector<ll> vll;
#define life ios_base::sync_with_stdio(false);
#define saver cin.tie(0);
#define f first
#define s second
#define nxt cout << endl;
const int mod = 1e9 + 7;
const int N = 1e5 + 10;
#define rep(i, a, b) for (int(i) = (a); (i) < (b); ++(i))
#define rep0(i, a) rep(i, 0, a)
#define pb push_back

int main()
{
    life saver int t;
    cin >> t;
    while (t--)
    {

        int n;
        cin >> n;
        vll a(n);
        rep0(i, n)
        {
            cin >> a[i];
        }

        if (a[0] >= a[1])
        {
            cout << "NO" << endl;
        }
        else
        {
            cout << "YES" << endl;
        }
    }

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(a) a.begin(), a.end()
typedef vector<ll> vll;
#define life ios_base::sync_with_stdio(false);
#define saver cin.tie(0);
#define f first
#define s second
#define nxt cout << endl;
const int mod = 1e9 + 7;
const int N = 1e5 + 10;
#define rep(i, a, b) for (int(i) = (a); (i) < (b); ++(i))
#define rep0(i, a) rep(i, 0, a)
#define pb push_back

int main()
{
    life saver int t;
    cin >> t;
    while (t--)
    {

        int n;
        cin >> n;
        vll a(n);
        bool flag = true;
        rep0(i, n)
        {
            cin >> a[i];
        }

        ll d = a[0];
        rep(i, 1, n)
        {
            if (d > a[i])
            {
                flag = false;
                break;
            }
            else
            {
                d = a[i] - d;
            }
        }
        if (flag)
        {
            cout << "YES" << endl;
        }
        else
        {
            cout << "NO" << endl;
        }
    }

    return 0;
}

Answer: 2


# -*- 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 True:
        answer = 0
        for j in range(len(v)):
            if j < int(value)-1:
                answer = int(v[j+1]) - int(v[j])

        if answer >=0:
            ans.append("yes")

        else:
            ans.append("no")

for m in ans:
    print(m)

# -*- 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)

Answer: 2


#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#include <math.h>
#include <array>
#include <random>
#include <bitset>
#include <climits>
#include <cstring>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define endl '\n'
#define mod 1000000007
#define INF 0x3f3f3f3f

#pragma GCC optimize("O3,Ofast,unroll-loops")
#pragma GCC target("avx2,sse3,sse4,avx")
#pragma GCC target("popcnt")

template <class x>
using ordered_set = tree<x, null_type, less<x>, rb_tree_tag, tree_order_statistics_node_update>;

typedef pair<int, int> ipair;

static inline int read()
{
    int x = 0;char ch = getchar();
    while (ch < '0' || ch>'9') ch = getchar();
    while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
    return x;
}

static inline void print(const int &x) {
    if (x > 9)print(x / 10);
    putchar('0' + x % 10);
}

int main()
{
    cin.tie(0) -> sync_with_stdio(0);

    int t;

    cin >> t;

    while(t--)
    {
        int n;

        cin >> n;

        int list[n];
        for(int i = 0;i < n;cin >> list[i++]);

        for(int i = 1;i < n;i++)
        {
            int x = min(list[i], list[i-1]);

            list[i] -= x;
            list[i - 1] -= x;
        }

        bool f = 1;
        for(int i = 0;i < n;i++)
        {
            if(list[i] > list[i + 1]) f = 0;
        }

        cout << (f ? "YES\n" : "NO\n");
    }
}

#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#include <math.h>
#include <array>
#include <random>
#include <bitset>
#include <climits>
#include <cstring>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define endl '\n'
#define mod 1000000007
#define INF 0x3f3f3f3f

#pragma GCC optimize("O3,Ofast,unroll-loops")
#pragma GCC target("avx2,sse3,sse4,avx")
#pragma GCC target("popcnt")

template <class x>
using ordered_set = tree<x, null_type, less<x>, rb_tree_tag, tree_order_statistics_node_update>;

typedef pair<int, int> ipair;

static inline int read()
{
    int x = 0;char ch = getchar();
    while (ch < '0' || ch>'9') ch = getchar();
    while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
    return x;
}

static inline void print(const int &x) {
    if (x > 9)print(x / 10);
    putchar('0' + x % 10);
}

int main()
{
    cin.tie(0) -> sync_with_stdio(0);

    int t;

    cin >> t;

    while(t--)
    {
        int n;

        cin >> n;

        int list[n];
        for(int i = 0;i < n;cin >> list[i++]);

        for(int i = 1;i < n;i++)
        {
            int x = min(list[i], list[i-1]);

            list[i] -= x;
            list[i - 1] -= x;
        }

        bool f = 1;
        for(int i = 0;i < n-1;i++)
        {
            if(list[i] > list[i + 1]) f = 0;
        }

        cout << (f ? "YES\n" : "NO\n");
    }
}

Answer: 2


// Codeforces Round 998: Problem D

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define f first
#define s second

void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (auto &x : a) cin >> x;
    if (a[0] > a[1]) {
        cout << "NO\n";
        return;
    }
    for (int i = 1; i < n; i++) {
        if (a[i] > a[i - 1] && (i - 2 < 0 || a[i - 1] > a[i - 2])) {
            a[i] -= a[i - 1], a[i - 1] = 0;
        }
    }

    for (int i = 1; i < n; i++) {
        if (a[i] < a[i - 1]) {
            cout << "NO\n";
            return;
        }
    }

    cout << "YES\n";
}

int32_t main() {
    cin.tie(0)->sync_with_stdio(0);
    int t = 1;
    cin >> t;
    while (t--) solve();
}

// Codeforces Round 998: Problem D

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define f first
#define s second

void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (auto &x : a) cin >> x;
    if (a[0] > a[1]) {
        cout << "NO\n";
        return;
    }
    for (int i = 1; i < n; i++) {
        if (a[i] >= a[i - 1] && (i == 1 || a[i - 2] == 0)) {
            a[i] -= a[i - 1], a[i - 1] = 0;
        }
    }

    // for (auto x : a) cout << x << ' ';
    // cout << '\n';

    for (int i = 1; i < n; i++) {
        if (a[i] < a[i - 1]) {
            cout << "NO\n";
            return;
        }
    }

    cout << "YES\n";
}

int32_t main() {
    cin.tie(0)->sync_with_stdio(0);
    int t = 1;
    cin >> t;
    while (t--) solve();
}

Answer: 2


#include<bits/stdc++.h>

using namespace std;

void solve(){

int n;

cin>>n;

int arr[n];

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

cin>>arr[i];

}

int k=arr[0];

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

k=arr[i]-k;

if(k<0){ cout<<"no"<<endl;

return;

}

}

cout<<"yes"<<endl;

}

int main(){

int t;

cin>>t;

while(t--){

solve();

}

return 0;

}

#include<bits/stdc++.h>

using namespace std;

void solve(){

int n;

cin>>n;

int arr[n];

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

cin>>arr[i];

}

int k=arr[0];

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

k=arr[i]-k;

if(k<0){ cout<<"no"<<endl;

return;

}

}

cout<<"yes"<<endl;

}

int main(){

int t;

cin>>t;

while(t--){

solve();

}

return 0;

}

Answer: 2


#include <bits/stdc++.h>
using namespace std;
#define int long long
int power(int A, int expo)
{
    if (expo == 0)
        return 1;
    int res = power(A, expo / 2);
    if (expo % 2)
        return res * res * A;
    else
        return res * res;
}
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int factorial(int x)
{
    if (x == 1 || x == 0)
        return 1;
    return (x * factorial(x - 1));
}
class UnionFind{
    private: vector<int> parent,rank;
    public:
        UnionFind(int n){
            rank.assign(n,0);
            parent.assign(n,0);
            iota(parent.begin(),parent.end(),0);
        }
        int find(int x) {
            if(parent[x] == x)
                return x;

            return parent[x] = find(parent[x]);
        }

    void UnionSet(int x, int y) {
        int x_parent = find(x);
        int y_parent = find(y);

        if(rank[x_parent] > rank[y_parent]) {
            parent[y_parent] = x_parent;
        } else if(rank[x_parent] < rank[y_parent]) {
            parent[x_parent] = y_parent;
        } else {
            parent[x_parent] = y_parent;
            rank[y_parent]++;
        }
    }
};

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

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

void solve() {
  int n;
  cin>>n;
  vector<int> v(n);
  for(int i=0;i<n;i++){
    cin>>v[i];
  }
  for(int i=1;i<n;i++){
    int x=min(v[i],v[i-1]);
    v[i-1]-=x;
    v[i]-=x;
  }
  int cnt=0;
  for(int i=0;i<n;i++){
    if(v[i]>0) cnt++;
  }
  if(cnt>1){
    cout<<"No\n";
  }
  else{
    cout<<"Yes\n";
  }
}

signed main() {
#ifndef ONLINE_JUDGE
    freopen("input1.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
int power(int A, int expo)
{
    if (expo == 0)
        return 1;
    int res = power(A, expo / 2);
    if (expo % 2)
        return res * res * A;
    else
        return res * res;
}
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int factorial(int x)
{
    if (x == 1 || x == 0)
        return 1;
    return (x * factorial(x - 1));
}
class UnionFind{
    private: vector<int> parent,rank;
    public:
        UnionFind(int n){
            rank.assign(n,0);
            parent.assign(n,0);
            iota(parent.begin(),parent.end(),0);
        }
        int find(int x) {
            if(parent[x] == x)
                return x;

            return parent[x] = find(parent[x]);
        }

    void UnionSet(int x, int y) {
        int x_parent = find(x);
        int y_parent = find(y);

        if(rank[x_parent] > rank[y_parent]) {
            parent[y_parent] = x_parent;
        } else if(rank[x_parent] < rank[y_parent]) {
            parent[x_parent] = y_parent;
        } else {
            parent[x_parent] = y_parent;
            rank[y_parent]++;
        }
    }
};

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

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

void solve() {
  int n;
  cin>>n;
  vector<int> v(n);
  for(int i=0;i<n;i++){
    cin>>v[i];
  }
  for(int i=0;i<n-1;i++){
    int x=min(v[i],v[i+1]);
    v[i+1]-=x;
    v[i]-=x;
    if(v[i]>v[i+1]){
        cout<<"No\n";
        return;
    }
  }
 cout<<"Yes\n";
}

signed main() {
#ifndef ONLINE_JUDGE
    freopen("input1.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

Answer: 2


#include<bits/stdc++.h>

using namespace std;

int main(){

int t; cin>>t;

while(t--){

int n; cin>>n;

vector<int> v(n);

for(auto &i: v) cin>>i;

if(v[n-1]>v[n-2]) cout<<"YES"<<endl;

else cout<<"NO"<<endl;

}

}

#include<bits/stdc++.h>

using namespace std;

int main(){

long long t; cin>>t;

while(t--){

long long n; cin>>n;

vector<long long> v(n);

for(auto &i: v) cin>>i;

long long j = 0;

for(long long i = 1; i<n; i++){

if(v[i-1]>v[i]) j = i;

}

if(j == 0) cout<<"YES"<<endl;

else{

for(long long i = 0; i<j; i++){

long long temp = min(v[i], v[i+1]);

v[i] -= temp;

v[i+1] -= temp;

}

if(is_sorted(v.begin(), v.end())) cout<<"YES"<<endl;

else cout<<"NO"<<endl;

}

}

}

Answer: 2


#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#define fastio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define ll long long
#define pb push_back
#define eb emplace_back
#define endl '\n'

using namespace std;

const int MOD = 1000000007;

#ifdef KRISHNA
#include "handle_debug.hpp"
#define debug(...)                    \
    cout << '[';                      \
    debug_print(#_VA_ARGS, VA_ARGS_); \
    cout << "]\n";
#else
#define debug(...)
#endif

ll gcd(ll a, ll b)
{
    while (b)
    {
        ll t = a % b;
        a = b;
        b = t;
    }
    return a;
}

bool isPrime(ll n)
{
    if (n <= 1)
    {
        return false;
    }
    for (int i = 2; i <= sqrt(n); i++)
    {
        if (n % i == 0)
        {
            return false;
        }
    }
    return true;
}

int isSubstring(string s1, string s2)
{
    if (s2.find(s1) != string::npos)
        return s2.find(s1);
    return -1;
}

ll fac(ll n)
{
    ll f = 1;
    if (n == 0 || n == 1)
        return 1;
    else
    {
        for (ll i = 2; i <= n; i++)
        {
            f *= i;
        }
        return f;
    }
}

int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        vector<int> vec(n,0);
        for(int i=0; i<n; i++){
            cin>>vec[i];
        }
        int flag=1;
        for (int i = 0; i < n-1; i+=2)
        {
            if(vec[i+1]<vec[i]){
                flag=0;
                break;
            }
        }

        if(flag) cout<<"YES"<<endl;
        else{
            cout<<"NO"<<endl;
        }

    }
    return 0;
}

#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#define fastio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define ll long long
#define pb push_back
#define eb emplace_back
#define endl '\n'

using namespace std;

const int MOD = 1000000007;

#ifdef KRISHNA
#include "handle_debug.hpp"
#define debug(...)                    \
    cout << '[';                      \
    debug_print(#_VA_ARGS, VA_ARGS_); \
    cout << "]\n";
#else
#define debug(...)
#endif

ll gcd(ll a, ll b)
{
    while (b)
    {
        ll t = a % b;
        a = b;
        b = t;
    }
    return a;
}

bool isPrime(ll n)
{
    if (n <= 1)
    {
        return false;
    }
    for (int i = 2; i <= sqrt(n); i++)
    {
        if (n % i == 0)
        {
            return false;
        }
    }
    return true;
}

int isSubstring(string s1, string s2)
{
    if (s2.find(s1) != string::npos)
        return s2.find(s1);
    return -1;
}

ll fac(ll n)
{
    ll f = 1;
    if (n == 0 || n == 1)
        return 1;
    else
    {
        for (ll i = 2; i <= n; i++)
        {
            f *= i;
        }
        return f;
    }
}

int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        vector<int> vec(n,0);
        for(int i=0; i<n; i++){
            cin>>vec[i];
        }
        int flag=1;
        for (int i = 0; i < n-1; i++)
        {
           int k=min(vec[i], vec[i+1]);
           vec[i]=vec[i]-k;
           vec[i+1]=vec[i+1]-k;

           if(vec[i]>vec[i+1]){
            flag=0;
            break;
           }
        }

        if(flag) cout<<"YES"<<endl;
        else{
            cout<<"NO"<<endl;
        }

    }
    return 0;
}

Answer: 2


#include <iostream>
#include <vector>
#include <string>
#include<bits/stdc++.h>

using namespace std;
using ll = long long;

template<class T>
void cl(vector<T> &vec,ll a,ll b){
    ll min_ = min(vec[a],vec[b]);
    vec[a]-=min_;
    vec[b]-=min_;
};
template<class T>
void ret(vector<T> &vec1){
    // checker for sorted
    int is_sorted_ = 0;
    for(ll j = 0; j < vec1.size(); ++j){

        if(vec1[j]<=vec1[j + 1]){
            cl(vec1,j,j+1);
        }
    }

    cout << (is_sorted(ve.begin(), ve.end()) ? "YES" : "NO") << '\n';
}

int main(){
    cin.tie(nullptr) -> sync_with_stdio(false);
    ll n;
    cin >> n;

    for(ll s = 0; s < n; s++){
        ll sn;
        cin >> sn;
        vector<ll> vec(sn);
        for (ll &t : vec){
            cin >> t;
        }
        ret(vec);

    }
    return 0;

}

#include <iostream>
#include <vector>
#include <string>
#include<bits/stdc++.h>

using namespace std;
using ll = long long;

template<class T>
void cl(vector<T> &vec,ll a,ll b){
    ll min_ = min(vec[a],vec[b]);
    vec[a]-=min_;
    vec[b]-=min_;
}
template<class T>
void ret(vector<T> &vec1){
    // checker for sorted

    for(ll j = 0; j < vec1.size()-1; ++j){

        if(vec1[j]<=vec1[j + 1]){
            cl(vec1,j,j+1);
        }
    }

    cout << (is_sorted(vec1.begin(), vec1.end()) ? "YES" : "NO") << '\n';
}

int main(){
    cin.tie(nullptr) -> sync_with_stdio(false);
    ll n;
    cin >> n;

    for(ll s = 0; s < n; s++){
        ll sn;
        cin >> sn;
        vector<ll> vec(sn);
        for (ll &t : vec){
            cin >> t;
        }
        ret(vec);

    }
    return 0;

}

Answer: 2


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef double long dl;
typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update>
    ordered_set;

ll n,k;
string sa,sb;
vector<ll> a,p;
//vector<vector<ll>> ca;
ll mod = 1e9 + 7;
ll fact[200005];

ll powN(ll x, ll y);
ll getNcR(ll n, ll r);
ll ansSparseQuery(vector<vector<ll>>& sparseTable,int l, int r);
vector<vector<ll>> getSparseTable(vector<ll>& arr);
void initFact();
void initArr(vector<ll>& arr, ll n);

map<char,bool> mp;

bool solve()
{
    if(a[0] > a[1]) return false;
    ll x = 0;
    for(int i = 1; i<n; i++){
        ll mn = min(a[i],a[i-1]);
        a[i] -= mn;
        a[i-1] -= mn;
    }
    for(int i = 1; i<n; i++){
        if(a[i] < a[i-1]) return false;
    }
    return true;
}

int main()
{
    #ifndef ONLINE_JUDGE
       freopen("input.txt", "r", stdin);
       freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll ts;
    cin>>ts;
    //initFact();
    while(ts--)
    {
        cin>>n;
        initArr(a,n);
        //cin>>sa;
        //initArr(p,n-1);
        //initArr(c,n);
        cout<<(solve() ? "YES\n" : "NO\n");

        //cout<<solve()<< "\n";
        //solve();
    }

    return 0;
}

void initFact(){
    fact[0] = 1;
    for (int i = 1; i < 200005; i++) {
        fact[i] = (fact[i - 1] * i) % mod;
    }
}

void initArr(vector<ll>& arr, ll n){
    arr.clear();
    arr.resize(n);
    for(int i=0;i<n;i++) cin>>arr[i];
}

ll powN(ll x, ll y){
    ll res = 1;     // Initialize result

    x = x % mod; // Update x if it is more than or
                // equal to p

    if (x == 0) return 0; // In case x is divisible by p;

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % mod;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % mod;
    }
    return res;
}

ll getNcR(ll n, ll r)
{
    if(n < r) return 0;
	return (fact[n] * powN((fact[n - r] * fact[r]) % mod, mod - 2)) % mod;
}

ll ansSparseQuery(vector<vector<ll>>& sparseTable,int l, int r)
{
    int j = log2(r-l+1);

    return __gcd(sparseTable[l][j], sparseTable[r - (1<<j) + 1][j]);
}

vector<vector<ll>> getSparseTable(vector<ll>& arr)
{
    ll n = arr.size();
    if(n == 0) return {{}};
    vector<vector<ll>> sparseTable(n,vector<ll>(log2(n)+1));
    for(int i = 0; i<n; i++){
        sparseTable[i][0] = arr[i];
    }

    for(int j = 1; (1<<j) <= n; j++){
        for(int i = 0; i + (1<<j) <= n; i++){
            sparseTable[i][j] = __gcd(sparseTable[i][j-1],sparseTable[i + (1<<(j-1))][j-1]);
        }
    }
    return sparseTable;
}

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef double long dl;
typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update>
    ordered_set;

ll n,k;
string sa,sb;
vector<ll> a,p;
//vector<vector<ll>> ca;
ll mod = 1e9 + 7;
ll fact[200005];

ll powN(ll x, ll y);
ll getNcR(ll n, ll r);
ll ansSparseQuery(vector<vector<ll>>& sparseTable,int l, int r);
vector<vector<ll>> getSparseTable(vector<ll>& arr);
void initFact();
void initArr(vector<ll>& arr, ll n);

map<char,bool> mp;

bool solve()
{
    if(a[0] > a[1]) return false;
    ll x = 0;
    for(int i = 2; i<n; i++){
        if(a[i] < a[i-1]){
            a[i-1] -= min(a[i-2],a[i-1]);
            if(a[i] < a[i-1]) return false;
        }
    }
    return true;
}

int main()
{
    #ifndef ONLINE_JUDGE
       freopen("input.txt", "r", stdin);
       freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll ts;
    cin>>ts;
    //initFact();
    while(ts--)
    {
        cin>>n;
        initArr(a,n);
        //cin>>sa;
        //initArr(p,n-1);
        //initArr(c,n);
        cout<<(solve() ? "YES\n" : "NO\n");

        //cout<<solve()<< "\n";
        //solve();
    }

    return 0;
}

void initFact(){
    fact[0] = 1;
    for (int i = 1; i < 200005; i++) {
        fact[i] = (fact[i - 1] * i) % mod;
    }
}

void initArr(vector<ll>& arr, ll n){
    arr.clear();
    arr.resize(n);
    for(int i=0;i<n;i++) cin>>arr[i];
}

ll powN(ll x, ll y){
    ll res = 1;     // Initialize result

    x = x % mod; // Update x if it is more than or
                // equal to p

    if (x == 0) return 0; // In case x is divisible by p;

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % mod;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % mod;
    }
    return res;
}

ll getNcR(ll n, ll r)
{
    if(n < r) return 0;
	return (fact[n] * powN((fact[n - r] * fact[r]) % mod, mod - 2)) % mod;
}

ll ansSparseQuery(vector<vector<ll>>& sparseTable,int l, int r)
{
    int j = log2(r-l+1);

    return __gcd(sparseTable[l][j], sparseTable[r - (1<<j) + 1][j]);
}

vector<vector<ll>> getSparseTable(vector<ll>& arr)
{
    ll n = arr.size();
    if(n == 0) return {{}};
    vector<vector<ll>> sparseTable(n,vector<ll>(log2(n)+1));
    for(int i = 0; i<n; i++){
        sparseTable[i][0] = arr[i];
    }

    for(int j = 1; (1<<j) <= n; j++){
        for(int i = 0; i + (1<<j) <= n; i++){
            sparseTable[i][j] = __gcd(sparseTable[i][j-1],sparseTable[i + (1<<(j-1))][j-1]);
        }
    }
    return sparseTable;
}

Answer: 1


//~imran~

#include <bits/stdc++.h>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    long long t;
    cin>>t;
    while(t--){
       long long n,i,j;
        cin>>n;
        int arr[200005];
        for( i=0;i<n;i++){
            cin>>arr[i];
        }
        int x=0;
        for( j=0;j<n-1;j++){
               if( arr[j]>arr[j+1]) x=1;
               arr[j+1]-=arr[j];
            }
       if(x==0) cout << "YES\n";
        else cout<<"NO\n";
    }
    return 0;
}

//~imran~

#include <bits/stdc++.h>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        vector<int>v(n);
        for(int i=0;i<n;i++){
           cin>>v[i];
        }
        if (is_sorted(v.begin(), v.end())) {
            cout << "YES\n";
            continue;
        }
        int x=0,y=0;
        for(int j=0;j<n-1;j++){
               if( v[j]<y) x=1;
               y=v[j]-y;
            }
       if(x==0) cout << "YES\n";
        else cout<<"NO\n";
    }
    return 0;
}

Answer: 1


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

void solve() {
    ll n;
    cin >> n;
    vector <ll> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = n - 2; i > 0; i--){
        ll d = min(a[i], a[i-1]);
        if(d == 0) continue;
        ll k = (abs(a[i+1] - a[i]) + d - 1) / d;
        if(a[i] > a[i+1]){
            a[i] -= (k * d);
            a[i-1] -= (k * d);
            // cout << "k";
        }
        // cout << a[i] << " ";
    }
    bool ok = true;
    for(int i = 1; i < n; i++){
        // cout << a[i] << " ";
        if(a[i] < a[i-1]) ok = false;
    }
    if(ok) cout << "YES\n";
    else cout << "NO\n";
}

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int t = 1, st = clock();
    cin >> t;
    while(t--){
        solve();
    }
    // cerr << "[Time : " << 1000 * (clock() - st) / CLOCKS_PER_SEC << " ms]\n";
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

void solve() {
    ll n;
    cin >> n;
    vector <ll> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n - 1; i++){
        ll d = min(a[i], a[i+1]);
        a[i] -= d;
        a[i+1] -= d;
    }
    bool ok = true;
    for(int i = 1; i < n; i++){
        // cout << a[i] << " ";
        if(a[i] < a[i-1]) ok = false;
    }
    if(ok) cout << "YES\n";
    else cout << "NO\n";
}

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int t = 1, st = clock();
    cin >> t;
    while(t--){
        solve();
    }
    // cerr << "[Time : " << 1000 * (clock() - st) / CLOCKS_PER_SEC << " ms]\n";
    return 0;
}

Answer: 2


// Bluntforces ;)

#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
typedef long long int ll;

void solve() {
    int n; cin >>n;
    vector <int>a(n);
    for(int i=0;i<n;i++){
        cin >>a[i];
    }
    for(int i=0;i<n/2;i+=2){
        if(a[i] >a[i+1]){
            cout <<"NO"<<endl;

            return;
        }if(i>=(n/2)-1) continue;
        if(a[i] <a[i+1] && (a[i+1]-a[i]) > a[i+2]){
            cout <<"NO"<<endl;

            return;
        }
    }
    cout <<"YES"<<endl;
}

int main() {
    fast;
    ll t = 1;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
typedef long long int ll;

void solve() {
    int n;
    cin >> n;
    deque<int> a(n);
    for(int i=0;i<n;i++){
        cin >>a[i];
    }

  while(a.size()>1){
    if(a[0]>a[1]){
        cout <<"NO"<<endl;
        return;
    }else if(a[0]<a[1]){
        a[1]-=a[0];
        a.pop_front();
    }else{
        a.pop_front();
        a.pop_front();
    }
  }
  cout <<"YES"<<endl;
}

int main() {
    fast;
    ll t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

Answer: 2