Problem: 2061D - Kevin and Numbers
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;
#define ll int
#define lld long double
#define pll pair <ll, ll> 
#define f(i, a, b) for(ll i = a; i < b; i++)
#define br cout<<"\n";
const long long int N =  2e5+20;
const long long int M =  998244353;

ll binpow(ll x, ll y, ll MOD){
    ll res = 1; x %= MOD;
    while(y > 0){
        if(y&1ll){res = (res * x) % MOD;}
        x = (x * x) % MOD;
        y >>= 1LL;
    }
    res %= MOD;
    return res;
}


void solve(){ 
    ll n, m; 
    cin>>n>>m;
    vector <ll> a(n), b(m); 
    multiset <ll> s, t;
    f(i, 0, n){
        cin>>a[i];
        s.insert(a[i]);
    }
    f(j, 0, m){
        cin>>b[j];
        t.insert(b[j]);
    }
    ll cnt = 0; 
    while(cnt < n-m){
        vector <ll> v;
        for(auto x: t){
            if(s.find(x) != s.end()){
                s.erase(s.find(x));
            }
            else{
                cnt++;
                v.push_back(x/2);
                v.push_back((x+1)/2);
            }
            if(cnt >= n-m){break;}
        }
        t.clear();
        assert(t.size() == 0);
        for(auto x: v){
            t.insert(x);
        }
        if(t.empty() || s.empty()){break;}
    }
    if(t.size() != s.size()){
        cout<<"NO\n";
        return;
    }
    for(auto x: t){
        if(s.find(x) == s.end()){
            cout<<"NO\n"; 
            return;
        }
        if(s.count(x) != t.count(x)){
            cout<<"NO\n";
            return;
        }
    }
    for(auto x: s){
        if(t.find(x) == t.end()){
            cout<<"NO\n"; 
            return;
        }
        if(s.count(x) != t.count(x)){
            cout<<"NO\n";
            return;
        }
    }
    cout<<"YES\n";
    return;
}   

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int TT = 1;
    cin >> TT;
    f(tt, 1, TT+1){
        solve();
    }
    return 0;
}

Submission (verdict: Time limit exceeded on test 21):
#include <bits/stdc++.h>
using namespace std;
#define ll int
#define lld long double
#define pll pair <ll, ll> 
#define f(i, a, b) for(ll i = a; i < b; i++)
#define br cout<<"\n";
const long long int N =  2e5+20;
const long long int M =  998244353;

ll binpow(ll x, ll y, ll MOD){
    ll res = 1; x %= MOD;
    while(y > 0){
        if(y&1ll){res = (res * x) % MOD;}
        x = (x * x) % MOD;
        y >>= 1LL;
    }
    res %= MOD;
    return res;
}


void solve(){ 
    ll n, m; 
    cin>>n>>m;
    vector <ll> a(n), b(m); 
    multiset <ll> s, t;
    f(i, 0, n){
        cin>>a[i];
        s.insert(a[i]);
    }
    f(j, 0, m){
        cin>>b[j];
        t.insert(b[j]);
    }
    ll cnt = 0; 
    while(cnt < n-m){
        vector <ll> v;
        for(auto x: t){
            if(s.find(x) != s.end()){
                s.erase(s.find(x));
            }
            else{
                cnt++;
                v.push_back(x/2);
                v.push_back((x+1)/2);
            }
            
        }
        t.clear();
        assert(t.size() == 0);
        for(auto x: v){
            t.insert(x);
        }
        if(t.empty() || s.empty()){break;}
    }
    if(t.size() != s.size()){
        cout<<"NO\n";
        return;
    }
    for(auto x: t){
        if(s.find(x) == s.end()){
            cout<<"NO\n"; 
            return;
        }
        if(s.count(x) != t.count(x)){
            cout<<"NO\n";
            return;
        }
    }
    for(auto x: s){
        if(t.find(x) == t.end()){
            cout<<"NO\n"; 
            return;
        }
        if(s.count(x) != t.count(x)){
            cout<<"NO\n";
            return;
        }
    }
    cout<<"YES\n";
    return;
}   

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int TT = 1;
    cin >> TT;
    f(tt, 1, TT+1){
        solve();
    }
    return 0;
}