ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2063B - Subsequence Update
Language: C++23 (GCC 14-64, msys2)

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

typedef long long ll;
typedef pair<ll, ll>PLL;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lowbit(ll x) { return x & -x; }

const int N = 1e6 + 10;
const int M = 5010;

ll t;

int main()
{
   cin>>t;
   while(t--) {
      ll n,l,r;
      cin>>n>>l>>r;
      vector<ll>a(n);
      for(ll i=0;i<n;i++) {
         cin>>a[i];
      }
      sort(a.begin(),a.end());
      ll sum=r-l+1;
      ll ans=0;
      for(ll i=0;i<sum;i++) {
         ans+=a[i];
      }
      cout<<ans<<endl;
   }

}


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

using namespace std;



typedef long long ll;

typedef pair<ll, ll>PLL;



ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll lowbit(ll x) { return x & -x; }



const int N = 1e6 + 10;

const int M = 5010;



ll t;



int main()

{

   cin>>t;

   while(t--) {

      ll n,l,r;

      cin>>n>>l>>r;

      vector<ll>a(n);

      vector<ll>b(n);

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

         cin>>a[i];

         b[i]=a[i];

      }

      sort(a.begin(),a.begin()+r);

      sort(b.begin()+l-1,b.begin()+n);



      ll sum1=0;

      ll sum2=0;

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

         sum1+=a[i];

      }

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

         sum2+=b[i];

      }

      ll ans=min(sum1,sum2);

      cout<<ans<<endl;

   }



}
Problem: 2057C - Trip to the Olympiad
Language: C++20 (GCC 13-64)

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

#define ll long long

string c(ll a) {
    if(a == 0) return "0";
    string ans = "";
    while(a) {
        ans += char('0' + (a & 1));
        a >>= 1;
    }
    reverse(ans.begin(), ans.end());
    return ans;
}


ll d(string s){
  
  ll j=0,ans=0;
  for(ll i=s.size()-1;i>=0;i--){
    if(s[i]=='1') ans+=pow(2,j);
    j++;
  }
  return ans;
}

void adarsh(){
    ll a,b;
    cin>>a>>b;
    string m1,m2;
    m1=c(a);
    m2=c(b);
    string a1="",a2="",a3="";
    if(m1.size()!=m2.size()){
      ll x = m2.size()-m1.size();
      while(x--) m1="0"+m1;
    }
    for(ll i=0;i<m1.size();i++){
      if(m1[i]==m2[i]){
        a1+=m1[i];
        a2+=m2[i];
        // a3+=m2[i];
      }
      else break;
    }
    ll x = m2.size()-a1.size();
    x--;
    a1+="1";
    a2+="0";
    a3+="0";
    while(x--){
      a1+="0";
      a2+="1";
      a3+="0";
    }
    ll ans1,ans2,ans3;
    ans1=d(a1);
    ans2=d(a2);
    // ans3=d(a3);
    if(ans2==a) ans3=a+1;
    else ans3=a;
    cout<<ans1<<" "<<ans2<<" "<<ans3<<endl;
}

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


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

#define ll long long

string c(ll a) {
    if(a == 0) return "0";
    string ans = "";
    while(a) {
        ans += char('0' + (a & 1));
        a >>= 1;
    }
    reverse(ans.begin(), ans.end());
    return ans;
}


ll d(string s){
  
  ll j=0,ans=0;
  for(ll i=s.size()-1;i>=0;i--){
    if(s[i]=='1') ans+=pow(2,j);
    j++;
  }
  return ans;
}

void adarsh(){
    ll a,b;
    cin>>a>>b;
    string m1,m2;
    m1=c(a);
    m2=c(b);
    string a1="",a2="",a3="";
    if(m1.size()!=m2.size()){
      ll x = m2.size()-m1.size();
      while(x--) m1="0"+m1;
    }
    for(ll i=0;i<m1.size();i++){
      if(m1[i]==m2[i]){
        a1+=m1[i];
        a2+=m2[i];
        // a3+=m2[i];
      }
      else break;
    }
    ll x = m2.size()-a1.size();
    x--;
    a1+="1";
    a2+="0";
    a3+="0";
    while(x--){
      a1+="0";
      a2+="1";
      a3+="0";
    }
    ll ans1,ans2,ans3;
    ans1=d(a1);
    ans2=d(a2);
    // ans3=d(a3);
    for(ll i=a;i<=b;i++){
      if(i!=ans2 and i!=ans1) {
        ans3=i; 
        break;
      }
    }
    else ans3=a;
    cout<<ans1<<" "<<ans2<<" "<<ans3<<endl;
}

