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

Solution 1 (runtime: 874 ms):
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define int long long int
#define F first
#define S second
#define MOD 1000000007

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

        multiset <int> a , b;
        for(int i=0 ; i<n ; i++) {
            int x; cin >> x;
            a.insert(x);
        }

        for(int i=0 ; i<m ; i++) {
            int x; cin >> x;
            b.insert(x);
        }

        while(a.size() > 0 and b.size() > 0 and b.size() <= a.size()) {
            auto x = b.end(); x--;
            int xx = *x; b.erase(x);
            if(a.find(xx) != a.end()) 
                a.erase(a.find(xx));
            else {
                if(xx % 2){
                    b.insert(xx/2);
                    b.insert(xx/2 + 1);
                } else{
                    b.insert(xx/2);
                    b.insert(xx/2);
                }
            }
        }

        if(a.size() == 0 and b.size() == 0)
            cout << "YES";
        else
            cout << "NO";

        cout << '\n';
    }
}

Solution 2 (runtime: 937 ms):
#include<bits/stdc++.h>
using namespace std;
int T,n,m,a[200005],b[200005];
priority_queue<int> pq;
map<int,int> ma,mb;
int main(){
    cin>>T;
    for(int i=1;i<=T;i++){
        ma.clear(),mb.clear();
        while(!pq.empty())
        pq.pop();
        cin>>n>>m;
        int op=n-m;
        for(int j=1;j<=n;j++){
            cin>>a[j];
            ma[a[j]]++;
        }
        for(int j=1;j<=m;j++){
            cin>>b[j];
            mb[b[j]]++;
        }
        for (auto it=ma.begin();it!=ma.end();){
            int x=it->first;
            if(mb.count(x)){
                if(ma[x]<mb[x]){
                    mb[x]-=ma[x];
                    it=ma.erase(it);
                }
                else if(ma[x]==mb[x]){
                    mb.erase(x);
                    it=ma.erase(it);
                }
                else{
                    ma[x]-=mb[x];
                    mb.erase(x);
                    it++;
                }
            }
            else
            it++;
        }
        for(auto it=mb.begin();it!=mb.end();it++){
            int x=it->first;
            pq.push(x);
        }
        while((!pq.empty())&&op>0){
            int x=pq.top();
            pq.pop();
            if(x==1)
            break;
            if(x%2){
                if(ma.count(x/2+1)){
                    if(ma[x/2+1]<mb[x]){
                        if(!mb.count(x/2+1))
                        pq.push(x/2+1);
                        mb[x/2+1]+=mb[x]-ma[x/2+1];
                        ma.erase(x/2+1);
                    }
                    else if(ma[x/2+1]==mb[x])
                    ma.erase(x/2+1);
                    else
                    ma[x/2+1]-=mb[x];
                }
                else{
                    if(!mb.count(x/2+1))
                    pq.push(x/2+1);
                    mb[x/2+1]+=mb[x];
                }
                if(ma.count(x/2)){
                    if(ma[x/2]<mb[x]){
                        if(!mb.count(x/2))
                        pq.push(x/2);
                        mb[x/2]+=mb[x]-ma[x/2];
                        ma.erase(x/2);
                    }
                    else if(ma[x/2]==mb[x])
                    ma.erase(x/2);
                    else
                    ma[x/2]-=mb[x];
                }
                else{
                    if(!mb.count(x/2))
                    pq.push(x/2);
                    mb[x/2]+=mb[x];
                }
            }
            else{
                if(ma.count(x/2)){
                    if(ma[x/2]<mb[x]*2){
                        if(!mb.count(x/2))
                        pq.push(x/2);
                        mb[x/2]+=mb[x]*2-ma[x/2];
                        ma.erase(x/2);
                    }
                    else if(ma[x/2]==mb[x]*2)
                    ma.erase(x/2);
                    else
                    ma[x/2]-=mb[x]*2;
                }
                else{
                    if(!mb.count(x/2))
                    pq.push(x/2);
                    mb[x/2]+=mb[x]*2;
                }
            }
            op-=mb[x];
            mb.erase(x);
        }
        if(ma.empty()&&mb.empty()&&!op)
        cout<<"Yes"<<endl;
        else
        cout<<"No"<<endl;
    }
}