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

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

using namespace std;

using ll =long long;

using pii=pair<int,int>;

#define yes cout<<"YES"<<endl;

#define no cout<<"NO"<<endl;

#define all(v) v.begin(),v.end()

using namespace std;





void solve(){

    ll n,m;

    cin>>n>>m;

    vector<ll>a(n),b(n);

    for(auto &it:a)cin>>it;

    for(auto &it:b)cin>>it;

    map<ll,ll>freq_a,freq_b;

    set<ll,greater<ll>>set_a,set_b;

    for(auto value:a){

        freq_a[value]++;

        set_a.insert(value);

    }

    for(auto value:b){

        freq_b[value]++;

        set_b.insert(value);

    }

    while(true){

        if(set_a.empty() and set_b.empty()){

            yes

            return;

        }

        if(set_a.empty() or set_b.empty()){

            no

            return;

        }

        ll max_b=*set_b.begin();

        ll max_a=*set_a.begin();

        if(max_a>max_b){

            no

            return;

        }

        if(freq_a[max_b]){

            ll min_count=min(freq_a[max_b],freq_b[max_b]);

            freq_a[max_b]-=min_count;

            freq_b[max_b]-=min_count;

            

            if (freq_a[max_b] == 0) set_a.erase(max_b);

            if (freq_b[max_b] == 0) set_b.erase(max_b);

        }

        else{

            ll part1=max_b/2;

            ll part2=(max_b+1)/2;

            ll count=freq_b[max_b];

            freq_b[max_b]=0;

            set_b.erase(max_b);



            freq_b[part1]+=count;

            freq_b[part2]+=count;

            set_b.insert(part1);

            set_b.insert(part2);

        }

    }

}

int main(){

    ios::sync_with_stdio(false); cin.tie(0);cout.tie(0);

    int t=1;

    cin>>t;

    while(t--){

        solve();

    }

    return 0; 

}



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

using namespace std;

using ll =long long;

using pii=pair<int,int>;

#define yes cout<<"YES"<<endl;

#define no cout<<"NO"<<endl;

#define all(v) v.begin(),v.end()

using namespace std;





void solve(){

    ll n,m;

    cin>>n>>m;

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

    for(auto &it:a)cin>>it;

    for(auto &it:b)cin>>it;

    map<ll,ll>freq_a,freq_b;

    set<ll,greater<ll>>set_a,set_b;

    for(auto value:a){

        freq_a[value]++;

        set_a.insert(value);

    }

    for(auto value:b){

        freq_b[value]++;

        set_b.insert(value);

    }

    while(true){

        if(set_a.empty() and set_b.empty()){

            yes

            return;

        }

        if(set_a.empty() or set_b.empty()){

            no

            return;

        }

        ll max_b=*set_b.begin();

        ll max_a=*set_a.begin();

        if(max_a>max_b){

            no

            return;

        }

        if(freq_a[max_b]){

            ll min_count=min(freq_a[max_b],freq_b[max_b]);

            freq_a[max_b]-=min_count;

            freq_b[max_b]-=min_count;

            

            if (freq_a[max_b] == 0) set_a.erase(max_b);

            if (freq_b[max_b] == 0) set_b.erase(max_b);

        }

        else{

            ll part1=max_b/2;

            ll part2=(max_b+1)/2;

            ll count=freq_b[max_b];

            freq_b[max_b]=0;

            set_b.erase(max_b);



            freq_b[part1]+=count;

            freq_b[part2]+=count;

            set_b.insert(part1);

            set_b.insert(part2);

        }

    }

}

int main(){

    ios::sync_with_stdio(false); cin.tie(0);cout.tie(0);

    int t=1;

    cin>>t;

    while(t--){

        solve();

    }

    return 0; 

}