ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2049C - MEX Cycle
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>

using namespace std;

const int N = 2e5+7;

int a[N];

int main(){

	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);

	int T;

	cin>>T;

	while(T--){

		int n,x,y;

		cin>>n>>x>>y;

		int m=y-x,flag=0;

		if (n%2==0){

			if (m%2){

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

					a[i]=flag;

					if (flag==0) flag=1;

					else flag=0;

				}

			} 

			else{

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

					a[i]=flag;

					if (flag==0) flag=1;

					else flag=0;

				}

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

					a[i]=flag;

					if (flag==0) flag=1;

					else flag=0;

				}

				a[y]=2;

			}

		}

		else{

			if (m%2){

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

					a[i]=flag;

					if (flag==0) flag=1;

					else flag=0;

				}

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

					a[i]=flag;

					if (flag==0) flag=1;

					else flag=0;

				}

				a[x-1]=2;

			}

			else{

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

					a[i]=flag;

					if (flag==0) flag=1;

					else flag=0;

				}

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

					a[i]=flag;

					if (flag==0) flag=1;

					else flag=0;

				}

				a[x-1]=2;

				a[y]=2;

			}

		}

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

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

		cout<<"\n";

	}

	return 0;

} 

Submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>

using namespace std;

const int N = 2e5+7;

int a[N];

int main(){

	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);

	int T;

	cin>>T;

	while(T--){

		int n,x,y;

		cin>>n>>x>>y;

		int m=y-x,flag=0;

		if (n%2==0){

			if (m%2){

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

					a[i]=flag;

					if (flag==0) flag=1;

					else flag=0;

				}

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

					a[i]=flag;

					if (flag==0) flag=1;

					else flag=0;

				}

			} 

			else{

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

					a[i]=flag;

					if (flag==0) flag=1;

					else flag=0;

				}

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

					a[i]=flag;

					if (flag==0) flag=1;

					else flag=0;

				}

				a[y]=2;

			}

		}

		else{

			if (m%2){

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

					a[i]=flag;

					if (flag==0) flag=1;

					else flag=0;

				}

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

					a[i]=flag;

					if (flag==0) flag=1;

					else flag=0;

				}

				if (x-1==0) a[n]=2;

				else a[x-1]=2;

			}

			else{

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

					a[i]=flag;

					if (flag==0) flag=1;

					else flag=0;

				}

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

					a[i]=flag;

					if (flag==0) flag=1;

					else flag=0;

				}

				if (x-1==0) a[n]=2;

				else a[x-1]=2;

				a[y]=2;

			}

		}

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

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

		cout<<"\n";

	}

	return 0;

}
Problem: 2049C - MEX Cycle
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>

using namespace std;

const int N = 2e5+7;

int a[N];

int main(){

	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);

	int T;

	cin>>T;

	while(T--){

		int n,x,y;

		cin>>n>>x>>y;

		int m=y-x,flag=0;

		if (n%2==0){

			if (m%2){

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

					a[i]=flag;

					if (flag==0) flag=1;

					else flag=0;

				}

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

					a[i]=flag;

					if (flag==0) flag=1;

					else flag=0;

				}

			} 

			else{

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

					a[i]=flag;

					if (flag==0) flag=1;

					else flag=0;

				}

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

					a[i]=flag;

					if (flag==0) flag=1;

					else flag=0;

				}

				a[y]=2;

			}

		}

		else{

			if (m%2){

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

					a[i]=flag;

					if (flag==0) flag=1;

					else flag=0;

				}

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

					a[i]=flag;

					if (flag==0) flag=1;

					else flag=0;

				}

				if (x-1==0) a[n]=2;

				else a[x-1]=2;

			}

			else{

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

					a[i]=flag;

					if (flag==0) flag=1;

					else flag=0;

				}

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

					a[i]=flag;

					if (flag==0) flag=1;

					else flag=0;

				}

				if (x-1==0) a[n]=2;

				else a[x-1]=2;

				a[y]=2;

			}

		}

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

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

		cout<<"\n";

	}

	return 0;

} 

Submission (verdict: Accepted):
#include<bits/stdc++.h>

using namespace std;

const int N = 2e5+7;

int a[N];

