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

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

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

Code 1:
/*****************************************
备注：
******************************************/
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <climits>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define int ll
const int MAXN = 2e6 + 10;
const int MR = 10 + 5;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int _ = 0;
const bool debug = false;
#define check(x)cout << #x << "   ===   " << x << endl;

inline int read()
{
    int s = 0, f = 1;
    char x = getchar();
    while(x < '0' || x > '9')
    {
        if(x == '-')f = -1;
        x = getchar();
    }
    while(x >= '0' && x <= '9')
    {
        s = s * 10 + x - '0';
        x = getchar();
    }
    return s * f;
}

void print(int x)
{
    printf("%d", &x);
}
int n, a[MAXN];
void solve()
{
	cin >> n;
	for(int i = 1; i <= n; i++)cin >> a[i];
	for(int i = 1; i < n; i++)
	{
		int x = min(a[i], a[i + 1]);
		a[i] -= x, a[i + 1] -= x;
	}
	for(int i = 1; i <= n; i++)cout << a[i] << ' ';
	puts("");
	bool flag = true;
	for(int i = n; i >= 2; i--)
	{
		if(a[i] < a[i - 1])flag = false;
	}
	if(flag)puts("YES");
	else puts("NO");
}
signed main()
{
	// int start = clock();
	int T;cin >> T;
	while(T--)solve();
	// printf("%.3lf", clock() - start);
    return ~~(0^_^0);
}

Code 2:
/*****************************************
备注：
******************************************/
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <climits>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define int ll
const int MAXN = 2e6 + 10;
const int MR = 10 + 5;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int _ = 0;
const bool debug = false;
#define check(x)cout << #x << "   ===   " << x << endl;

inline int read()
{
    int s = 0, f = 1;
    char x = getchar();
    while(x < '0' || x > '9')
    {
        if(x == '-')f = -1;
        x = getchar();
    }
    while(x >= '0' && x <= '9')
    {
        s = s * 10 + x - '0';
        x = getchar();
    }
    return s * f;
}

void print(int x)
{
    printf("%d", &x);
}
int n, a[MAXN];
void solve()
{
	cin >> n;
	for(int i = 1; i <= n; i++)cin >> a[i];
	for(int i = 1; i < n; i++)
	{
		int x = min(a[i], a[i + 1]);
		a[i] -= x, a[i + 1] -= x;
	}
	bool flag = true;
	for(int i = n; i >= 2; i--)
	{
		if(a[i] < a[i - 1])flag = false;
	}
	if(flag)puts("YES");
	else puts("NO");
}
signed main()
{
	// int start = clock();
	int T;cin >> T;
	while(T--)solve();
	// printf("%.3lf", clock() - start);
    return ~~(0^_^0);
}

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

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;
        int a[n];
        for (int i = 0; i < n; i++)
        {
            cin >> a[i];
        }

        if (a[0] > a[1])
        {
            cout << "NO" << "\n";
            continue;
        }
        int flag = 0;
        for (int i = 0; i < n; i += 2)
        {
            if (a[i] >= a[i + 1])
            {
                flag = 1;
                break;
            }
        }

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

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;
        int a[n + 1];
        for (int i = 1; i <= n; i++)
        {
            cin >> a[i];
        }

        int mini;
        for (int i = 1; i < n; i++)
        {
            mini = min(a[i], a[i + 1]);
            a[i] -= mini;
            a[i + 1] -= mini;
        }
        int flag = 0;

        for (int i = 1; i < n; i++)
        {
            if (a[i] > a[i + 1])
            {
                flag = 1;
                break;
            }
        }

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

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;
    int arr[n];
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    for(int i=1;i<n;i++){
        int m = min(arr[i],arr[i-1]);
        arr[i]=arr[i]-m;
        arr[i-1] = arr[i-1]-m;
    }
    int b= 0;
    for(int i=0;i<n-1;i++){
        //cout<<arr[i]<<" ";
        if(arr[i]>arr[i+1]){
            b++;
        }
    }

    if(b!=0){
        cout<<"NO"<<endl;
    }else{

        cout<<"YES"<<endl;
    }
}
int main(){
    int t;
    cin>>t;
    while(t--){
        solve();
    }
}

Code 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];
    }
    if(arr[0]>=arr[1]){
        cout<<"NO"<<endl;
    }else{

        cout<<"YES"<<endl;
    }
}
int main(){
    int t;
    cin>>t;
    while(t--){
        solve();
    }
}

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

Code 1:
#include<iostream>
#include<vector>
#include<climits>

#define vi vector<int> 
#define vll vector<ll>  
#define ll long long   

using namespace std;
char ln = '\n';

