ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2060D - Subtract Min Sort
Language: c++23 

Code 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";
        }
    }
}

Code 2:
#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
Problem: 2060D - Subtract Min Sort
Language: c++17 

Code 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.
//



Code 2:
#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
Problem: 2060D - Subtract Min Sort
Language: python

Code 1:
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()


Code 2:
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
Problem: 2060D - Subtract Min Sort
Language: c++20 

Code 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;
}



Code 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;
}



Answer: 2
Problem: 2060D - Subtract Min Sort
Language: c++23 

Code 1:
#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;

}

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

}

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
Problem: 2060D - Subtract Min Sort
Language: python

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



Code 2:
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
Problem: 2060D - Subtract Min Sort
Language: c++17 

Code 1:
#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;
}

Code 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);
		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
Problem: 2060D - Subtract Min Sort
Language: c++17 

Code 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;

}

Code 2:
#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
Problem: 2060D - Subtract Min Sort
Language: python

Code 1:
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")

Code 2:
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
Problem: 2060D - Subtract Min Sort
Language: c++20 

Code 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;
    }
}

Code 2:
#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
Problem: 2060D - Subtract Min Sort
Language: c++23 

Code 1:
#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;

}

Code 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=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
Problem: 2060D - Subtract Min Sort
Language: c++20 

Code 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;
			}
		}
		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;
}



Code 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])
			{
				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
Problem: 2060D - Subtract Min Sort
Language: c++20 

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

}}

Code 2:
#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
Problem: 2060D - Subtract Min Sort
Language: c++23 

Code 1:
#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();

}



Code 2:
#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
Problem: 2060D - Subtract Min Sort
Language: c++17 

Code 1:
#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;
}

Code 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;

    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
Problem: 2060D - Subtract Min Sort
Language: c++23 

Code 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;
}

Code 2:
#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