int main(){

	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);

	int T;

	cin>>T;

	while(T--){

		int n,x,y;

		cin>>n>>x>>y;

		int m=y-x,flag=0;

		if (n%2==0){

			if (m%2){

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

					a[i]=flag;

					if (flag==0) flag=1;

					else flag=0;

				}

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

					a[i]=flag;

					if (flag==0) flag=1;

					else flag=0;

				}

			} 

			else{

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

					a[i]=flag;

					if (flag==0) flag=1;

					else flag=0;

				}

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

					a[i]=flag;

					if (flag==0) flag=1;

					else flag=0;

				}

				a[y]=2;

			}

		}

		else{

			if (m%2){

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

					a[i]=flag;

					if (flag==0) flag=1;

					else flag=0;

				}

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

					a[i]=flag;

					if (flag==0) flag=1;

					else flag=0;

				}

				a[x]=2;

			}

			else{

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

					a[i]=flag;

					if (flag==0) flag=1;

					else flag=0;

				}

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

					a[i]=flag;

					if (flag==0) flag=1;

					else flag=0;

				}

				a[x]=2;

			}

		}

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

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

		cout<<"\n";

	}

	return 0;

}
Problem: 2049C - MEX Cycle
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>

using namespace std;

const int N = 2e5+7;

int a[N];

int main(){

	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);

	int T;

	cin>>T;

	while(T--){

		int n,x,y;

		cin>>n>>x>>y;

		int m=y-x;

		if (n%2==0){

			if (m%2){

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

					if (i%2) a[i]=0;

					else a[i]=1;

				}

			} 

			else{

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

					if (i%2) a[i]=0;

					else a[i]=1;

				}

				a[x]=2;

			}

		}

		else{

			if (m%2){

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

					if (i%2) a[i]=0;

					else a[i]=1;

				}

				a[n]=2;

			}

			else{

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

					if (i%2) a[i]=0;

					else a[i]=1;

				}

				a[n]=2;

				a[x]=2;

			}

		}

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

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

		cout<<"\n";

	}

	return 0;

}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 6):
#include <iostream>
#include<string>

using namespace std;

void solve(string&s){
    for(int i =0;i<s.length();i++){
             int k =0;
            int u = -1;
        for(int j = i+1;j<s.length();j++){
            if(s[j]!=0&&((s[j]-j+i)>s[i])){
                int maxi = s[j]-j+i;
                if(maxi>k){
                    k = max(k,maxi);
                    u = j;
                }
            }
        }
        s[u] = k;
        int l = u-1;
      while(l>=i){
          swap(s[l--],s[u--]);
      }
    }
}

int main(){ 
   int t;
cin>>t;
    while(t--){
   string s;
    cin>>s;
    solve(s);
    cout<<s<<endl;
    }
    return 0;
}

Submission (verdict: Wrong answer on test 1):
#include <iostream>
#include <string>
#include <deque>
using namespace std;

void solve(string &s) {
    int n = s.length();
    deque<int> candidates; // Store indices of potential candidates for swapping

    for (int i = n - 1; i > 0; i--) {
        // Only consider digits that can be decreased (not 0)
        if (s[i] > '0') {
            while (!candidates.empty() && s[candidates.back()] <= s[i]) {
                candidates.pop_back(); // Remove weaker candidates
            }
            candidates.push_back(i); // Add current digit as a candidate
        }

        // Check if there's a valid candidate to swap with the left neighbor
        if (!candidates.empty() && candidates.front() == i) {
            int j = i - 1; // Left neighbor
            if (s[i] - 1 > s[j]) {
                swap(s[i], s[j]);       // Perform the swap
                s[j] = s[j] - 1;       // Decrease the swapped digit
                candidates.pop_front(); // Remove the used candidate
            }
        }
    }
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        string s;
        cin >> s;
        solve(s);
        cout << s << endl;
    }
    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
#include <iostream>
#include <string>
#include <deque>
using namespace std;

void solve(string &s) {
    int n = s.length();
    deque<int> candidates; // Store indices of potential candidates for swapping

    for (int i = n - 1; i > 0; i--) {
        // Only consider digits that can be decreased (not 0)
        if (s[i] > '0') {
            while (!candidates.empty() && s[candidates.back()] <= s[i]) {
                candidates.pop_back(); // Remove weaker candidates
            }
            candidates.push_back(i); // Add current digit as a candidate
        }

        // Check if there's a valid candidate to swap with the left neighbor
        if (!candidates.empty() && candidates.front() == i) {
            int j = i - 1; // Left neighbor
            if (s[i] - 1 > s[j]) {
                swap(s[i], s[j]);       // Perform the swap
                s[j] = s[j] - 1;       // Decrease the swapped digit
                candidates.pop_front(); // Remove the used candidate
            }
        }
    }
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        string s;
        cin >> s;
        solve(s);
        cout << s << endl;
    }
    return 0;
}

Submission (verdict: Accepted):
#include <iostream>
#include <string>
using namespace std;

