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
#define ll long long
#define mod 1000000007
#define mod2 998244353
#define inf (1LL << 60)
#define all(x) (x).begin(), (x).end()
#define pii pair<int, int>
#define endl "\n"
#define cout std::cout
#define cin std::cin
#define fo(i, a, b) for (int i = a; i < b; i++)
void print(vector<int> &a){
    fo(i, 0, a.size()) cout << a[i] << " ";
    cout << endl;
}
/**************************************************/
int expo(int a, int b, int m){
    int res = 1;
    while (b > 0)
    {
        if (b & 1)
            res = (res * a) % m;
        a = (a * a) % m;
        b = (b >> 1);
    }
    return res;
}
 
int gcd(int a, int b){
    if (a < b) swap(a, b);
    return b == 0 ? a : gcd(b, a % b);
}
 
int LCM(int a, int b){return (a * b) / gcd(a, b);}
 
int mod_add(int a, int b, int m){a = (m + a % m) % m;b = (m + b % m) % m;return (a + b) % m;}
int mod_sub(int a, int b, int m){a = (m + a % m) % m;b = (m + b % m) % m;return (m + a - b) % m;}
int mod_mul(int a, int b, int m){a = (m + a % m) % m;b = (m + b % m) % m;return (a * b) % m;}
int mod_div_prime(int a, int b, int m) { return mod_mul(a, expo(b, m - 2, m), m); } // modular multiplicative inverse with prime modulo
/**************************************************/
 
void solve(){
    int n, m; cin >> n >> m;
    vector<int> a(n), b(m);
    map<int,int> cnt;
    fo(i, 0, n){
        cin >> a[i];
        cnt[a[i]]++;
    }

    fo(i, 0, m){
        cin >> b[i];
    }

    fo(i, 0, m){
        while(b[i]){
            if(cnt[b[i]]){
                cnt[b[i]]--; 
                break;
            }
            int a1 = (b[i] + 1)/2, a2 = (b[i])/2;
            
            if(!cnt[a1] && !cnt[a2]){
                cout << "NO" << endl;
                return;
            }
            if(cnt[a1]){
                cnt[a1]--;
                b[i] /= 2;
            }
            else if(cnt[a2]){
                cnt[a2]--;
                b[i] = (b[i] + 1)/2;
            }
        }
    }

    for(auto & it : cnt){
        if(it.second){
            cout << "NO" << endl; return;
        }
    }

    cout << "YES" << endl;

}
 
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 
    int t = 1;
    cin >> t;
 
    while (t--){
        solve();
    }
 
    return 0;
}
 
/*
 
 
*/


Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define ll long long
#define mod 1000000007
#define mod2 998244353
#define inf (1LL << 60)
#define all(x) (x).begin(), (x).end()
#define pii pair<int, int>
#define endl "\n"
#define cout std::cout
#define cin std::cin
#define fo(i, a, b) for (int i = a; i < b; i++)
void print(vector<int> &a){
    fo(i, 0, a.size()) cout << a[i] << " ";
    cout << endl;
}
/**************************************************/
int expo(int a, int b, int m){
    int res = 1;
    while (b > 0)
    {
        if (b & 1)
            res = (res * a) % m;
        a = (a * a) % m;
        b = (b >> 1);
    }
    return res;
}
 
int gcd(int a, int b){
    if (a < b) swap(a, b);
    return b == 0 ? a : gcd(b, a % b);
}
 
int LCM(int a, int b){return (a * b) / gcd(a, b);}
 
int mod_add(int a, int b, int m){a = (m + a % m) % m;b = (m + b % m) % m;return (a + b) % m;}
int mod_sub(int a, int b, int m){a = (m + a % m) % m;b = (m + b % m) % m;return (m + a - b) % m;}
int mod_mul(int a, int b, int m){a = (m + a % m) % m;b = (m + b % m) % m;return (a * b) % m;}
int mod_div_prime(int a, int b, int m) { return mod_mul(a, expo(b, m - 2, m), m); } // modular multiplicative inverse with prime modulo
/**************************************************/
 
bool can(int n, map<int,int> & cnt){
    if(cnt[n]){
        cnt[n]--;
        return true;
    }

    if(n == 1) {
        return false;
    }

    return can(n/2, cnt) && can(n - n/2, cnt);
}

void solve(){
    int n, m; cin >> n >> m;
    vector<int> a(n), b(m);
    map<int,int> cnt;
    fo(i, 0, n){
        cin >> a[i];
        cnt[a[i]]++;
    }

    fo(i, 0, m){
        cin >> b[i];
    }

    fo(i, 0, m){
        if(!can(b[i], cnt)){
            cout << "NO" << endl; return;
        }
    }

    for(auto & it : cnt){
        if(it.second){
            cout << "NO" << endl; return;
        }
    }

    cout << "YES" << endl;

}
 
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 
    int t = 1;
    cin >> t;
 
    while (t--){
        solve();
    }
 
    return 0;
}
 
/*
 
 
*/