Problem: 2061D - Kevin and Numbers
Language: C++17 (GCC 7-32)

Previous submission (verdict: Compilation error):
#include <iostream>
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
using namespace std;
#define int long long


void solve(){
    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(m);
    
    for(int i = 0; i<n; i++) cin >> a[i];
    for(int i = 0; i<m; i++) cin >> b[i];

    map<int, int> freqa, freqb;
    set<int> seta, setb;

    for(auto ele: a){
        freqa[ele]++;
        seta.insert(ele);
    }

    for(auto ele: b){
        freqb[ele]++;
        setb.insert(ele);
    }

    while(true){
        if(seta.empty() && setb.empty()){
            cout << "YES" << endl;
            return;
        }

        if(seta.empty() || setb.empty()){
            cout << "NO" << endl;
            return;
        }

        int max1 = *prev(set.end());
        int max2 = *prev(set.end());

        if(max1 > max2){
            cout << "NO" << endl;
            return;
        }

        if(freqa[max2]){
            int minfreq = min(freqa[max2], freqb[max2]);
            freqa[max2] = freqa[max2] - minfreq;
            freqb[max2] = freqb[max2] - minfreq;

            if(freqa[max2] == 0) seta.erase(max2);
            if(freqb[max2] == 0) setb.erase(max2);
        }

        else{
            int cl = (max2 + 1)/2;
            int fl = max2/2;
            freqb[cl] = freqb[cl] + freqb[max2];
            freqb[fl] = freqb[fl] + freqb[max2];
            freqb[max2] = 0;
            setb.insert(cl);
            setb.insert(fl);
            setb.erase(max2);
        }
    }
}


signed main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int t;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}

Submission (verdict: Accepted):
#include <iostream>
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
using namespace std;
#define int long long


void solve(){
    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(m);
    
    for(int i = 0; i<n; i++) cin >> a[i];
    for(int i = 0; i<m; i++) cin >> b[i];

    map<int, int> freqa, freqb;
    set<int> seta, setb;

    for(auto ele: a){
        freqa[ele]++;
        seta.insert(ele);
    }

    for(auto ele: b){
        freqb[ele]++;
        setb.insert(ele);
    }

    while(true){
        if(seta.empty() && setb.empty()){
            cout << "YES" << endl;
            return;
        }

        if(seta.empty() || setb.empty()){
            cout << "NO" << endl;
            return;
        }

        int max1 = *prev(seta.end());
        int max2 = *prev(setb.end());

        if(max1 > max2){
            cout << "NO" << endl;
            return;
        }

        if(freqa[max2]){
            int minfreq = min(freqa[max2], freqb[max2]);
            freqa[max2] = freqa[max2] - minfreq;
            freqb[max2] = freqb[max2] - minfreq;

            if(freqa[max2] == 0) seta.erase(max2);
            if(freqb[max2] == 0) setb.erase(max2);
        }

        else{
            int cl = (max2 + 1)/2;
            int fl = max2/2;
            freqb[cl] = freqb[cl] + freqb[max2];
            freqb[fl] = freqb[fl] + freqb[max2];
            freqb[max2] = 0;
            setb.insert(cl);
            setb.insert(fl);
            setb.erase(max2);
        }
    }
}


signed main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int t;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}