void solve(string &s) {
    bool swapped = true;
    while (swapped) {
        swapped = false;
        for (int i = 1; i < s.length(); i++) {
            if (s[i] > '0' && s[i] - 1 > s[i - 1]) {
                swap(s[i], s[i - 1]);   // Swap the current digit with the left neighbor
                s[i - 1]--;            // Decrease the digit that moved to the left
                swapped = true;        // Mark as swapped to continue processing
            }
        }
    }
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        string s;
        cin >> s;
        solve(s);
        cout << s << endl;
    }
    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)


Submission (verdict: Time limit exceeded on test 6):
#include <iostream>
#include<string>

using namespace std;

void solve(string&s){
    for(int i =0;i<s.length();i++){
             int k =0;
            int u = -1;
        for(int j = i+1;j<s.length();j++){
            if(s[j]!=0&&((s[j]-j+i)>s[i])){
                int maxi = s[j]-j+i;
                if(maxi>k){
                    k = max(k,maxi);
                    u = j;
                }
            }
        }
        s[u] = k;
        int l = u-1;
      while(l>=i){
          swap(s[l--],s[u--]);
      }
    }
}

int main(){ 
   int t;
cin>>t;
    while(t--){
   string s;
    cin>>s;
    solve(s);
    cout<<s<<endl;
    }
    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 3):
#include <cstdio>
#include <cstring>
#include<bits/stdc++.h>
using namespace std;

#define int long long
#define nl cout<<endl
#define vec vector<int>
#define vecs vector<string>
#define ddv vector<vec>
#define ub upper_bound 
#define lb lower_bound
#define prnt(v) for(auto i:v) cout<<i<<" "; nl
#define inp(v); for(auto &i:v) cin>>i;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define ppb pop_back
#define F first
#define S second
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl

const int N = 2e5;
const int M = 1e9+7;

int factorials[N+1];
int factInv[N+1];
bool isPrime[N+1];

int gcd(int a,int b){ //O(logb)
    if(!b) return a;
    return gcd(b,a%b);
}

int lcm(int a,int b){ //O(logb)
    return (a*b/gcd(a,b)) % M;
}

int binExp(long long a, int b) { //O(logb)
    a %= M;
    int ans = 1;
    while (b) {
        if (b & 1) ans = (ans * 1LL * a) % M;
        a = (a * 1LL * a) % M;
        b >>= 1;
    }
    return ans;
}

int inv(int n){ //O(logM)
    return binExp(n,M-2);
}

void FACT(){ //O(N)
    factorials[0] = 1;
    for (int i = 1; i <= N; i++) {
        factorials[i] = factorials[i - 1] * 1LL * i % M;
    }
}

void FACTINV(){ //O(N)
    for (int i = 0; i <= N; i++) {
        factInv[i] = inv(factorials[i]);
    }
}

void SIEVE(){ //O(NloglogN)

    //Pre-compute

    fill(isPrime, isPrime+N, true);
    isPrime[0]=isPrime[1]=false;

    for(int i = 2; i <= N; ++i){
        if(isPrime[i]){
            for(int j=2*i ; j<=N ; j+=i)
                isPrime[j]=false;
        }
    }
}

long long nCr(int n, int r){ //O(1) excl. Pre-Comp which is O(N).

    // Pre-Compute before using this func.
    // FACT();
    // FACTINV();

    if (r > n) return 0;
    return (factorials[n] * 1LL * factInv[r] % M * factInv[n - r] % M) % M;
}

void solve(){
    string s,ans="";
    cin>>s;
    int n = s.length();

    vector<bool> used(n,false);

    for(int i=0 ; i<n ; ){
        if(used[i]){
            ++i;
            continue;
        }

        int num = s[i]-'0';
        int numi = i;
        used[i] = true;
        ans.pb(s[i]);
        int bunk = 0;

        //
        // cout<<i<<endl;

        for(int j=i+1 ; j < min(i+10,n) ; ++j){
            if(used[j]){
                ++bunk;
                continue;
            }
            //
            // cout<<j<<endl;

            int trnum = s[j]-'0'-(j-i)+bunk;
            if(trnum > num){
                used[numi] = false;
                numi = j;
                num = trnum;
                ans.ppb();
                ans.pb(s[j]-(j-i)+bunk);
                used[numi] = true;
            }
        }

        //
        // cout<<ans<<endl;
        // prnt(used);

        if(numi == i) ++i;
    }

    cout<<ans<<endl;
}

int32_t main(){
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);

    // FACT();
    // FACTINV();
    // SIEVE();
    
    int t;
    cin>>t;
 
    while(t--){
        solve();
    }
 
    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 4):
