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

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

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

void solve(){
    int n, m;
    cin >> n >> m;
    multiset<int> a;
    vi b(m);
    for(int i = 0; i < n; i++) {
        int x; cin >> x;
        a.insert(x);
    }
    for(int i = 0; i < m; i++) {
        cin >> b[i];
    }
    sort(b.begin(), b.end());
    
    int ib = 0;
    auto ia = a.begin();

    while(ia != a.end()) {
        
        if(*ia == b[ib]) {
            ia++;
            ib++;
        }
        else {
            int ea = *(ia++);
            if(ia == a.end()) {
                cout << "No\n";
                return;
            }
            int na = *ia;
            if(abs(na - ea) <= 1) {
                a.insert(na + ea);
                ia++;
                // a.erase(ea);
                // a.erase(na);
            }else {
                cout << "No\n";
                return;
            }
        }
    }

    if(ib == m) {
        cout << "Yes\n";
    }
    else {
        cout << "No\n";
    }
    return;
}

int main(){
    int tt = 1; 
    cin >> tt;
    while(tt--) {
        solve();    
    }
    return 0;
}
// 500000000 500000000
// 1000000000 1000000000


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

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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);
    }
    
    auto ia = a.begin(), ib = b.begin();

    while(ia != a.end() || ib != b.end()) {
        int aa = *ia, bb = *ib;
        if(aa == bb) {
            ia++, ib++;
        }
        else {
            ia++;
            if(ia == a.end()) {
                break;
            }
            int na = *ia;
            if(abs(aa - na) > 1) {
                break;
            }

            a.insert(na + aa);
            ia++;
        }
    }

    if(ia == a.end() && ib == b.end()) {
        cout << "Yes\n";
    }
    else {
        cout << "No\n";
    }

    return;
}

void correct_solve() {
    int n, m; cin >> n >> m;
    priority_queue<int> a, b;
    for(int i = 0; i < n; i++) {
        int x; cin >> x;
        a.push(x);
    }
    for(int i = 0; i < m; i++) {
        int x; cin >> x;
        b.push(x);
    }

    while(!a.empty() && !b.empty()) {
        if(b.size() > a.size()) {
            cout << "No\n";
            return;
        }
        int x = b.top();
        b.pop();

        int y = a.top();

        if(x == y) {
            a.pop();
        }
        else if(x < y) {
            cout << "No\n";
            return;
        } 
        else {
            b.push(x / 2);
            b.push((x + 1) / 2);
        }
    } 

    if(a.empty() && b.empty()) {
        cout << "Yes\n";
        return;
    }

    cout << "No\n";
    return;
}


int main(){
    int tt = 1; 
    cin >> tt;
    while(tt--) {
        // solve();    
        correct_solve();
    }
    return 0;
}
// 500000000 500000000
// 1000000000 1000000000