void solve()
{
  int n ;cin >> n;
  vi a(n);
  for(int& i :a)
  {
    cin >> i;
  }
  for(int i = 0; i < n-1 ; i++)
  {
    if(a[i] > a[i+1] && i==0)
    {
      cout << "No" <<ln;
      return;
    }
    else
    {
      int minVal = min(a[i],a[i+1]);
      a[i+1] -=minVal;
      a[i] -=minVal;
    }
    
  }
   for(int i = 0 ; i < n ; i++)
  {
    cout <<a[i]<< " ";
    
  }
  cout<<ln;
  for(int i = 0 ; i < n-1; i++)
  {
    if(a[i] > a[i+1])
    {
      cout << "No" <<ln;
      return;
    }
  }
  cout << "Yes"<<ln;
}

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

Code 2:
#include<iostream>
#include<vector>
#include<climits>

#define vi vector<int> 
#define vll vector<ll>  
#define ll long long   

using namespace std;
char ln = '\n';

void solve()
{
  int n ;cin >> n;
  vi a(n);
  for(int& i :a)
  {
    cin >> i;
  }
  for(int i = 0; i < n-1 ; i++)
  {
    if(a[i] > a[i+1] && i==0)
    {
      cout << "No" <<ln;
      return;
    }
    else
    {
      int minVal = min(a[i],a[i+1]);
      a[i+1] -=minVal;
      a[i] -=minVal;
    }
    
  }
  for(int i = 0 ; i < n-1; i++)
  {
    if(a[i] > a[i+1])
    {
      cout << "No" <<ln;
      return;
    }
  }
  cout << "Yes"<<ln;
}

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;
#define ll long long
#define printarr(arr, n) for(int i=0; i<n; i++) cout<<arr[i]<<" ";
#define na cout << "NO" << endl;
#define ha cout << "YES" << endl;

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

            if(arr[i+1]<arr[i] || arr[i+1]<arr[i-1]) {
                isnd=0;
                break;
            }
        }
        if(n==2) {
            if(arr[0]>arr[1]) isnd=0;
        }

        if(isnd==1) ha
        else na

    }
}

Code 2:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define printarr(arr, n) for(int i=0; i<n; i++) cout<<arr[i]<<" ";
#define na cout << "NO" << endl;
#define ha cout << "YES" << endl;

int main() {
    int t;
    cin>>t;
    while(t--) {
        int n;
        cin>>n;
        vector<int> arr(n);
        for(int i=0; i<n; i++) {
            cin>>arr[i];
        }
        int isnd=1;
        for(int i=1; i<n-1; i++) {
            int minnum=min(arr[i],arr[i-1]);
            if(minnum!=arr[i-1]) {
                isnd=0;
                break;
            }
            arr[i]-=minnum;
            arr[i-1]-=minnum;

            if(arr[i+1]<arr[i] || arr[i+1]<arr[i-1] ) {
                isnd=0;
                break;
            }
        }
        if(n==2) {
            if(arr[0]>arr[1]) isnd=0;
        }

        if(isnd==1) ha
        else na

    }
}

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

Code 1:
#include<bits/stdc++.h>

using namespace std;

#define int long long 



void solve()

{

	int n;cin>>n;

	vector<int> a(n);

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

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

	{

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

		{

			cout<<"NO"<<endl;

			return ;

		}

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

	}

	cout<<"YES"<<endl;

}

signed main()

{

	ios::sync_with_stdio(false);

	cin.tie(nullptr);

	cout.tie(nullptr);

	int T;cin>>T;

	while(T--) solve();

	return 0;

}

Code 2:
#include<bits/stdc++.h>

using namespace std;

#define int long long 



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-1;i++)

	{

		if(a[i]>a[i+1]&&a[i+1]>a[i+2])

		{

			cout<<"NO"<<endl;

			return ;

		}

	}

	cout<<"YES"<<endl;

}

signed main()

{

	ios::sync_with_stdio(false);

	cin.tie(nullptr);

	cout.tie(nullptr);

	int T;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;
int t, a[200009], n;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    cin >> t;
    
    while(t--){
        cin >> n;
        for(int i = 0; i < n; i++){
            cin >> a[i];
        }
        for(int i = 0; i < n - 1; i++){
            int k = min(a[i], a[i + 1]);
            a[i] -= k;
            a[i + 1] -= k;
        }
        
        cout << (is_sorted(a, a + n) ? "YES\n" : "NO\n");
    }

    return 0;
}

Code 2:
#include <bits/stdc++.h>

using namespace std;


