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

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

using namespace std;

typedef long long ll;
typedef long double ldl;
typedef unsigned long long ull;

// #define INTERACT

bool ga(ll x, ll c1, ll c2, map<ll, ll>& cnt)
{
    ll c1i = c1;
    ll c2i = c2;
    c1 = max(0LL, c1-cnt[x]);
    c2 = max(0LL, c2-cnt[x+1]);
    cnt[x] = max(0LL, cnt[x]-c1i);
    cnt[x+1] = max(0LL, cnt[x+1]-c2i);

    if(c1 == 0 && c2 == 0)
        return true;
    if(x == 1)
    {
        return false;
    }

    if(x % 2)
    {
        return ga(x / 2, c1, c2*2+c1, cnt);
    }
    else
    {
        return ga(x / 2, c1*2+c2, c2, cnt);
    }
}

int main()
{
#ifndef INTERACT
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#endif
    int t = 1;
    cin >> t;
    while (t--)
    {
        ll n, m;
        cin >> n >> m;
        map<ll, ll> a;
        vector<ll> b(m);
        for(ll i = 0; i < n; i++)
        {
            ll tmp;
            cin >> tmp;
            a[tmp] += 1;
        }
        for(ll i = 0; i < m; i++)
        {
            cin >> b[i];
        }

        ll ans = 1;
        for(ll i = 0; i < m; i++)
        {
            ans &= ga(b[i], 1, 0, a);
        }

        for(auto i: a)
        {
            if(i.second)
                ans = 0;
        }
        if(ans)
        {
            cout << "YES\n";
        }
        else
        {
            cout << "No\n";
        }
    }
}

Submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using vi = vector <ll>;
using vll = vector<ll>;
using vs = vector <string>;
using vb = vector <bool>;
using vd = vector <double>;
using vc = vector <char>;
using pii = pair<ll, ll>;
using pib = pair<ll, bool>;
using vpib = vector<pair<ll, bool>>;
using pll = pair<ll, ll>;
using vpii = vector <pii>;

bool update(map<ll, ll> &freqa, map<ll, ll> &freqb) {
    auto q = freqb.rbegin();
    if(freqa.find(q->first) != freqa.end()){
        // cerr<<q->first<<" "<<q->second<<" "<<freqa[q->first]<<".\n";
        ll diff = min(freqa[q->first], freqb[q->first]);
        ll num = q->first;
        freqb[q->first] -= diff;
        freqa[q->first] -= diff;
        if(freqb[q->first] == 0){
            freqb.erase(q->first);
        }
        if(freqa[num] == 0)
            freqa.erase(num);
        return true;
    }
    ll x = q->first / 2, y = (q->first + 1) / 2;
    if(x == 0)
    {
        freqb.erase(q->first);
        return true;
    }
    freqb[x] += freqb[q->first];
    freqb[y] += freqb[q->first];
    // cerr<<q->first<<" "<<q->second<<"h:"<<'\n';
    freqb.erase(q->first);
    return true;
}

void solve(){
    ll n, m;
    cin>>n>>m;
    map<ll, ll> freqa;
    map<ll, ll> freqb;
    vector<ll> el(n);

    ll sum1 = 0, sum2 = 0;
    for(auto &x : el)
    {
        cin>>x;
        freqa[x]++;
        sum1 += x;
    }
    vector<ll> el2(m);

    for(auto &x : el2)
    {
        cin>>x;
        freqb[x]++;
        sum2 += x;
    }
    
    if(sum1 != sum2)
    {
        cout<<"No\n";
        return;
    }

    while(freqb.size() and freqa.size()){
        auto q = freqb.rbegin();
        update(freqa, freqb);
    }

    if(freqb.empty() and freqa.empty())
    {
        cout<<"Yes\n";
    }
    else 
        cout<<"No\n";
    
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);

    ll t;
    cin>>t;
    while(t--)
        solve();
}