ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2057C - Trip to the Olympiad
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
#define int long long int
using namespace std;

void solve() {
    int l,r;
    cin >> l >> r;
    int max_xor = LLONG_MIN;
    int x = -1;
    for(int i = l; i < r; i++){
        if(max_xor < (i ^ r)){
            max_xor = (i ^ r);
            x = i;
        }
    }
    if(x!=0)
    cout << r << " " << x << " " << x-1 << endl;
    else cout << r << " " << x << " " << x+1 << endl;

}

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

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("opp.txt", "w", stdout);
#endif

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

    return 0;
}


Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
#define int long long int
using namespace std;

void solve() {
    int l,r;
    cin >> l >> r;
    int a = 1 << (int)(log2(r)+0.5);
    int b = a-1;
    int c = a-2;
    cout << a << " " << b << " " << c << endl;


}

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

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("opp.txt", "w", stdout);
#endif

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

    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
#define int long long int
using namespace std;

void solve() {
    int l,r;
    cin >> l >> r;
    int a = 1 << (int)(log2(r)+0.5);
    int b = a-1;
    int c = a-2;
    cout << a << " " << b << " " << c << endl;


}

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

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("opp.txt", "w", stdout);
#endif

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

    return 0;
}


Submission (verdict: Accepted):
#include <bits/stdc++.h>
#define int long long int
using namespace std;

void solve() {
    int l,r;
    cin >> l >> r;
    int a = 0;
    for(int i = 31; i >= 0; i--){
        if(a > l) break;
        if(r & (1 << i)){
            a += (1 << i);
        }
    }
    int b = a - 1;
    int c = l;
    if(a != r) c = r;
    else if( b != l) c = l;
    else c = a-2;
    cout << a <<" " << b << " " << c << endl;
}

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

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("opp.txt", "w", stdout);
#endif

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

    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
#define int long long int
using namespace std;

void solve() {
    int l,r;
    cin >> l >> r;
    int max_xor = LLONG_MIN;
    int x = -1;
    for(int i = l; i < r; i++){
        if(max_xor < (i ^ r)){
            max_xor = (i ^ r);
            x = i;
        }
    }
    if(x!=0)
    cout << r << " " << x << " " << x-1 << endl;
    else cout << r << " " << x << " " << x+1 << endl;

}

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

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("opp.txt", "w", stdout);
#endif

    int t;
    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>

#include<vector>

using namespace std;

int main() {

    int t;

    cin>>t;

    while(t--){

        int n,l,r;

        cin>>n>>l>>r;

        vector<int> arr(n);

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

            cin>>arr[i];

        }

        sort(arr.begin(),arr.end());

        

        long long sum=0;

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

            sum+=arr[i];

        }

        cout<<sum<<endl;

    }

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

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
#include<vector>
using namespace std;
int main() {
    int t;
    cin>>t;
    while(t--){
        int n,l,r;
        cin>>n>>l>>r;
        vector<int> arr(n);
        for(int i=0;i<n;i++){
            cin>>arr[i];
        }
        vector<int> brr;
        for(int i=l-1;i<n;i++){
            brr.push_back(arr[i]);
        }
        sort(brr.begin(),brr.end());
        vector<int> crr;
        for(int i=0;i<l;i++){
            crr.push_back(arr[i]);
        }
        for(int i=0;i<crr.size();i++){
            cout<<crr[i]<<" ";
        }
        sort(crr.begin(),crr.end());
        long long sum=0;
        for(int i=0;i<r-l+1;i++){
            sum+=brr[i];
        }
        cout<<sum<<endl;
        long long sum2=0;
        for(int i=0;i<r-l+1;i++){
            sum2+=crr[i];
        }
        cout<<min(sum,sum2)<<endl;
    }
}

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

#include<vector>

using namespace std;

int main() {

    int t;

    cin>>t;

    while(t--){

        int n,l,r;

        cin>>n>>l>>r;

        vector<int> arr(n);

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

            cin>>arr[i];

        }

        vector<int> brr;

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

            brr.push_back(arr[i]);

        }

        sort(brr.begin(),brr.end());

        vector<int> crr;

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

            crr.push_back(arr[i]);

        }

        sort(crr.begin(),crr.end());

        long long sum=0;

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

            sum+=brr[i];

        }

        long long sum2=0;

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

            sum2+=crr[i];

        }

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

    }

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

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