int main() {
   int t;
    cin >> t;
    
    while(t--){
        int n, p = 0;
        int a[n];
        cin >> n;
        
        for(int i = 0; i < n; i++){
            cin >> a[i];
        }
        
        for(int i = 0; i < n - 1; i++){
            int k = min(a[i], a[i + 1]);
            a[i] -= k;
            a[i + 1] -= k;
        }
        
        cout << (is_sorted(a, a + n) ? "YES\n" : "NO\n");
    }

    return 0;
}

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

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

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

Code 1:
#include <bits/stdc++.h>

using namespace std;



void minSub(int *arr, int i)

{

    int j = i;

    while (arr[j]>0 && j>0)

    {

        j--;

    }

    for (; j < i - 1; j++)

    {

        

        int mi = min(arr[j], arr[j + 1]);

            arr[j] = arr[j] - mi;

            arr[j + 1] = arr[j + 1] - mi;

    }

}

int main()

{

    ios_base::sync_with_stdio(false);

    cout.tie(NULL);

    cin.tie(NULL);

    int t;

    cin >> t;

    while (t--)

    {

        int n, i;

        cin >> n;



        int arr[n];



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

        {

            cin >> arr[j];

        }

            bool isPossible = true;

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

            {

                if(arr[i] > arr[i + 1])

                {

                    minSub(arr, i + 1);

                    if (arr[i] > arr[i + 1])

                    {

                        isPossible = false;

                        break;

                    }

                }

            }

            if (isPossible)

            {

                cout<< "YES"<<endl;

            }

            else

            {

                cout<< "NO"<<endl;

            }

    }

    return 0;

}

Code 2:
#include <bits/stdc++.h>

using namespace std;



void minSub(int *arr, int i)

{

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

    {

        if (arr[j]>0 && arr[j + 1]> 0 )

        {

            int mi = min(arr[j], arr[j + 1]);

            arr[j] = arr[j] - mi;

            arr[j + 1] = arr[j + 1] - mi;

        }

    }

}

int main()

{

    ios_base::sync_with_stdio(false);

    cout.tie(NULL);

    cin.tie(NULL);

    int t;

    cin >> t;

    while (t--)

    {

        int n, i;

        cin >> n;



        int arr[n];



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

        {

            cin >> arr[j];

        }

            bool isPossible = true;

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

            {

                if(arr[i] > arr[i + 1])

                {

                    minSub(arr, i + 1);

                    if (arr[i] > arr[i + 1])

                    {

                        isPossible = false;

                        break;

                    }

                }

            }

            if (isPossible)

            {

                cout<< "YES"<<endl;

            }

            else

            {

                cout<< "NO"<<endl;

            }

    }

    return 0;

}

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

Code 1:
#include <bits/stdc++.h>
using namespace std;
#define int long long


signed main() {
    ios::sync_with_stdio(false); cin.tie(0);

   int tt; cin >> tt;
   while(tt--){
       int n; cin >> n;
       vector<int> a (n);
       for(int i = 0; i < n; i++) cin >> a[i];
       string ans = "YES\n";
       for(int i = 1; i < n; i += 2){
           if(a[i] < a[i - 1]){
               ans = "NO\n";
               break;
           }
       }
       if(n % 2){
           if(a[n - 1] < a[n - 2] - a[n - 3]) ans = "NO\n";
       }
       cout << ans;
   }



    return 0;
}


Code 2:
#include <bits/stdc++.h>
using namespace std;
#define int long long


signed main() {
    ios::sync_with_stdio(false); cin.tie(0);

   int tt; cin >> tt;
   while(tt--){
       int n; cin >> n;
       vector<int> a (n);
       for(int i = 0; i < n; i++) cin >> a[i];
       for(int i = 1; i < n; i++){
           int mn = min(a[i] , a[i - 1]);
           a[i] -= mn;
           a[i - 1] -= mn;
       }
       
       if(is_sorted(a.begin() , a.end())) cout << "YES\n";
       else cout << "NO\n";
   }

    return 0;
}


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

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





    }

}

Code 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])) {

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

                answer = "NO"; break;

            }

        }



        cout << answer << "\n";





    }

}

Answer: 1
Problem: 2060D - Subtract Min Sort
Language: python

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

    for i in range(n-1):
        temp = min(a[i], a[i+1])
        a[i] -= temp
        a[i+1] -= temp

    possible = True
    for i in range(n-1):
        if a[i] > a[i+1]:
            possible = False
            break

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


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

    possible = True
    for i in range(n-1):
        if a[i] - a[i + 1] > 0 and i % 2 == 0:
           possible = False 
           break

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


Answer: 1
Problem: 2060D - Subtract Min Sort
Language: c++20 

