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;
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;typedef long double ld;typedef pair<int,int> pii;
#define F first
#define S second
#define PB push_back
#define MP make_pair
const ll mod = 1e9+7, N = 2e6+7, M = 2e6+7, INF = INT_MAX/10;
ll powe(ll x, ll y){ x = x%mod, y=y%(mod-1);ll ans = 1;while(y>0){if (y&1){ans = (1ll * x * ans)%mod;}y>>=1;x = (1ll * x * x)%mod;}return ans;}




void solve() {
	int n,m;
    cin >> n >> m;
    map<int,int>a,b;
    for(int i=0,x;i<n;i++)
        cin >> x,a[x]++;
    for(int j=0,x;j<m;j++)
        cin >> x,b[x]++;
    for(auto &pp:b) {
        int times = pp.second;
        while (times--) {
            int num = pp.first;
            while(a[num]==0) {
                if (num%2==0) {
                    if (a[num/2]>0) {
                        a[num/2]--;
                        num/=2;
                    } else {
                        cout << "NO\n";
                        return;
                    }
                } else {
                    int t1 = (num-1)/2;
                    int t2 = t1+1;
                    if (a[t1]>0) {
                        a[t1]--;
                        num-=t1;
                    } else if (a[t2]>0) {
                        a[t2]--;
                        num-=t2;
                    } else {
                        cout << "NO\n";
                        return;
                    }
                }
            }
            a[num]--;
        }
    }
    int remaining = 0;
    for(auto &pp:a)
        remaining+=pp.second;
    if (remaining>0)
        cout << "NO\n";
    else
        cout << "YES\n";
}




signed main() {
    fast;
    int t = 1;
    cin >> t;
    while(t--){
    	solve();
    }
    return 0;
}


Submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;typedef long double ld;typedef pair<int,int> pii;
#define F first
#define S second
#define PB push_back
#define MP make_pair
const ll mod = 1e9+7, N = 2e6+7, M = 2e6+7, INF = INT_MAX/10;
ll powe(ll x, ll y){ x = x%mod, y=y%(mod-1);ll ans = 1;while(y>0){if (y&1){ans = (1ll * x * ans)%mod;}y>>=1;x = (1ll * x * x)%mod;}return ans;}




void solve() {
	int n,m;
    cin >> n >> m;
    map<int,int>a,b;
    for(int i=0,x;i<n;i++)
        cin >> x,a[x]++;
    for(int j=0,x;j<m;j++)
        cin >> x,b[x]++;
    for(auto itr=b.rbegin();itr!=b.rend();itr++) {
        int times = itr->second;
        while (times--) {
            int num = itr->first;
            while(a[num]==0) {
                if (num%2==0) {
                    if (a[num/2]>0) {
                        a[num/2]--;
                        num/=2;
                    } else {
                        cout << "NO\n";
                        return;
                    }
                } else {
                    int t1 = (num-1)/2;
                    int t2 = t1+1;
                    if (a[t2]>0) {
                        a[t2]--;
                        num-=t2;
                    } else if (a[t1]>0) {
                        a[t1]--;
                        num-=t1;
                    } else {
                        cout << "NO\n";
                        return;
                    }
                }
            }
            a[num]--;
        }
    }
    int remaining = 0;
    for(auto &pp:a)
        remaining+=pp.second;
    if (remaining>0)
        cout << "NO\n";
    else
        cout << "YES\n";
}




signed main() {
    fast;
    int t = 1;
    cin >> t;
    while(t--){
    	solve();
    }
    return 0;
}