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

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

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

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

}



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

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

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

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

}

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

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

}

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



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

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

}

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

}

cout<<"\n";

}

return 0;

}

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

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

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

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

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

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++17 

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

}

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;

}

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

}

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

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

}

}

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

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


}

Code 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

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

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

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

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

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