int main(){
    ll t;
    cin >> t;
    while(t--){
        adarsh();
    }
    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++20 (GCC 13-64)

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

#define ll long long

string c(ll a) {
    if(a == 0) return "0";
    string ans = "";
    while(a) {
        ans += char('0' + (a & 1));
        a >>= 1;
    }
    reverse(ans.begin(), ans.end());
    return ans;
}


ll d(string s){
  
  ll j=0,ans=0;
  for(ll i=s.size()-1;i>=0;i--){
    if(s[i]=='1') ans+=pow(2,j);
    j++;
  }
  return ans;
}

void adarsh(){
    ll a,b;
    cin>>a>>b;
    string m1,m2;
    m1=c(a);
    m2=c(b);
    string a1="",a2="",a3="";
    if(m1.size()!=m2.size()){
      ll x = m2.size()-m1.size();
      while(x--) m1="0"+m1;
    }
    for(ll i=0;i<m1.size();i++){
      if(m1[i]==m2[i]){
        a1+=m1[i];
        a2+=m2[i];
        // a3+=m2[i];
      }
      else break;
    }
    ll x = m2.size()-a1.size();
    x--;
    a1+="1";
    a2+="0";
    a3+="0";
    while(x--){
      a1+="0";
      a2+="1";
      a3+="0";
    }
    ll ans1,ans2,ans3;
    ans1=d(a1);
    ans2=d(a2);
    // ans3=d(a3);
    ans3=a+1;
    cout<<ans1<<" "<<ans2<<" "<<ans3<<endl;
}

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


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

#define ll long long

string c(ll a) {
    if(a == 0) return "0";
    string ans = "";
    while(a) {
        ans += char('0' + (a & 1));
        a >>= 1;
    }
    reverse(ans.begin(), ans.end());
    return ans;
}


ll d(string s){
  
  ll j=0,ans=0;
  for(ll i=s.size()-1;i>=0;i--){
    if(s[i]=='1') ans+=pow(2,j);
    j++;
  }
  return ans;
}

void adarsh(){
    ll a,b;
    cin>>a>>b;
    string m1,m2;
    m1=c(a);
    m2=c(b);
    string a1="",a2="",a3="";
    if(m1.size()!=m2.size()){
      ll x = m2.size()-m1.size();
      while(x--) m1="0"+m1;
    }
    for(ll i=0;i<m1.size();i++){
      if(m1[i]==m2[i]){
        a1+=m1[i];
        a2+=m2[i];
        // a3+=m2[i];
      }
      else break;
    }
    ll x = m2.size()-a1.size();
    x--;
    a1+="1";
    a2+="0";
    a3+="0";
    while(x--){
      a1+="0";
      a2+="1";
      a3+="0";
    }
    ll ans1,ans2,ans3;
    ans1=d(a1);
    ans2=d(a2);
    // ans3=d(a3);
    if(ans2==a) ans3=a+1;
    else ans3=a;
    cout<<ans1<<" "<<ans2<<" "<<ans3<<endl;
}

int main(){
    ll t;
    cin >> t;
    while(t--){
        adarsh();
    }
    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++20 (GCC 13-64)

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

#define ll long long

string c(ll a) {
    if(a == 0) return "0";
    string ans = "";
    while(a) {
        ans += char('0' + (a & 1));
        a >>= 1;
    }
    reverse(ans.begin(), ans.end());
    return ans;
}


ll d(string s){
  
  ll j=0,ans=0;
  for(ll i=s.size()-1;i>=0;i--){
    if(s[i]=='1') ans+=pow(2,j);
    j++;
  }
  return ans;
}

void adarsh(){
    ll a,b;
    cin>>a>>b;
    string m1,m2;
    m1=c(a);
    m2=c(b);
    string a1="",a2="",a3="";
    if(m1.size()!=m2.size()){
      ll x = m2.size()-m1.size();
      while(x--) m1="0"+m1;
    }
    for(ll i=0;i<m1.size();i++){
      if(m1[i]==m2[i]){
        a1+=m1[i];
        a2+=m2[i];
        // a3+=m2[i];
      }
      else break;
    }
    ll x = m2.size()-a1.size();
    x--;
    a1+="1";
    a2+="0";
    a3+="0";
    while(x--){
      a1+="0";
      a2+="1";
      a3+="0";
    }
    ll ans1,ans2,ans3;
    ans1=d(a1);
    ans2=d(a2);
    // ans3=d(a3);
    for(ll i=a;i<=b;i++){
      if(i!=ans2 and i!=ans1) {
        ans3=i; 
        break;
      }
    }
    else ans3=a;
    cout<<ans1<<" "<<ans2<<" "<<ans3<<endl;
}

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


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll>PII;
typedef pair<ll, string>PIS;
const int N = 1e6 + 10;
const int MOD = 998244353;
const int INF = 0X3F3F3F3F;
const int dx[] = {-1, 1, 0, 0, -1, -1, +1, +1};
const int dy[] = {0, 0, -1, 1, -1, +1, -1, +1};
const int M = 1e9 + 7;

int main()
{
	int t;
	cin >> t;
	while(t --){
		ll l, r;
		cin >> l >> r;
        ll a = l, b = 0, c = r;
		for(ll i = 30; i >= 0; i --)
		{
		    ll o1 = (l >> i) & 1, o2 = (r >> i) & 1;
			if(o1 == o2 && (o1)) b |= (1 << i);
			else if(o1 != o2){
				b |= (1 << i);
				for(int j = i - 1; j >= 0; j --)
				{
					o1 = (l >> i) & 1, o2 = (r >> i) & 1;
					if(o1 != o2) continue;
					if(o1 & 1) continue;
					b |= (1 << j);
				}
				break;
			}
		}
		if(b != c) 
		cout << a << ' ' << b << ' ' << c << endl;
		else 
		cout << a << ' ' << b - 1 << ' ' << c << endl;
	}
	return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++20 (GCC 13-64)


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

#define ll long long

string c(ll a) {
    if(a == 0) return "0";
    string ans = "";
    while(a) {
        ans += char('0' + (a & 1));
        a >>= 1;
    }
    reverse(ans.begin(), ans.end());
    return ans;
}


ll d(string s){
  
  ll j=0,ans=0;
  for(ll i=s.size()-1;i>=0;i--){
    if(s[i]=='1') ans+=pow(2,j);
    j++;
  }
  return ans;
}

void adarsh(){
    ll a,b;
    cin>>a>>b;
    string m1,m2;
    m1=c(a);
    m2=c(b);
    string a1="",a2="",a3="";
    if(m1.size()!=m2.size()){
      ll x = m2.size()-m1.size();
      while(x--) m1="0"+m1;
    }
    for(ll i=0;i<m1.size();i++){
      if(m1[i]==m2[i]){
        a1+=m1[i];
        a2+=m2[i];
        // a3+=m2[i];
      }
      else break;
    }
    ll x = m2.size()-a1.size();
    x--;
    a1+="1";
    a2+="0";
    a3+="0";
    while(x--){
      a1+="0";
      a2+="1";
      a3+="0";
    }
    ll ans1,ans2,ans3;
    ans1=d(a1);
    ans2=d(a2);
    // ans3=d(a3);
    ans3=a+1;
    cout<<ans1<<" "<<ans2<<" "<<ans3<<endl;
}

int main(){
    ll t;
    cin >> t;
    while(t--){
        adarsh();
    }
    return 0;
}
Problem: 2057B - Gorilla and the Exam
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,k;
    cin>>n>>k;
    vector<int>b(n),cnt;
    for(int i=0;i<n;i++)cin>>b[i];
    sort(b.begin(),b.end());
    cnt.push_back(1);
    for(int i=1;i<n;i++){
        if(b[i]==b[i-1]){
            cnt.back()++;
        }else{
            cnt.push_back(1);
        }
    }
    sort(cnt.begin(),cnt.end());
    int ans=0,nn=cnt.size();
    for(int i=0;i<nn;i++){
        if(cnt[i]<=k){
            k-=cnt[i];
        }else{
            ans++;
        }
    }
    cout<<ans<<endl;
    return;
}
signed 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,k;
    cin>>n>>k;
    vector<int>b(n),cnt;
    for(int i=0;i<n;i++)cin>>b[i];
    sort(b.begin(),b.end());
    cnt.push_back(1);
    for(int i=1;i<n;i++){
        if(b[i]==b[i-1]){
            cnt.back()++;
        }else{
            cnt.push_back(1);
        }
    }
    sort(cnt.begin(),cnt.end());
    int ans=1,nn=cnt.size();
    for(int i=0;i<nn;i++){
        if(cnt[i]<=k){
            k-=cnt[i];
        }else{
            ans++;
        }
    }
    cout<<ans<<endl;
    return;
}
signed main(){
    int t;cin>>t;
    while(t--)solve();
    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)


Submission (verdict: Compilation error):
#include<bits/stdc++.h>
using namespace std;
void solve(){
    int n,k;
    cin>>n>>k;
    vector<int>b(n),cnt;
    for(int i=0;i<n;i++)cin>>b[i];
    sort(b.begin(),v.end());
    cnt.push_back(1);
    for(int i=1;i<n;i++){
        if(b[i]==b[i-1]){
            cnt.back()++;
        }else{
            cnt.push_back(1);
        }
    }
    sort(cnt.begin(),cnt.end());
    int ans=0;
    for(int i=0;i<cnt.size();i++){
        if(cnt[i]<=k){
            k-=cnt[i];
        }else{
            ans++;
        }
    }
    cout<<ans<<endl;
    return;
}
signed main(){
    int t;cin>>t;
    while(t--)solve();
    return 0;
}
Problem: 2057B - Gorilla and the Exam
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,k;
    cin>>n>>k;
    vector<int>b(n),cnt;
    for(int i=0;i<n;i++)cin>>b[i];
    sort(b.begin(),b.end());
    cnt.push_back(1);
    for(int i=1;i<n;i++){
        if(b[i]==b[i-1]){
            cnt.back()++;
        }else{
            cnt.push_back(1);
        }
    }
    sort(cnt.begin(),cnt.end());
    int ans=1,nn=cnt.size();
    for(int i=0;i<nn;i++){
        if(cnt[i]<=k){
            k-=cnt[i];
        }else{
            ans++;
        }
    }
    cout<<ans<<endl;
    return;
}
signed main(){
    int t;cin>>t;
    while(t--)solve();
    return 0;
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
void solve(){
    int n,k;
    cin>>n>>k;
    vector<int>b(n),cnt;
    for(int i=0;i<n;i++)cin>>b[i];
    sort(b.begin(),b.end());
    cnt.push_back(1);
    for(int i=1;i<n;i++){
        if(b[i]==b[i-1]){
            cnt.back()++;
        }else{
            cnt.push_back(1);
        }
    }
    sort(cnt.begin(),cnt.end());
    int nn=cnt.size();
    for(int i=0;i<nn-1;i++){
        if(cnt[i]>k){
             cout<<nn-i<<endl;
             return;
        } 
        k-=cnt[i];
    }
    cout<<1<<endl;
    return;
}
signed main(){
    int t;cin>>t;
    while(t--)solve();
    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

Previous submission (verdict: Compilation error):
#include<bits/stdc++.h>
using namespace std;
void solve(){
    int n,k;
    cin>>n>>k;
    vector<int>b(n),cnt;
    for(int i=0;i<n;i++)cin>>b[i];
    sort(b.begin(),v.end());
    cnt.push_back(1);
    for(int i=1;i<n;i++){
        if(b[i]==b[i-1]){
            cnt.back()++;
        }else{
            cnt.push_back(1);
        }
    }
    sort(cnt.begin(),cnt.end());
    int ans=0;
    for(int i=0;i<cnt.size();i++){
        if(cnt[i]<=k){
            k-=cnt[i];
        }else{
            ans++;
        }
    }
    cout<<ans<<endl;
    return;
}
signed 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,k;
    cin>>n>>k;
    vector<int>b(n),cnt;
    for(int i=0;i<n;i++)cin>>b[i];
    sort(b.begin(),b.end());
    cnt.push_back(1);
    for(int i=1;i<n;i++){
        if(b[i]==b[i-1]){
            cnt.back()++;
        }else{
            cnt.push_back(1);
        }
    }
    sort(cnt.begin(),cnt.end());
    int ans=0,nn=cnt.size();
    for(int i=0;i<nn;i++){
        if(cnt[i]<=k){
            k-=cnt[i];
        }else{
            ans++;
        }
    }
    cout<<ans<<endl;
    return;
}
signed main(){
    int t;cin>>t;
    while(t--)solve();
    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++17 (GCC 7-32)

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

void solve() {
    int n, m;
    cin >> n >> m;
    multiset<int> a, b;

    // Input sets
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        a.insert(x);
    }
    for (int i = 0; i < m; i++) {
        int y;
        cin >> y;
        b.insert(y);
    }

    // Process multisets
    while (!a.empty() && !b.empty()) {
        if (*a.begin() == *b.begin()) {
            // Erase the matching smallest elements
            a.erase(a.begin());
            b.erase(b.begin());
        } else if (a.size() > 1) {
            // Combine the two smallest elements in 'a'
            int first = *a.begin();
            a.erase(a.begin());
            int second = *a.begin();
            a.erase(a.begin());
            a.insert(first + second);

            // Check if the combination breaks the rules
            if (second - first > 1) {
                cout << "NO\n";
                return;
            }
        } else {
            // If 'a' cannot form valid pairs, break
            cout << "NO\n";
            return;
        }
    }

    // Check if either set is non-empty after processing
    if (!a.empty() || !b.empty()) {
        cout << "NO\n";
        return;
    }

    cout << "YES\n";
}

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


Submission (verdict: Time limit exceeded on test 1):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 998244353

void solve() {
    int n, m;
    cin >> n >> m;
    multiset<int> a, b;

    // Input sets
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        a.insert(x);
    }
    for (int i = 0; i < m; i++) {
        int y;
        cin >> y;
        b.insert(y);
    }

    // Process multisets
    while (!a.empty() && !b.empty()) {
        // Check if the largest elements are equal
        if (*a.rbegin() == *b.rbegin()) {
            a.erase(--a.end());  // Remove the largest element of a
            b.erase(--b.end());  // Remove the largest element of b
        } else if (*a.rbegin() < *b.rbegin()) {
            int lastele = *b.rbegin(); // Last element of b
            b.erase(--b.end());  // Remove the largest element of b

            // Split only if lastele > 1 to prevent infinite halving
            if (lastele > 1) {
                b.insert(lastele / 2);  // Insert first half
                b.insert((lastele + 1) / 2);  // Insert second half (to handle odd case)
            } else {
                cout << "NO\n";
                return;
            }
        } else {
            cout << "NO\n";
            return;
        }
    }

    // If one of the sets is non-empty, print "NO"
    if (!a.empty() || !b.empty()) {
        cout << "NO\n";
        return;
    }

    cout << "YES\n";
}

