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 vl vector<long long>
#define rep(j,b) for((j)=0;(j)<(b);(j)++)
#define Y cout<<"YES\n";
#define N cout<<"NO\n";
#define all(v) (v).begin(), (v).end() 
#define Sort(v) sort(all(v))
#define nl cout<<endl;


bool f(ll k, map<ll,ll> &mp)
{
    if(mp[k]>0)
    {
        mp[k]--; return true;
    }
    ll x=k/2, y=(k+1)/2;
    if(x<1) return false;
    return f(x,mp) && f(y,mp); 
}

vl input_vec(ll n) { ll i,a; vl vec; rep(i,n) { cin>>a; vec.push_back(a); } return vec; }

void solve()
{
    ll n,i,m; cin>>n>>m;
    vl vec=input_vec(n);
    vl v=input_vec(m);
    map<ll,ll> mp;
    rep(i,n) mp[vec[i]]++;
    rep(i,m)
    {
        if(f(v[i],mp)) continue;
        N return;
    }
    for(auto it:mp)
    {
        if(it.second!=0) { N return;}
    }
    Y 

}

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

Solution 2 (runtime: 780 ms):
#include <bits/stdc++.h>
#define int long long
#define float long double
#define pp pair<int, int>
#define tp tuple<int, int, int>
#define mtp make_tuple
#define mp make_pair
using namespace std;
// using lf = __float128;
// using ld = __int128;
// float pi = 3.141592653589793238462643383279502884197169399375105Q;
int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};
int ddx[8] = {0, 0, 1, -1, 1, 1, -1, 1}, ddy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

void er(map<int, int> &dict, int x)
{
    if (dict[x] == 0)
        dict.erase(x);
}

map<int, int> adict, bdict;
int go(int bi)
{
    if (bi < adict.begin()->first)
        return 1;

    if (adict.count(bi))
    {
        adict[bi]--;
        er(adict, bi);
        return 0;
    }

    if (bi == 1)
        return 1;

    if (bi % 2 == 0)
    {
        int x = bi >> 1;

        if (adict.count(x) && adict[x] >= 2)
        {
            adict[x] -= 2;
            er(adict, x);
            return 0;
        }
        if (go(x))
            return 1;
        return go(x);
    }
    else
    {
        int hol = bi + 1 >> 1, jjak = bi + 1 >> 1;
        if (hol % 2 == 0)
            hol--;
        else
            jjak--;

        int ret = 0;
        if (adict.count(jjak) == 0)
        {
            ret = go(jjak);
        }
        else
        {
            adict[jjak]--;
            er(adict, jjak);
        }
        if (ret)
            return 1;
        return go(hol);
    }
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int tt;
    cin >> tt;
    while (tt--)
    {
        adict.clear();
        bdict.clear();
        int n, m;
        cin >> n >> m;
        vector<int> arr(n), brr(m);
        for (int i = 0; i < n; i++)
        {
            cin >> arr[i];
            adict[arr[i]]++;
        }
        for (int i = 0; i < m; i++)
        {
            cin >> brr[i];
            bdict[brr[i]]++;
        }

        int flag = 0;
        for (int i = 0; i < m; i++)
        {
            flag = max(flag, go(brr[i]));
            bdict[brr[i]]--;
            er(bdict, brr[i]);
        }

        if (adict.size() != 0 || bdict.size() != 0)
            flag = 1;

        if (flag)
        {
            cout << "No";
            cout << '\n';
            continue;
        }

        if (flag)
        {
            cout << "No";
            cout << '\n';
            continue;
        }
        cout << "Yes\n";
    }
    return 0;
}