Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 3):
#include<bits/stdc++.h>
#define int long long 
using namespace std;

void solve(){
     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(((int)b.size() > 0) and ((int)a.size() > 0)) {
        //     for(auto &it : a) {
        //     cout << it << " ";
        // } cout << " $\n";
        
        if(*a.begin() == *b.begin()) {
            a.erase(a.begin());
            b.erase(b.begin());
        } else {
            // cout << ((int)a.count(*a.begin() + 1)) << " " << ((*a.begin()) + 1) <<  "\n";
            // cout << ((int)a.count(*a.begin())) << " " << ((*a.begin())) <<  "\n";
            
            if(((int)a.size() > 1) and ((int)a.count(*a.begin()) > 1)) {
                int x = *a.begin();
                a.erase(a.begin());
                a.erase(a.find(x));
                
                a.insert((int)2 * x);                
            } else if(((int)a.size() > 1) and (int)a.count(*a.begin() + 1)) {
                int x = *a.begin();
                a.erase(a.begin());
                a.erase(a.find(x + 1));
                
                a.insert(((int)2 * x)  + (int)1);
            } else {
                cout << "No" << "\n"; return;
            }
        }
     }
     
    //  for(auto &it : a) {
    //       cout << it << " ";
    // } cout << " $\n";
     
     if(!(int)a.size() and !(int)b.size()) {
         cout << "Yes" << "\n";
     } else {
         cout << "No" << "\n";
     }
}  
 
int32_t main(){
 
    int t = 1;
    cin >> t;
 
    while(t--){
        solve();
    } 
 
    return 0;
}

/*
Yes
No
Yes
Yes
No
Yes
No
No
No

*/


















Submission (verdict: Accepted):
#include<bits/stdc++.h>
#define int long long 
using namespace std;

void solve(){
     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(((int)b.size() > 0) and ((int)a.size() > 0)) {
        int val = -(*b.begin());
        b.erase(b.begin());
        queue<int> qu;
        qu.push(val);
        
        while((int)qu.size()) { 
            int currVal = (int)qu.front();
            qu.pop();
            
            if(a.count(currVal)) {
                a.erase(a.find(currVal));
            } else {
                if(currVal != 1) {
                    if(currVal & (int)1) {
                        qu.push((currVal / (int)2));
                        qu.push((currVal / (int)2) + (int)1);
                    } else {
                        qu.push((currVal / (int)2));
                        qu.push((currVal / (int)2));
                    }
                } else {
                    cout << "No" << "\n";
                    return;
                }
            }
            
            if((int)qu.size() > n) { cout << "No" << "\n"; return;}
        }
     }

     if(!(int)a.size() and !(int)b.size()) {
         cout << "Yes" << "\n";
     } else {
         cout << "No" << "\n";
     }
}  
 
int32_t main(){
 
    int t = 1;
    cin >> t;
 
    while(t--){
        solve();
    } 
 
    return 0;
}

/*
Yes
No
Yes
Yes
No
Yes
No
No
No

*/