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 endl '\n'
#define Yes cout<<"Yes"<<endl;
#define No cout<<"No"<<endl;
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define all(x) x.begin(),x.end()
#define All(x) x.begin()+1,x.end()
#define int long long 
typedef unsigned long long ull;
typedef long long ll;
typedef __int128 i128;
typedef pair<int,int> pii;
const int dx[4]={1,-1,0,0};
const int dy[4]={0,0,1,-1};

void solve(){
    int n,m;
    cin>>n>>m;
    vector<int>a(n+1),b(m+1);
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=m;i++)cin>>b[i];
    sort(All(a)),sort(All(b));
    int id=1;
    map<int,int>mp,need;

    function<bool(int)> dfs=[&](int now){
        if(now==0)return 0;
        if(mp[now]>0)need[now]++;
        else if(now==1){
            return 0;
        }
        else {
            if(dfs(now/2)==1&&dfs((now+1)/2)==1)return 1;
            else return 0;
        }

        if(need[now]>mp[now])return 0;
        return 1;
    };

    function<void(int)> clear=[&](int now){
        if(mp[now]>0){
            mp[now]--;
            if(mp[now]==0)mp.erase(now);
        }
        else {
            clear(now/2);
            clear((now+1)/2);
        }
        return;
    };

    for(int i=1;i<=m;i++){
        if(id<=n){
            while(id<=n&&a[id]<b[i])mp[a[id]]++,id++;
            if(a[id]==b[i]){
                id++;
                continue;
            }
        }
        need.clear();
        if(dfs(b[i])){
            clear(b[i]);
        }
        else {
            No;
            return;
        }
    }
    int sta=0;
    for(auto [u,v]:mp)if(v>0)sta=1;
    if(id==n+1&&sta==0)Yes
    else No
}

signed main(){
    ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
    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 endl '\n'
#define Yes cout<<"Yes"<<endl;
#define No cout<<"No"<<endl;
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define all(x) x.begin(),x.end()
#define All(x) x.begin()+1,x.end()
#define int long long 
typedef unsigned long long ull;
typedef long long ll;
typedef __int128 i128;
typedef pair<int,int> pii;
const int dx[4]={1,-1,0,0};
const int dy[4]={0,0,1,-1};

void solve(){
    int n,m;
    cin>>n>>m;
    vector<int>a(n+1),b(m+1);
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=m;i++)cin>>b[i];
    sort(All(a)),sort(All(b));
    int id=1;
    map<int,int>mp;

    function<bool(int)> dfs=[&](int now){
        if(now==0)return 0;
        if(mp[now]>0)mp[now]--;
        else if(now==1){
            return 0;
        }
        else {
            if(dfs(now/2)==1&&dfs((now+1)/2)==1)return 1;
            else return 0;
        }
        return 1;
    };

    for(int i=1;i<=m;i++){
        if(id<=n){
            while(id<=n&&a[id]<b[i])mp[a[id]]++,id++;
            if(a[id]==b[i]){
                id++;
                continue;
            }
        }
        if(dfs(b[i]));
        else {
            No;
            return;
        }
    }
    int sta=0;
    for(auto [u,v]:mp)if(v>0)sta=1;
    if(id==n+1&&sta==0)Yes
    else No
}

signed main(){
    ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
    int t=1;
    cin>>t;
    while(t--)solve();
    return 0;
}