Problem: 2061D - Kevin and Numbers
Language: c++17 

Solution 1 (runtime: 484 ms):
#include <bits/stdc++.h>
using namespace std;
#define fastIO() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long

void solution() {
    int n, m;
    cin >> n >> m;
    map <int, int> mp;
    for(int i=0; i<n; i++){
        int x; cin >> x;
        mp[x]++;
    }
    multiset <int> st;
    for(int i=0; i<m; i++){
        int x; cin >> x;
        st.insert(x);
    }

    while(1){
        // cout << st.size() << " " << mp.size() << endl;
        if(st.size() > n){
            cout << "No\n";
            return;
        }
        if(mp.size() == 0 && st.size() == 0){
            cout << "Yes\n";
            return;
        }
        if((mp.size() == 0 && st.size() > 0) || (st.size() == 0 && mp.size() > 0) ){
            cout << "No\n";
            return;
        }
        int x = *st.begin();
        st.erase(st.begin());
        if(mp.count(x) > 0){
            mp[x]--;
            if(mp[x] == 0){
                mp.erase(x);
            }
        }
        else{
            int a = x/2, b = x/2;
            if(x&1)b++;
            st.insert(a);
            st.insert(b);
        }
    }
}

int32_t main() {
#ifndef ONLINE_JUDGE
    freopen("in.in", "r", stdin);
    freopen("out.out", "w", stdout);
#endif

    fastIO();
    int t = 1;
    cin >> t;
    while (t--)
    solution();
}

Solution 2 (runtime: 311 ms):
#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;
}
 
/*
 
 
*/