Code 1:
#include <bits/stdc++.h>
#define no   "NO"
#define nl   "\n"
#define yes  "YES"
#define pb   push_back
#define ll   long long int
#define all(a)  sort(a.begin(),a.end())
#define allr(a) sort(a.rbegin(),a.rend())
#define rev(a)  reverse(a.begin(),a.end())
#define Code_By_exception ios::sync_with_stdio(false); cin.tie(0);
using namespace std;

void solution()
{
    ll n,tmp;
    cin>>n;
    vector<ll>v(n);
    for(ll i=0;i<n;i++) cin>>v[i];
    for(ll i=0;i<n-1;i++){
            tmp=v[i];
        if(v[i]==v[i+1])
            {
                v[i]-=tmp,v[i+1]-=tmp;
                ++i;
            }
        else if(v[i]>v[i+1]){
            cout<<no<<nl;
            return;
        }
        else{
            v[i]-=tmp;
            v[i+1]-=tmp;
        }
    }
    cout<<yes<<nl;
}
int main()
{
    Code_By_exception
    int tc;
    cin>>tc;
    while(tc--)
    {
        solution();
    }
    return 0;
}


Code 2:
#include <bits/stdc++.h>
#define no   "NO"
#define nl   "\n"
#define yes  "YES"
#define pb   push_back
#define ll   long long int
#define all(a)  sort(a.begin(),a.end())
#define allr(a) sort(a.rbegin(),a.rend())
#define rev(a)  reverse(a.begin(),a.end())
#define Code_By_exception ios::sync_with_stdio(false); cin.tie(0);
using namespace std;

void solution()
{
    int n;
    cin>>n;
    vector<ll>v(n);
    for(ll i=0;i<n;i++) cin>>v[i];
    int x=0;
    for(int i=1;i<n;i++){
        if(v[0]>=v[i])
            x++;
    }
    if(x==(n-1)){cout<<no<<nl;}
    else cout<<yes<<nl;
}
int main()
{
    Code_By_exception
    int tc;
    cin>>tc;
    while(tc--)
    {
        solution();
    }
    return 0;
}


Answer: 1
Problem: 2060D - Subtract Min Sort
Language: java

Code 1:
import java.util.*;
 
public class bit {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while (t-- > 0) {
            int n = sc.nextInt();
            int arr[] = new int[n];
            for(int i=0;i<n;i++){
                arr[i]=sc.nextInt();
            }
            String ans = "YES";
            if(arr[0]>arr[1]){
                System.out.println("NO");
                continue;
            }
            for(int i=0;i<n-1;i++){
                if(arr[i]>arr[i+1]){
                    System.out.println(i);
                    ans = "NO";
                    break;
                }else{
                    arr[i+1]-=arr[i];
                    arr[i]-=arr[i];
                }
            }
            System.out.println(ans);
            
        } 
    }
}




Code 2:
import java.util.*;
 
public class bit {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while (t-- > 0) {
            int n = sc.nextInt();
            int arr[] = new int[n];
            for(int i=0;i<n;i++){
                arr[i]=sc.nextInt();
            }
            String ans = "YES";
            if(arr[0]>arr[1]){
                System.out.println("NO");
                continue;
            }
            for(int i=0;i<n-1;i++){
                if(arr[i]>arr[i+1]){
                    ans = "NO";
                    break;
                }else{
                    arr[i+1]-=arr[i];
                    arr[i]-=arr[i];
                }
            }
            System.out.println(ans);
            
        } 
    }
}




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

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

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

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

    // Try to make the array non-decreasing using the subtraction operation
    for(int i = 0; i < n - 1; i++){
        int diff = min(arr[i], arr[i + 1]);
        arr[i] -= diff;
        arr[i + 1] -= diff;
    }

    // Check if the array is now sorted in non-decreasing order
    for(int i = 0; i < n - 1; i++){
        if(arr[i] > arr[i + 1]){
            cout << "No" << endl;
            return;
        }
    }
    
    cout << "Yes" << endl;
}

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

    while(t--){
        sub();
    }

    return 0;
}

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

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

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

    // Try to make the array non-decreasing using the subtraction operation
    for(int i = 0; i < n - 1; i++){
        int diff = min(arr[i], arr[i + 1]);
        arr[i] -= diff;
        arr[i + 1] -= diff;
    }

    // Check if the array is now sorted in non-decreasing order
    for(int i = 0; i < n - 1; i++){
        if(arr[i] > arr[i + 1]){
            cout << "No" << endl;
            return;
        }
    }
    
    cout << "Yes" << endl;
}

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

    while(t--){
        sub();
    }

    return 0;
}

Answer: 1