#include <cstdio>
#include <cstring>
#include<bits/stdc++.h>
using namespace std;

#define int long long
#define nl cout<<endl
#define vec vector<int>
#define vecs vector<string>
#define ddv vector<vec>
#define ub upper_bound 
#define lb lower_bound
#define prnt(v) for(auto i:v) cout<<i<<" "; nl
#define inp(v); for(auto &i:v) cin>>i;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define ppb pop_back
#define F first
#define S second
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define pinp(a) for(int i=1;i<=n;++i) { int p; cin>>p; a[i] = p; }

const int N = 2e5;
const int M = 1e9+7;

int factorials[N+1];
int factInv[N+1];
bool isPrime[N+1];

int gcd(int a,int b){ //O(logb)
    if(!b) return a;
    return gcd(b,a%b);
}

int lcm(int a,int b){ //O(logb)
    return (a*b/gcd(a,b)) % M;
}

int binExp(long long a, int b) { //O(logb)
    a %= M;
    int ans = 1;
    while (b) {
        if (b & 1) ans = (ans * 1LL * a) % M;
        a = (a * 1LL * a) % M;
        b >>= 1;
    }
    return ans;
}

int inv(int n){ //O(logM)
    return binExp(n,M-2);
}

void FACT(){ //O(N)
    factorials[0] = 1;
    for (int i = 1; i <= N; i++) {
        factorials[i] = factorials[i - 1] * 1LL * i % M;
    }
}

void FACTINV(){ //O(N)
    for (int i = 0; i <= N; i++) {
        factInv[i] = inv(factorials[i]);
    }
}

void SIEVE(){ //O(NloglogN)

    //Pre-compute

    fill(isPrime, isPrime+N, true);
    isPrime[0]=isPrime[1]=false;

    for(int i = 2; i <= N; ++i){
        if(isPrime[i]){
            for(int j=2*i ; j<=N ; j+=i)
                isPrime[j]=false;
        }
    }
}

long long nCr(int n, int r){ //O(1) excl. Pre-Comp which is O(N).

    // Pre-Compute before using this func.
    // FACT();
    // FACTINV();

    if (r > n) return 0;
    return (factorials[n] * 1LL * factInv[r] % M * factInv[n - r] % M) % M;
}

void solve(){
    int n;
    cin>>n;
    vec a(n+1);
    pinp(a);

    vec vis(n+1,0);
    ddv ans;

    for(int i=n;i>0;--i){
        vis[a[i]] = 1;
        for(int j=a[i]+1;j<=n;++j){
            if(!vis[j]){
                ans.pb({j,a[i]});
            }
        }
    }

    for(int i=1;i<n;++i){
        if(a[i] < a[i+1]){
            ans.pb({a[i+1],a[i]});
            ans.pb({a[i],a[i+1]});
        }
    }

    cout<<ans.size()<<endl;
    for(auto i:ans){
        cout<<i[0]<<" "<<i[1]<<endl;
    }
}

int32_t main(){
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);

    // FACT();
    // FACTINV();
    // SIEVE();
    
    int t = 1;
    // cin>>t;
 
    while(t--){
        solve();
    }
 
    return 0;
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>

using namespace std; 

int main(){

	int t;

	cin>>t;

	while(t--){

		int n,l,r;

		cin>>n>>l>>r;

		int arr[n+1],brr[n+1];

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

			cin>>arr[i];

			brr[i]=arr[i];

		}

		sort(arr+l,arr+n+1);

		sort(brr+1,brr+r);

		int count=r-l;

		int sum1=0,sum2=0;

		for(int i=l;i<=l+count;i++){

			sum1+=arr[i];

		}

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

			sum2+=brr[i];

		}

		cout<<min(sum1,sum2)<<endl;

	}

	return 0;

}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>

using namespace std; 

int main(){

	int t;

	cin>>t;

	while(t--){

		int n,l,r;

		cin>>n>>l>>r;

		int arr[n+1],brr[n+1];

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

			cin>>arr[i];

			brr[i]=arr[i];

		}

		sort(arr+l,arr+n+1);

		sort(brr+1,brr+r);

		int count=r-l;

		int sum1=0,sum2=0;

		for(int i=l;i<=l+count;i++){

			sum1+=arr[i];

		}

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

			sum2+=brr[i];

		}

		cout<<min(sum1,sum2)<<endl;

	}

	return 0;

}

Submission (verdict: Wrong answer on test 8):
#include<bits/stdc++.h>

using namespace std; 