#include<vector>

using namespace std;

int main() {

    int t;

    cin>>t;

    while(t--){

        int n,l,r;

        cin>>n>>l>>r;

        vector<int> arr(n);

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

            cin>>arr[i];

        }

        sort(arr.begin(),arr.end());

        

        long long sum=0;

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

            sum+=arr[i];

        }

        cout<<sum<<endl;

    }

}

Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
#include<vector>
using namespace std;
int main() {
    int t;
    cin>>t;
    while(t--){
        int n,l,r;
        cin>>n>>l>>r;
        vector<int> arr(n);
        for(int i=0;i<n;i++){
            cin>>arr[i];
        }
        vector<int> brr;
        for(int i=l-1;i<n;i++){
            brr.push_back(arr[i]);
        }
        sort(brr.begin(),brr.end());
        vector<int> crr;
        for(int i=0;i<l;i++){
            crr.push_back(arr[i]);
        }
        for(int i=0;i<crr.size();i++){
            cout<<crr[i]<<" ";
        }
        sort(crr.begin(),crr.end());
        long long sum=0;
        for(int i=0;i<r-l+1;i++){
            sum+=brr[i];
        }
        cout<<sum<<endl;
        long long sum2=0;
        for(int i=0;i<r-l+1;i++){
            sum2+=crr[i];
        }
        cout<<min(sum,sum2)<<endl;
    }
}
Problem: 2057B - Gorilla and the Exam
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Time limit exceeded on test 11):
#include<bits/stdc++.h>
#define int long long
using namespace std;
unordered_map<int,int>mp;
vector<int>num;
int n,m,idt,x;
void solve(){
	mp.clear();
	num.clear();
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%lld",&x);
		mp[x]++;
	}
	for(auto _:mp){
		num.push_back(_.second);
	}
	sort(num.begin(),num.end());
	// int ans=num.size();
	// for(auto i:num){
	// 	if(m<=0)break;
	// 	if(i<=m){	
	// 		m-=i;
	// 	}
	// 	ans--;
	// }
	// printf("%lld\n",max(ans,1ll));
	int s=num.size(),flag=0,k=m;
		for(int i=0;i<s;i++){
			if(k>=num[i]) k-=num[i];
			else{
				cout<<s-i<<endl;
				flag=1;
				break;
			}
		}
		if(!flag) cout<<1<<endl;
}
signed main(){
#ifdef USE_FILE_IO
	freopen("code.in","r",stdin);
	freopen("code.out","w",stdout);
#endif
	int t;
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

Submission (verdict: Time limit exceeded on test 11):
#include<bits/stdc++.h>
#define int long long
using namespace std;
unordered_map<int,int>mp;
vector<int>num;
int n,m,idt,x;
void solve(){
	mp.clear();
	num.clear();
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%lld",&x);
		mp[x]++;
	}
	for(auto _:mp){
		num.push_back(_.second);
	}
	sort(num.begin(),num.end());
	// int ans=num.size();
	// for(auto i:num){
	// 	if(m<=0)break;
	// 	if(i<=m){	
	// 		m-=i;
	// 	}
	// 	ans--;
	// }
	// printf("%lld\n",max(ans,1ll));
	bool flag=false;
	int s=num.size();
	for(int i=0;i<s;i++){
		if(m>=num[i])
			m-=num[i];
		else{
			printf("%lld\n",s-i);
			flag=true;
			break;
		}
	}
	if(!flag){
		printf("1\n");
	}
}
signed main(){
#ifdef USE_FILE_IO
	freopen("code.in","r",stdin);
	freopen("code.out","w",stdout);
#endif
	int t;
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Time limit exceeded on test 11):
#include<bits/stdc++.h>
#define int long long
using namespace std;
unordered_map<int,int>mp;
vector<int>num;
int n,m,idt,x;
void solve(){
	mp.clear();
	num.clear();
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%lld",&x);
		mp[x]++;
	}
	for(auto _:mp){
		num.push_back(_.second);
	}
	sort(num.begin(),num.end());
	// int ans=num.size();
	// for(auto i:num){
	// 	if(m<=0)break;
	// 	if(i<=m){	
	// 		m-=i;
	// 	}
	// 	ans--;
	// }
	// printf("%lld\n",max(ans,1ll));
	bool flag=false;
	int s=num.size();
	for(int i=0;i<s;i++){
		if(m>=num[i])
			m-=num[i];
		else{
			printf("%lld\n",s-i);
			flag=true;
			break;
		}
	}
	if(!flag){
		printf("1\n");
	}
}
signed main(){
#ifdef USE_FILE_IO
	freopen("code.in","r",stdin);
	freopen("code.out","w",stdout);
#endif
	int t;
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

Submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
#define int long long
using namespace std;
map<int,int>mp;
vector<int>num;
int n,m,idt,x;
void solve(){
	mp.clear();
	num.clear();
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%lld",&x);
		mp[x]++;
	}
	for(auto _:mp){
		num.push_back(_.second);
	}
	// sort(num.begin(),num.end());
	// int ans=num.size();
	// for(auto i:num){
	// 	if(m<=0)break;
	// 	if(i<=m){	
	// 		m-=i;
	// 	}
	// 	ans--;
	// }
	// printf("%lld\n",max(ans,1ll));
	bool flag=false;
	int s=num.size();
	for(int i=0;i<s;i++){
		if(m>=num[i])
			m-=num[i];
		else{
			printf("%lld\n",s-i);
			flag=true;
			break;
		}
	}
	if(!flag){
		printf("1\n");
	}
}
signed main(){
#ifdef USE_FILE_IO
	freopen("code.in","r",stdin);
	freopen("code.out","w",stdout);
#endif
	int t;
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Time limit exceeded on test 11):
#include<bits/stdc++.h>
#define int long long
using namespace std;
unordered_map<int,int>mp;
vector<int>num;
int n,m,idt,x;
void solve(){
	mp.clear();
	num.clear();
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%lld",&x);
		mp[x]++;
	}
	for(auto _:mp){
		num.push_back(_.second);
	}
	sort(num.begin(),num.end());
	// int ans=num.size();
	// for(auto i:num){
	// 	if(m<=0)break;
	// 	if(i<=m){	
	// 		m-=i;
	// 	}
	// 	ans--;
	// }
	// printf("%lld\n",max(ans,1ll));
	int s=num.size(),flag=0,k=m;
		for(int i=0;i<s;i++){
			if(k>=num[i]) k-=num[i];
			else{
				cout<<s-i<<endl;
				flag=1;
				break;
			}
		}
		if(!flag) cout<<1<<endl;
}
signed main(){
#ifdef USE_FILE_IO
	freopen("code.in","r",stdin);
	freopen("code.out","w",stdout);
#endif
	int t;
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
#define int long long
using namespace std;
map<int,int>mp;
vector<int>num;
int n,m,idt,x;
void solve(){
	mp.clear();
	num.clear();
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%lld",&x);
		mp[x]++;
	}
	for(auto _:mp){
		num.push_back(_.second);
	}
	// sort(num.begin(),num.end());
	// int ans=num.size();
	// for(auto i:num){
	// 	if(m<=0)break;
	// 	if(i<=m){	
	// 		m-=i;
	// 	}
	// 	ans--;
	// }
	// printf("%lld\n",max(ans,1ll));
	bool flag=false;
	int s=num.size();
	for(int i=0;i<s;i++){
		if(m>=num[i])
			m-=num[i];
		else{
			printf("%lld\n",s-i);
			flag=true;
			break;
		}
	}
	if(!flag){
		printf("1\n");
	}
}
signed main(){
#ifdef USE_FILE_IO
	freopen("code.in","r",stdin);
	freopen("code.out","w",stdout);
#endif
	int t;
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
#define int long long
using namespace std;
map<int,int>mp;
vector<int>num;
int n,m,idt,x;
void solve(){
	mp.clear();
	num.clear();
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%lld",&x);
		mp[x]++;
	}
	for(auto _:mp){
		num.push_back(_.second);
	}
	sort(num.begin(),num.end());
	// int ans=num.size();
	// for(auto i:num){
	// 	if(m<=0)break;
	// 	if(i<=m){	
	// 		m-=i;
	// 	}
	// 	ans--;
	// }
	// printf("%lld\n",max(ans,1ll));
	bool flag=false;
	int s=num.size();
	for(int i=0;i<s;i++){
		if(m>=num[i]){
			m-=num[i];
		}
		else{
			printf("%lld\n",s-i);
			flag=true;
			return;
		}
	}
	printf("1\n");
}
signed main(){
#ifdef USE_FILE_IO
	freopen("code.in","r",stdin);
	freopen("code.out","w",stdout);
#endif
	int t;
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 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;
using LL = long long;
const int mod = 1000000007;
int main(void) {
      ios_base :: sync_with_stdio(false);
      cin.tie(0); cout.tie(0);
      /*#ifndef ONLINE_JUDGE
            freopen("input.txt", "r", stdin);
            freopen("output.txt", "w", stdout);
      #endif*/
      int T = 1; cin >> T;
      for (int qq = 0; qq < T; qq++) {
            LL l, r; cin >> l >> r;
            LL a = 0, b = 0, c = 0, bit = 0;
            for (LL i = 30; i >= 0; i--) {
                  if ((r & (1LL << i)) != (l & (1LL << i))) {
                        a = a | (1LL << i);
                        bit = i; break;
                  } else if ((l & (1LL << i)) == 1) {
                        a = a | (1LL << i);
                        b = b | (1LL << i);
                  }
            }
            for (LL i = bit + 1; i >= 0; i--) {
                  b = b | (1LL << i);
            }
            for (LL i = l; i <= r; i++) {
                  if (i != a and i != b) {
                        c = i; break;
                  }
            }        
            cout << a << " " << b << " " << c << '\n';
      }	
      return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 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;
using LL = long long;
const int mod = 1000000007;
int main(void) {
      ios_base :: sync_with_stdio(false);
      cin.tie(0); cout.tie(0);
      /*#ifndef ONLINE_JUDGE
            freopen("input.txt", "r", stdin);
            freopen("output.txt", "w", stdout);
      #endif*/
      int T = 1; cin >> T;
      for (int qq = 0; qq < T; qq++) {
            LL l, r; cin >> l >> r;
            LL a = 0, b = 0, c = 0, bit = 0;
            for (LL i = 30; i >= 0; i--) {
                  if ((r & (1LL << i)) != (l & (1LL << i))) {
                        a = a | (1LL << i);
                        bit = i; break;
                  } else if ((l & (1LL << i)) == 1) {
                        a = a | (1LL << i);
                        b = b | (1LL << i);
                  }
            }
            for (LL i = bit + 1; i >= 0; i--) {
                  b = b | (1LL << i);
            }
            for (LL i = l; i <= r; i++) {
                  if (i != a and i != b) {
                        c = i; break;
                  }
            }        
            cout << a << " " << b << " " << c << '\n';
      }	
      return 0;
}


Submission (verdict: Wrong answer on test 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;
using LL = long long;
const int mod = 1000000007;
int main(void) {
      ios_base :: sync_with_stdio(false);
      cin.tie(0); cout.tie(0);
      /*#ifndef ONLINE_JUDGE
            freopen("input.txt", "r", stdin);
            freopen("output.txt", "w", stdout);
      #endif*/
      int T = 1; cin >> T;
      for (int qq = 0; qq < T; qq++) {
            LL l, r; cin >> l >> r;
            LL a = 0, b = 0, c = 0, bit = 0;
            for (LL i = 30; i >= 0; i--) {
                  if ((r & (1LL << i)) != (l & (1LL << i))) {
                        a = a | (1LL << i);
                        bit = i; break;
                  } else if ((l & (1LL << i)) == 1) {
                        a = a | (1LL << i);
                        b = b | (1LL << i);
                  }
            }
            for (LL i = bit - 1; i >= 0; i--) {
                  b = b | (1LL << i);
            }
            for (LL i = l; i <= r; i++) {
                  if (i != a and i != b) {
                        c = i; break;
                  }
            }        
            cout << a << " " << b << " " << c << '\n';
      }	
      return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 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;
using LL = long long;
const int mod = 1000000007;
int main(void) {
      ios_base :: sync_with_stdio(false);
      cin.tie(0); cout.tie(0);
      /*#ifndef ONLINE_JUDGE
            freopen("input.txt", "r", stdin);
            freopen("output.txt", "w", stdout);
      #endif*/
      int T = 1; cin >> T;
      for (int qq = 0; qq < T; qq++) {
            LL l, r; cin >> l >> r;
            LL a = 0, b = 0, c = 0, bit = 0;
            for (LL i = 30; i >= 0; i--) {
                  if ((r & (1LL << i)) != (l & (1LL << i))) {
                        a = a | (1LL << i);
                        bit = i; break;
                  } else if ((l & (1LL << i)) == 1) {
                        a = a | (1LL << i);
                        b = b | (1LL << i);
                  }
            }
            for (LL i = bit - 1; i >= 0; i--) {
                  b = b | (1LL << i);
            }
            for (LL i = l; i <= r; i++) {
                  if (i != a and i != b) {
                        c = i; break;
                  }
            }        
            cout << a << " " << b << " " << c << '\n';
      }	
      return 0;
}


Submission (verdict: Accepted):
#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;
using LL = long long;
const int mod = 1000000007;
int main(void) {
      ios_base :: sync_with_stdio(false);
      cin.tie(0); cout.tie(0);
      /*#ifndef ONLINE_JUDGE
            freopen("input.txt", "r", stdin);
            freopen("output.txt", "w", stdout);
      #endif*/
      int T = 1; cin >> T;
      for (int qq = 0; qq < T; qq++) {
            LL l, r; cin >> l >> r;
            LL a = 0, b = 0, c = 0, bit = 0;
            for (LL i = 30; i >= 0; i--) {
                  if (!!(r & (1LL << i)) != !!(l & (1LL << i))) {
                        a = a | (1LL << i);
                        bit = i; break;
                  } else if ((l & (1LL << i)) == (1LL << i)) {
                        a = a | (1LL << i);
                        b = b | (1LL << i);
                  }
            }
            for (LL i = bit - 1; i >= 0; i--) {
                  b = b | (1LL << i);
            }
            for (LL i = l; i <= r; i++) {
                  if (i != a and i != b) {
                        c = i; break;
                  }
            }        
            cout << a << " " << b << " " << c << '\n';
      }	
      return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 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 j = 1;
    bool possible = true;

    for (int i = 0; i < n - 1; i++) {
        if (j >= n) break;
        if (a[i] > a[j]) {
            a[i] = a[i] - a[j];
            a[j] = 0;
        } else {
            a[j] = a[j] - a[i];
            a[i] = 0;
        }
        j++;
    }

    for (int i = 0; i < n; i++) {
        if (a[i] != 0) {
            possible = false;
            break;
        }
    }

    cout << (possible ? "YES" : "NO") << endl;
}

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


Submission (verdict: Accepted):
#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 j = 1;
    bool possible = true;

    for (int i = 0; i < n - 1; i++) {
        if (j >= n) break;
        if (a[i] > a[j]) {
            a[i] = a[i] - a[j];
            a[j] = 0;
        } else {
            a[j] = a[j] - a[i];
            a[i] = 0;
        }
        j++;
    }

    for (int i = 0; i < n-1; i++) {
        if (a[i] != 0) {
            possible = false;
            break;
        }
    }

    cout << (possible ? "YES" : "NO") << endl;
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 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];
    }

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

    cout << "YES" << endl;
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 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];
    }

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

    cout << "YES" << endl;
}

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


Submission (verdict: Wrong answer on test 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 j = 1;
    bool possible = true;

    for (int i = 0; i < n - 1; i++) {
        if (j >= n) break;
        if (a[i] > a[j]) {
            a[i] = a[i] - a[j];
            a[j] = 0;
        } else {
            a[j] = a[j] - a[i];
            a[i] = 0;
        }
        j++;
    }

    for (int i = 0; i < n; i++) {
        if (a[i] != 0) {
            possible = false;
            break;
        }
    }

    cout << (possible ? "YES" : "NO") << endl;
}

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