signed main() {
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++17 (GCC 7-32)


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

void solve() {
    int n, m;
    cin >> n >> m;
    multiset<int> a, b;

    // Input sets
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        a.insert(x);
    }
    for (int i = 0; i < m; i++) {
        int y;
        cin >> y;
        b.insert(y);
    }

    // Process multisets
    while (!a.empty() && !b.empty()) {
        if (*a.begin() == *b.begin()) {
            // Erase the matching smallest elements
            a.erase(a.begin());
            b.erase(b.begin());
        } else if (a.size() > 1) {
            // Combine the two smallest elements in 'a'
            int first = *a.begin();
            a.erase(a.begin());
            int second = *a.begin();
            a.erase(a.begin());
            a.insert(first + second);

            // Check if the combination breaks the rules
            if (second - first > 1) {
                cout << "NO\n";
                return;
            }
        } else {
            // If 'a' cannot form valid pairs, break
            cout << "NO\n";
            return;
        }
    }

    // Check if either set is non-empty after processing
    if (!a.empty() || !b.empty()) {
        cout << "NO\n";
        return;
    }

    cout << "YES\n";
}

signed main() {
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 1):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 998244353

void solve() {
    int n, m;
    cin >> n >> m;
    multiset<int> a, b;

    // Input sets
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        a.insert(x);
    }
    for (int i = 0; i < m; i++) {
        int y;
        cin >> y;
        b.insert(y);
    }

    // Process multisets
    while (!a.empty() && !b.empty()) {
        // Check if the largest elements are equal
        if (*a.rbegin() == *b.rbegin()) {
            a.erase(--a.end());  // Remove the largest element of a
            b.erase(--b.end());  // Remove the largest element of b
        } else if (*a.rbegin() < *b.rbegin()) {
            int lastele = *b.rbegin(); // Last element of b
            b.erase(--b.end());  // Remove the largest element of b

            // Split only if lastele > 1 to prevent infinite halving
            if (lastele > 1) {
                b.insert(lastele / 2);  // Insert first half
                b.insert((lastele + 1) / 2);  // Insert second half (to handle odd case)
            } else {
                cout << "NO\n";
                return;
            }
        } else {
            cout << "NO\n";
            return;
        }
    }

    // If one of the sets is non-empty, print "NO"
    if (!a.empty() || !b.empty()) {
        cout << "NO\n";
        return;
    }

    cout << "YES\n";
}

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


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

