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

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

#define int long long
#define nl
#define imin INT_MIN
#define imax INT_MAX
#define lmin LLONG_MIN
#define lmax LLONG_MAX
int solve(int x,map<int,int> &m){
    if(m.find(x)!=m.end()){
        m[x]--;
        if(m[x]==0){
            m.erase(x);
        }
        return 0;
    }
    auto it =m.begin();
    if(x<it->first){
        return 1;
    }
    int x1=x/2;
    int y1=(x+1)/2;
    return (solve(x1,m)|solve(y1,m));
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t;
    cin >> t;
    while (t--)
    {
        int n, m;
        cin >> n >> m;
        vector<int> a(n);
        vector<int> b(m);
        for (int i = 0; i < n; i++)
        {
            cin >> a[i];
        }
        for (int i = 0; i < m; i++)
        {
            cin >> b[i];
        }
        sort(a.begin(), a.end());
        sort(b.begin(), b.end());
        vector<int> v;
        vector<int> u;
        int i = 0;
        int j = 0;
        int f = 0;
        while (i < n && j < m)
        {
            if (a[i] == b[j])
            {
                i++;
                j++;
            }
            else if (a[i] > b[j])
            {
                u.push_back(b[j]);
                j++;
            }
            else
            {
                v.push_back(a[i]);
                i++;
            }
        }
        while (i < n)
        {
            v.push_back(a[i]);
            i++;
        }
        while (j < m)
        {
            u.push_back(b[j]);
            j++;
        }
        // cout<<1<<endl;
        map<int,int> m1;
        for(auto it : v){
            m1[it]++;
        }
        // cout<<1<<endl;
        for(auto it : u){
            f=(f|solve(it,m1));
            if(f==1){
                break;
            }
            
        }
        if(!m1.empty()){
            f=1;
        }
        if (f == 1)
        {
            cout << "No" << endl;
        }
        else
        {
            cout << "Yes" << endl;
        }
    }
    return 0;
}

Solution 2 (runtime: 296 ms):

#include<bits/stdc++.h>
using namespace std;
#define int long long
int32_t main(){

#ifdef ONLINEJUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
#endif

int t = 1;
cin>>t;
while(t--){
	int n,m,p1,q1,p2;
	bool bb=0;
	cin>>n>>m;
	 // cout<<n<<" "<<m<<"\n";
	int i,j;
	vector<int> a(n),b(m);
	priority_queue<int,vector<int>,greater<int>> p,q;
	for(i=0;i<n;i++){
		cin>>a[i];	
		p.push(a[i]);
	}
	for(j=0;j<m;j++){
		cin>>b[j];
		q.push(b[j]);
	}
	while(1){
		if(p.empty()||q.empty())break;
		p1 = p.top();
		q1 = q.top();
		if(p.size()==1){
			if(q.size()!=1)break;
			
			if(p1==q1)bb=1;
			break;
		}
		if(p1==q1){
			p.pop();
			q.pop();
		}else if(p1>q1){
			break;
		}else{
			p.pop();
			p2 = p.top();
			p.pop();
			if(p2-p1<=1){
				p.push(p1+p2);
			}
			else break;
		}
	}
	// while(!p.empty()){
	// 	cout<<p.top()<<" ";
	// 	p.pop();
	// }cout<<"\n";
	// while(!q.empty()){
	// 	cout<<q.top()<<" ";
	// 	q.pop();
	// }
	if(p.empty()&&q.empty())bb=1;
	if(bb)cout<<"YES\n";
	else cout<<"NO\n";
}

return 0;
}