int main(){

	int t;

	cin>>t;

	while(t--){

		int n,l,r;

		cin>>n>>l>>r;

		int arr[n+1],brr[n+1];

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

			cin>>arr[i];

			brr[i]=arr[i];

		}

		sort(arr+l,arr+n+1);

		sort(brr+1,brr+r+1);

		int count=r-l;

		int sum1=0,sum2=0;

		for(int i=l;i<=l+count;i++){

			sum1+=arr[i];

		}

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

			sum2+=brr[i];

		}

		cout<<min(sum1,sum2)<<endl;

	}

	return 0;

}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 8):
#include<bits/stdc++.h>

using namespace std; 

int main(){

	int t;

	cin>>t;

	while(t--){

		int n,l,r;

		cin>>n>>l>>r;

		int arr[n+1],brr[n+1];

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

			cin>>arr[i];

			brr[i]=arr[i];

		}

		sort(arr+l,arr+n+1);

		sort(brr+1,brr+r+1);

		int count=r-l;

		int sum1=0,sum2=0;

		for(int i=l;i<=l+count;i++){

			sum1+=arr[i];

		}

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

			sum2+=brr[i];

		}

		cout<<min(sum1,sum2)<<endl;

	}

	return 0;

}

Submission (verdict: Accepted):
#include<bits/stdc++.h>

using namespace std; 

int main(){

	int t;

	cin>>t;

	while(t--){

		long long n,l,r;

		cin>>n>>l>>r;

		long long arr[n+1],brr[n+1];

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

			cin>>arr[i];

			brr[i]=arr[i];

		}

		sort(arr+l,arr+n+1);

		sort(brr+1,brr+r+1);

		long long count=r-l;

		long long sum1=0,sum2=0;

		for(int i=l;i<=l+count;i++){

			sum1+=arr[i];

		}

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

			sum2+=brr[i];

		}

		cout<<min(sum1,sum2)<<endl;

	}

	return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>



using namespace std;



typedef long long ll;

typedef vector<int> vi;

typedef vector<long long> vll;

typedef pair<int,int> pi;

#define pb push_back;

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

#define tc() int t; cin >> t; while(t--)

#define nl "\n";



void solve() {

    int n, flag = 1;

    cin >> n;

    vi v(n);

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

        cin >> v[i];

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

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

            flag = 0;

    if(flag) cout << "YES" << nl

    else cout << "NO" << nl



}



int main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    tc()

    solve();

    

    return 0;

}



Submission (verdict: Accepted):
#include <bits/stdc++.h>



using namespace std;



typedef long long ll;

typedef vector<int> vi;

typedef vector<long long> vll;

typedef pair<int,int> pi;

#define pb push_back;

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

#define tc() int t; cin >> t; while(t--)

#define nl "\n";



void solve() {

    int n, flag = 1;

    cin >> n;

    vi 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] -= x;

        v[i+1] -= x;

    }

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

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

            flag = 0;

            break;

        }

    }

        

    if(flag) cout << "YES" << nl

    else cout << "NO" << nl

}



int main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    tc()

    solve();

    

    return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>



using namespace std;



typedef long long ll;

typedef vector<int> vi;

typedef vector<long long> vll;

typedef pair<int,int> pi;

#define pb push_back;

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

#define tc() int t; cin >> t; while(t--)

#define nl "\n";



void solve() {

    int n, flag = 1;

    cin >> n;

    vi v(n);

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

        cin >> v[i];

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

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

            flag = 0;

    if(flag) cout << "YES" << nl

    else cout << "NO" << nl



}



int main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    tc()

    solve();

    

    return 0;

}



Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>



using namespace std;



typedef long long ll;

typedef vector<int> vi;

typedef vector<long long> vll;

typedef pair<int,int> pi;

#define pb push_back;

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

#define tc() int t; cin >> t; while(t--)

#define nl "\n";



void solve() {

    int n, flag = 1;

    cin >> n;

    vi v(n);

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

        cin >> v[i];

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

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

            flag = 0;

    if(flag) cout << "YES" << nl

    else cout << "NO" << nl



}



int main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    tc()

    solve();

    

    return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>



using namespace std;



typedef long long ll;

typedef vector<int> vi;

typedef vector<long long> vll;

typedef pair<int,int> pi;

#define pb push_back;

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

#define tc() int t; cin >> t; while(t--)

#define nl "\n";



void solve() {

    int n, flag = 1;

    cin >> n;

    vi v(n);

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

        cin >> v[i];

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

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

            flag = 0;

    if(flag) cout << "YES" << nl

    else cout << "NO" << nl



}



int main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    tc()

    solve();

    

    return 0;

}