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

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

void sol() {
    int n, m; cin >> n >> m;
    map<int, int>a, b;
    vector<int> A;
    for(int i = 1; i <= n; ++i) {
        int x; cin >> x;
        if(!a[x]) A.push_back(x);
        a[x]++;
    }
    for(int i = 1; i <= m; ++i) {
        int x; cin >> x;
        b[x]++;
    }

    sort(A.begin(), A.end());
    for(auto x : A) {
        int mn = min(a[x], b[x]);
        a[x] -= mn; b[x] -= mn;
    }
    for(auto x : A) {
        int mn = min(a[x], b[x]);
        a[x] -= mn; b[x] -= mn;
        if(a[x + 1]) {
            if(x != 1) {
                mn = min(a[x], a[x + 1]);
                a[x] -= mn; a[x + 1] -= mn;
                a[2 * x + 1] += mn;
                mn = min(a[2 * x + 1], b[2 * x + 1]);
                a[2 * x + 1] -= mn; b[2 * x + 1] -= mn;
                a[2 * x] += a[x] / 2;
                a[x] %= 2;
            } else {
                x++;
                mn = min(a[1] / x, a[x]);
                a[1] -= (x * mn); a[x] -= mn;
                a[2 * x] += mn;
                mn = min(a[2 * x], b[2 * x]);
                a[2 * x] -= mn; b[2 * x] -= mn;
                mn = min(a[1] / (x - 1), a[x]);
                a[1] -= ((x - 1) * mn); a[x] -= mn;
                a[2 * x - 1] += mn;
                mn = min(a[2 * x - 1], b[2 * x - 1]);
                a[2 * x - 1] -= mn; b[2 * x - 1] -= mn;
            }
            //cout << x << ' ' << a[1] << ' ' << a[2] << ' ' << a[3] << '\n';
        } else {
            if(x == 1) continue;
            mn = min(a[1] / x, a[x]);
            a[1] -= (x * mn); a[x] -= mn;
            a[2 * x] += mn;
            mn = min(a[2 * x], b[2 * x]);
            a[2 * x] -= mn; b[2 * x] -= mn;
            mn = min(a[1] / (x - 1), a[x]);
            a[1] -= ((x - 1) * mn); a[x] -= mn;
            a[2 * x - 1] += mn;
            mn = min(a[2 * x - 1], b[2 * x - 1]);
            a[2 * x - 1] -= mn; b[2 * x - 1] -= mn;
            a[2 * x] += a[x] / 2;
            a[x] %= 2;
            mn = min(a[2 * x], b[2 * x]);
            a[2 * x] -= mn; b[2 * x] -= mn;
            mn = min(a[1] / x, a[x]);
            a[1] -= (x * mn); a[x] -= mn;
            a[2 * x] += mn;
            mn = min(a[2 * x], b[2 * x]);
            a[2 * x] -= mn; b[2 * x] -= mn;
            mn = min(a[1] / (x - 1), a[x]);
            a[1] -= ((x - 1) * mn); a[x] -= mn;
            a[2 * x - 1] += mn;
            mn = min(a[2 * x - 1], b[2 * x - 1]);
            a[2 * x - 1] -= mn; b[2 * x - 1] -= mn;
        }
    }
    int d = 0;
    for(auto [x, cnt] : a) {
        if(x == 1) continue;
        d += (cnt > 0);
    }
    if(d) return void(cout << "NO\n");
    for(auto[x, cnt] : b) {
        if(a[1] < (cnt * x)) return void(cout << "NO\n");
        else a[1] -= (cnt * x);
    }
    if(a[1]) cout << "NO\n";
    else cout << "YES\n";
}

int32_t main() {
    ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
    int T = 1; cin >> T;
    while (T--) sol();
}

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

void sol() {
    int n, m; cin >> n >> m;
    map<int, int>mp;
    for(int i = 1; i <= n; ++i) {
        int x; cin >> x;
        mp[x]++;
    }
    priority_queue<int> pq;
    for(int i = 1; i <= m; ++i) {
        int x; cin >> x;
        pq.push(x);
    }
    for(int i = 1; i <= 2 * n - m; ++i) {
        if(pq.empty()) return void(cout << "NO\n");
        int x = pq.top();
        pq.pop();
        if(!mp[x]) {
            pq.push(x / 2);
            pq.push((x + 1) / 2);
        } else
            --mp[x];
    }
    cout << (pq.empty() ? "YES\n" : "NO\n");

}

int32_t main() {
    ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
    int T = 1; cin >> T;
    while (T--) sol();
}