Problem: 2061D - Kevin and Numbers
Language: c++23 

Code 1:
#include <bits/stdc++.h>

using namespace std;



void solve() {

    int n, m;

    cin >> n >> m;



    vector<int> a(n);

    vector<int> b(m);

    map<int, int> mpa;

    map<int, int> mpb;

	set<int,greater<int>> s1;

    set<int,greater<int>> s2;



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

        cin >> a[i];

        mpa[a[i]]++;

        s1.insert(a[i]);

    }

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

        cin >> b[i];

        mpb[b[i]]++;

        s2.insert(b[i]);

    }



    while (true) {

        if (s1.empty() && s2.empty()) {

            cout << "Yes" << endl;

            return;

        }



        if (s1.empty() || s2.empty()) {

            cout << "No" << endl;

            return;

        }



        int mxa = *s1.rbegin(); 

        int mxb = *s2.rbegin(); // Get the largest element in s2



        if (mxa > mxb) {

            cout << "No" << endl;

            return;

        } else if (mxa == mxb) {

            int minifre = min(mpa[mxa], mpb[mxb]);

            mpa[mxa] -= minifre;

            mpb[mxb] -= minifre;



            if (mpa[mxa] == 0) s1.erase(mxa);

            if (mpb[mxb] == 0) s2.erase(mxb);

        } else { // mxa < mxb

            int sl = mxb / 2;

            int sb = (mxb + 1) / 2;



            

			mpb[sl]+=mpb[mxb];

            s2.insert(sl);



            mpb[sb]+=mpb[mxb];

            s2.insert(sb);

			mpb[mxb]=0;

            if (mpb[mxb] == 0) s2.erase(mxb);



            

        }

    }

}



int main() {

    int t;

    cin >> t;

    while (t--) {

        solve();

    }

}

Code 2:
#include <bits/stdc++.h>

using namespace std;



void solve() {

    int n, m;

    cin >> n >> m;



    vector<int> a(n), b(m);

    map<int, int> mpa, mpb;

    set<int> s1, s2;



 

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

        cin >> a[i];

        mpa[a[i]]++;

        s1.insert(a[i]);

    }



  

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

        cin >> b[i];

        mpb[b[i]]++;

        s2.insert(b[i]);

    }



    while (true) {

      

        if (s1.empty() && s2.empty()) {

            cout << "Yes\n";

            return;

        }



       

        if (s1.empty() || s2.empty()) {

            cout << "No\n";

            return;

        }



       

        int mxa = *s1.rbegin(); 

        int mxb = *s2.rbegin(); 



        if (mxa > mxb) {

            cout << "No\n";

            return;

        }



        

        if (mxa == mxb) {

            int common = min(mpa[mxa], mpb[mxb]);

            mpa[mxa] -= common;

            mpb[mxb] -= common;



            if (mpa[mxa] == 0) s1.erase(mxa);

            if (mpb[mxb] == 0) s2.erase(mxb);

        }

        else {

           

            if (mpb[mxb] == 0) {

                s2.erase(mxb);

                continue;

            }



            int count = mpb[mxb];

            mpb[mxb] = 0;

            s2.erase(mxb);



            int part1 = mxb / 2;

            int part2 = (mxb + 1) / 2;



            mpb[part1] += count;

            s2.insert(part1);

            mpb[part2] += count;

            s2.insert(part2);

        }

    }

}



int main() {

    int t;

    cin >> t;

    while (t--) {

        solve();

    }

}



Answer: 2