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

Solution 1 (runtime: 327 ms):
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define fi first
#define sc second
#define PI acos(-1.0)
#define MOD 1000000007
#define endl '\n'
#define eb emplace_back
#define set(n, k) (n = (1LL << k))
#define unset(n, k) (n &= ~(1LL << k))
#define check(n , k) (n & (1LL << k))
#define toggle(n, k) (n ^ (1LL << k))
#define fastio std::ios_base::sync_with_stdio (false); cin.tie(0); cout.tie(0);
int popcount(ll n) {return __builtin_popcountll(n);}
int poplow(ll n) {return __builtin_ctzll(n);}
int pophigh(ll n) {return 63 - __builtin_ctzll(n);}
ll PERFECT_NUM[]={6,28,496,8128,33550336,8589869056,137438691328,2305843008139952128};
//-----------------------------------------------------------------------------------
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a, ll b){
    return ((a/gcd(a,b))*b);
}

ll BigMod(ll a, ll p, ll m){
    ll ret=1;
    while(p){
        if(p&1) ret=((ret%m)*(a%m))%m;
        a=((a%m)*(a%m))%m;
        p/=2;
    }
    return ret;
}
ll AddMul(ll a, ll p, ll m){
    ll ret=0;
    while(p){
        if(p&1) ret=((ret%m)+(a%m))%m;
        a=((a%m)+(a%m))%m;
        p /= 2;
    }
    return ret;
}
void iofile(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}
//-------------------------------------------------------------------------
 /*TO GET SOMETHING YOU NEVER HAD YOU HAVE TO DO SOMETHING YOU NEVER DID*/
//-------------------------------------------------------------------------

void solve(){
    int n, m; cin >> n >> m;
    map<int, int>mp;
    vector<int>v(m);

    for(int i = 0; i < n; i++){
        int x; cin >> x;
        mp[x]++;
    }

    priority_queue<int>pq;
    for(int i = 0; i < m; i++){
        int x; cin >> x;
        pq.push(x);
    }

    while(!pq.empty()){
        if(pq.size() > n) break;

        int x = pq.top(); pq.pop();
        if(mp[x]){
            mp[x]--; n--;
        }
        else{
            pq.push(x / 2);
            pq.push(x - (x / 2));
        }
    }

    if(pq.empty() && !n) cout << "YES" << endl;
    else cout << "NO" << endl;
}


int main(){
    fastio;
    iofile();
    int t=1, tc=1;
    cin>>t;
    //cin.ignore();
    while(t--){
        //cout<<"Case "<<tc++<<": ";
        solve();
    }

    return 0;
}


Solution 2 (runtime: 233 ms):
#include <bits/stdc++.h>

using namespace std;



#define py cout << "YES" << endl

#define pn cout << "NO" << endl

#define ll long long

#define pb push_back

#define all(x) x.begin(), x.end()

#define fastfast()                    \

    ios_base::sync_with_stdio(false); \

    cin.tie(NULL);                    \

    cout.tie(NULL)



typedef vector<ll> vll;



// Greatest Common Divisor

ll gcd(ll a, ll b) {

    if (b == 0)

        return a;

    return gcd(b, a % b);

}



// Least Common Multiple of three numbers

ll findLCM(ll a, ll b, ll c) {

    ll GCD = gcd(a, b);

    ll lcm = (a * b) / GCD;

    GCD = gcd(lcm, c);

    lcm = (lcm * c) / GCD;

    return lcm;

}



// Function to separate elements in a and b that don't match

pair<vll, vll> sol(vll &a, vll &b) {

    ll i = 0, j = 0;

    ll n = a.size(), m = b.size();

    vll a1, b1;

    sort(all(a));

    sort(all(b));

    while (i < n && j < m) {

        while (i < n && a[i] < b[j]) a1.pb(a[i++]);

        while (i < n && j < m && a[i] == b[j]) i++, j++;

        while (i < n && j < m && b[j] < a[i]) b1.pb(b[j++]);

    }

    while (i < n) a1.pb(a[i++]);

    while (j < m) b1.pb(b[j++]);

    return {a1, b1};

}



// Divide each element into two parts: floor and ceil of half

vll divid(vll &v) {

    vll a;

    for (ll x : v) {

        if (x == 1) continue; // Skip further division of 1

        a.pb(x / 2);

        a.pb((x + 1) / 2);

    }

    sort(all(a));

    return a;

}



void solve() {

    ll n, m;

    cin >> n >> m;

    vll a(n), b(m);



    for (ll i = 0; i < n; i++) cin >> a[i];

    for (ll i = 0; i < m; i++) cin >> b[i];



    sort(all(a));

    sort(all(b));

    

    vll a1, b1;

    tie(a1, b1) = sol(a, b); // remove common elements



    b1 = divid(b1);



    if (a1 == b1) {

        py;

        return;

    }



    vll an = a1, bn = b1;



    for (ll i = 0; i < 32; i++) {

        if (bn.empty()) break;



        tie(an, bn) = sol(an, bn);



        if (an == bn) {

            py;

            return;

        }



        bn = divid(bn);

        if(bn.size()>an.size()){pn;return;}

    }



    pn;

}



int main() {

    fastfast();

    int t;

    cin >> t;

    while (t--) {

        solve();

    }

    return 0;

}