void solve() {
    int n, m;
    cin >> n >> m;
    
    priority_queue<int> a, b;
    
    // Input sets (pushing elements into max-heaps)
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        a.push(x);
    }
    
    for (int i = 0; i < m; i++) {
        int y;
        cin >> y;
        b.push(y);
    }
    int itr=n-m+1;
    // Process the heaps
    while (itr && !a.empty() && !b.empty()) {
        int top_a = a.top();
        int top_b = b.top();
        
        if (top_a == top_b) {
            // Remove both elements as they match
            a.pop();
            b.pop();
        } else if (top_a < top_b) {
            // Split the largest element from b
            b.pop();
            if (top_b > 1) {
                itr--;
                b.push(top_b / 2);
                b.push((top_b + 1) / 2);
            } else {
                cout << "NO\n";
                return;
            }
        } else {
            // If top_a > top_b, output NO
            cout << "NO\n";
            return;
        }
    }

    // If either heap is non-empty, print NO
    if (!a.empty() || !b.empty()) {
        cout << "NO\n";
        return;
    }

    cout << "YES\n";
}

signed main() {
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++20 (GCC 13-64)

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

int main(){
	int t; cin>>t;
	while(t--){
		string s; cin>>s;
		int x= s.size();
		s+= "&&&&&&&&&&";
		for(int i=0;i<(s.size()-i)/10*10;i++){
			for(int j=i+9;j>i;j--){
				if(s[j-1]<s[j]-1){
					swap(s[j-1],s[j]);
					s[j-1]=s[j-1]-1;
				}
			}
		}
		s.erase(s.size() - 10, 10);
		cout<<s<<endl;
	}
}

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

int main(){
	int t; cin>>t;
	while(t--){
		string s; cin>>s;
		int x= s.size();
		s+= "&&&&&&&&&&";
		for(int i=0;i<(s.size()-10);i++){
			for(int j=i+9;j>i;j--){
				if(s[j-1]<s[j]-1){
					swap(s[j-1],s[j]);
					s[j-1]=s[j-1]-1;
				}
			}
		}
		s.erase(s.size() - 10, 10);
		cout<<s<<endl;
	}
}