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

Solution 1 (runtime: 343 ms):
#include<bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	long long t,n,m,i,x;
	cin>>t;
	while(t--){
		cin>>n>>m;
		multiset<long long> a;
		stack<long long> b;
		for(i=0;i<n;i++){
			cin>>x;
			a.insert(x);
		}
		for(i=0;i<m;i++){
			cin>>x;
			b.push(x);
		}
		while(!b.empty()){
			x=b.top();
			b.pop();
			if(a.find(x)!=a.end())
				a.erase(a.find(x));
			else if(x==1){
				b.push(x);
				break;
			}
			else{
				b.push(x/2);
				b.push((x+1)/2);
			}
		}
		cout<<(b.empty()&&a.empty()?"Yes\n":"No\n");
	}
	return 0;
}


Solution 2 (runtime: 796 ms):
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <complex>
#include <queue>
#include <set>
#include <unordered_set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <fstream>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> p32;
typedef pair<ll, ll> p64;
typedef pair<double, double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int>> vv32;
typedef vector<vector<ll>> vv64;
typedef vector<vector<p64>> vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
double eps = 1e-12;
#define forn(i, e) for (ll i = 0; i < e; i++)
#define forsn(i, s, e) for (ll i = s; i < e; i++)
#define rforn(i, s) for (ll i = s; i >= 0; i--)
#define rforsn(i, s, e) for (ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout << #x << " = " << x << ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 2e18
#define fast_cin()                    \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())

const int MOD = 1e9 + 7;
long long get_hash(string s)
{
    int n = s.length();
    long long h = 0;
    for (int i = 0; i < n; i++)
        h = (h * 31 + (s[i] - 'a' + 1)) % MOD;
    return h;
}

ll bin_power_mod(ll base, ll power, ll m)
{
    base %= m;
    ll res = 1;
    while (power > 0)
    {
        if (power & 1)
            res = res * base % m;
        base = base * base % m;
        power >>= 1;
    }
    return res;
}

ll modulo_inverse(ll base, ll mod)
{
    return bin_power_mod(base, mod - 2, mod);
}

void solve()
{
    ll n, m;
    cin >> n >> m;

    ll a[n], b[m];

    map<ll, ll> mpa, mpb;
    set<ll, greater<ll>> fqa, fqb;

    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        mpa[a[i]]++;
        fqa.insert(a[i]);
    }

    for (int i = 0; i < m; i++)
    {
        cin >> b[i];
        mpb[b[i]]++;
        fqb.insert(b[i]);
    }

    while (true)
    {
        if (fqa.empty() && fqb.empty())
        {
            cout << "Yes" << endl;
            return;
        }

        if (fqa.empty() || fqb.empty())
        {
            cout << "No" << endl;
            return;
        }

        ll vla = *fqa.begin();
        ll vlb = *fqb.begin();

        if (vla > vlb)
        {
            cout << "No" << endl;
            return;
        }

        if (vla == vlb)
        {
            ll mn = min(mpa[vla], mpb[vlb]);
            mpa[vla] -= mn;
            mpb[vlb] -= mn;

            if (mpa[vla] == 0)
                fqa.erase(vla);
            if (mpb[vla] == 0)
                fqb.erase(vla);
        }
        else
        {
            ll sa = vlb / 2;
            ll sb = vlb / 2;
            if (vlb % 2 != 0)
                sb++;

            mpb[sa] += mpb[vlb];
            mpb[sb] += mpb[vlb];
            mpb[vlb] = 0;

            fqb.insert(sa);
            fqb.insert(sb);

            fqb.erase(vlb);
        }
    }

    cout << "Yes" << endl;
}
int main()
{
    fast_cin();
    ll t;
    cin >> t;
    for (ll i = 1; i <= t; i++)
    {
        solve();
    }
    return 0;
}