Problem: 2061D - Kevin and Numbers
Language: C++23 (GCC 14-64, msys2)

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

#define long long int;

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

    while(t--){
        int n, m;
        cin >> n >> m;

        if(n==1){
            cout << "No" << endl;
            continue;
        }

        vector<int> a(n), b(m);
        map<int,int> mpa, mpb;
        multiset<int, greater<int>> sta, stb;
        for(int i=0; i<n; i++){
            cin >> a[i];
            mpa[a[i]]++;
            sta.insert(a[i]);
        }
        for(int i=0; i<m; i++){
            cin >> b[i];
            mpb[b[i]]++;
            stb.insert(b[i]);
        }

        while(1){
            if(sta.empty() && stb.empty()){
                cout << "Yes" << endl;
                break;
            }
            if(sta.empty() || stb.empty()){
                cout << "No" << endl;
                break;
            }
            int mxa = *sta.begin();
            int mxb = *stb.begin();
            if(mxa > mxb){
                cout << "No" << endl;
                break;
            }
            else if(mxa == mxb){
                //remove from both
                int mini = min(mpa[mxb], mpb[mxb]);
                mpa[mxb] -= mini;
                mpb[mxb] -= mini;
                if(mpa[mxb]==0){
                    sta.erase(mxb);
                }
                if(mpb[mxb]==0){
                    stb.erase(mxb);
                }
            }
            else if(mxa < mxb){
                int f = mpb[mxb];
                int cv = (mxb+1)/2;
                int fv = mxb/2;
                mpb[mxb]= 0;
                stb.erase(mxb);
                for(int i=1; i<=f; i++){
                    stb.insert(cv), mpb[cv]++;
                    stb.insert(fv), mpb[fv]++;
                }
            }
        }
    }
}

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

using ll = long long;

signed main(){
    ll t;
    cin >> t;

    while(t--){
        ll n, m;
        cin >> n >> m;

        if(n==1){
            cout << "No" << endl;
            continue;
        }

        vector<ll> a(n), b(m);
        map<ll,ll> mpa, mpb;
        multiset<ll, greater<ll>> sta, stb;
        for(ll i=0; i<n; i++){
            cin >> a[i];
            mpa[a[i]]++;
            sta.insert(a[i]);
        }
        for(ll i=0; i<m; i++){
            cin >> b[i];
            mpb[b[i]]++;
            stb.insert(b[i]);
        }

        while(1){
            if(sta.empty() && stb.empty()){
                cout << "Yes" << endl;
                break;
            }
            if(sta.empty() || stb.empty()){
                cout << "No" << endl;
                break;
            }
            ll mxa = *sta.begin();
            ll mxb = *stb.begin();
            if(mxa > mxb){
                cout << "No" << endl;
                break;
            }
            else if(mxa == mxb){
                //remove from both
                ll mini = min(mpa[mxb], mpb[mxb]);
                mpa[mxb] -= mini;
                mpb[mxb] -= mini;
                if(mpa[mxb]==0){
                    sta.erase(mxb);
                }
                if(mpb[mxb]==0){
                    stb.erase(mxb);
                }
            }
            else if(mxa < mxb){
                ll f = mpb[mxb];
                ll cv = (mxb+1)/2;
                ll fv = mxb/2;
                mpb[mxb]= 0;
                stb.erase(mxb);
                for(ll i=1; i<=f; i++){
                    stb.insert(cv), mpb[cv]++;
                    stb.insert(fv), mpb[fv]++;
                }
            }
        }
    }
}