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

Solution 1 (runtime: 749 ms):
#pragma GCC optimize("O3,unroll-loops")
#include<bits/stdc++.h>
 
using namespace std;
using namespace chrono;
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD 1000000007
#define MOD1 998244353
#define INF 1e18
#define nl '\n'
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ff first
#define ss second
#define PI 3.141592653589793238462
#define set_bits __builtin_popcountll
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define clr(x) memset(x, 0, sizeof(x))
#define pqt priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>
 
#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x<<" "; _print(x); cerr << endl;
#else
#define debug(x);
#endif
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
 
void _print(ll t) {cerr << t;}
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(lld t) {cerr << t;}
void _print(double t) {cerr << t;}
void _print(ull t) {cerr << t;}
 
template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}
#define int long long
 
 
/*..............................................................................................................................................................................................................................................................*/
ll gcd(ll a, ll b) {if (b > a) {return gcd(b, a);} if (b == 0) {return a;} return gcd(b, a % b);}
ll expo(ll a, ll b, ll mod) {ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;}
void extendgcd(ll a, ll b, ll*v) {if (b == 0) {v[0] = 1; v[1] = 0; v[2] = a; return ;} extendgcd(b, a % b, v); ll x = v[1]; v[1] = v[0] - v[1] * (a / b); v[0] = x; return;} //pass an arry of size1 3
ll mminv(ll a, ll b) {ll arr[3]; extendgcd(a, b, arr); return arr[0];} //for non prime b
ll mminvprime(ll a, ll b) {return expo(a, b - 2, b);}
bool revsort(ll a, ll b) {return a > b;}
ll combination(ll n, ll r, ll m, ll *fact, ll *ifact) {ll val1 = fact[n]; ll val2 = ifact[n - r]; ll val3 = ifact[r]; return (((val1 * val2) % m) * val3) % m;}
void google(int t) {cout << "Case #" << t << ": ";}
vector<ll> sieve(int n) {int*arr = new int[n + 1](); vector<ll> vect; for (int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for (int j = 2 * i; j <= n; j += i)arr[j] = 1;} return vect;}
ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;}
ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;}
ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;}
ll mod_div(ll a, ll b, ll m) {a = a % m; b = b % m; return (mod_mul(a, mminvprime(b, m), m) + m) % m;}  //only for prime m
ll phin(ll n) {ll number = n; if (n % 2 == 0) {number /= 2; while (n % 2 == 0) n /= 2;} for (ll i = 3; i <= sqrt(n); i += 2) {if (n % i == 0) {while (n % i == 0)n /= i; number = (number / i * (i - 1));}} if (n > 1)number = (number / n * (n - 1)) ; return number;} //O(sqrt(N))
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll getRandomNumber(ll l, ll r) {return uniform_int_distribution<ll>(l, r)(rng);} 
/*..............................................................................................................................................................................................................................................................*/




void solve(){

    int n,m;
    cin>>n>>m;

    multiset<ll> a;
    vector<ll> b;

    for(int i=0;i<n;i++){
        ll num;
        cin>>num;

        a.insert(num);
    }

    for(int j=0;j<m;j++){
        ll num;
        cin>>num;

        b.pb(num);
    }

    sort(b.begin(),b.end());

    priority_queue<ll,vector<ll>,greater<ll>> pq;

    bool flag = true;

    for(int i=0;i<m;i++){
        ll num = b[i];
        pq.push(num);

        while(!pq.empty()){
            ll ele = pq.top();
            pq.pop();

            auto it = a.find(ele);


            if(it==a.end()){
                if(ele == 1 ){
                    flag = false;
                    break;
                }

                pq.push((ele+1)/2);
                pq.push(ele/2);
            }

            else{
                a.erase(it);
            }
        }

        if(flag== false)break;

    }

    if(a.size()==0 && flag){
        cout<<"YES"<<"\n";
    }
    else{
        cout<<"NO"<<"\n";
    }



}

signed main() {
    int tt=1;
    cin>>tt;

    while(tt--){
    	solve();
    }
}

Solution 2 (runtime: 359 ms):
#include <iostream>

#include <algorithm>

#include <vector>

#include <map>

#include <list>

#include <set>

#include <queue>

#include <bits/stdc++.h>

#define ll long long

#define int long long

#define pb push_back

#define ppb pop_back

#define mp make_pair

using namespace std;

using vpi = vector<pair<int, int>>;

using pi = pair<int, int>;

using vi = vector<int>;

using vvi = vector<vector<int>>;

#define ff first

#define ss second

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

#define sz(x) (int)(x).size()

const int inf = 9e18;

const int mod = 1e9 + 7;

const int NUM = 1000030;

const int N = 10000000;

#define DEBUG(x) cerr << #x << ": " << x << '\n'

template <typename T, typename Y>

istream &operator>>(istream &is, pair<T, Y> &p)

{

    is >> p.first >> p.second;

    return is;

}

template <typename T, typename Y>

ostream &operator<<(ostream &os, pair<T, Y> p)

{

    os << p.first << ' ' << p.second << ' ';

    return os;

}

template <typename T>

istream &operator>>(istream &is, vector<T> &v)

{

    for (auto &i : v)

        is >> i;

    return is;

}

template <typename T>

ostream &operator<<(ostream &os, vector<T> v)

{

    for (auto &i : v)

        os << i << ' ';

    return os;

}

vector<int> lp, sieve;

vector<int> pr;

vector<int> power;

vector<int> fact;

void initpow(int x)

{

    power.resize(NUM);

    power[0] = 1;

    for (int i = 1; i < NUM; i++)

    {

        power[i] = (power[i - 1] * (x % mod)) % mod;

    }

}

void initFactorial()

{

    fact.resize(NUM);

    fact[0] = 1;

    for (int i = 1; i < NUM; i++)

    {

        fact[i] = (fact[i - 1] * i) % mod;

    }

}

void calc_sieve()

{

    sieve.resize(NUM + 1, 0);

    for (int x = 2; x <= NUM; x++)

    {

        if (sieve[x])

            continue;

        for (int u = x; u <= NUM; u += x)

        {

            sieve[u] = x;

        }

    }

}

void primefactor()

{

    lp.resize(N + 1, 0);

    for (int i = 2; i <= N; ++i)

    {

        if (lp[i] == 0)

        {

            lp[i] = i;

            pr.push_back(i);

        }

        for (int j = 0; j < (int)pr.size() && pr[j] <= lp[i] && i * pr[j] <= N; ++j)

            lp[i * pr[j]] = pr[j];

    }

}

int binpow(int a, int b)

{

    int res = 1;

    while (b > 0)

    {

        if (b & 1)

            res = res * a;

        a = a * a;

        b >>= 1;

    }

    return res;

}

int binpow(int a, int b, int mod)

{

    int res = 1;

    while (b > 0)

    {

        if (b & 1)

            res = (res * a) % mod;

        a = (a * a) % mod;

        b >>= 1;

    }

    return res % mod;

}

int gcd(int a, int b)

{

    if (b == 0)

        return a;

    else

        return gcd(b, a % b);

}

int lcm(int a, int b)

{

    return ((a / gcd(a, b)) * b);

}

int inversemod(int a, int mod)

{

    return binpow(a, mod - 2, mod);

}

int divmod(int a, int b, int c)

{

    return ((a % c) * inversemod(b, c)) % c;

}

int combination(int n, int k)

{

    if (k > n)

        return 0;

    int p1 = (fact[n] * inversemod(fact[k], mod)) % mod;

    int p2 = (1 * inversemod(fact[n - k], mod)) % mod;

    return (p1 * p2) % mod;

}

void solve()

{

     int n,m;

     cin>>n>>m;

     multiset<int,greater<int>> a,b;

     int suma=0,sumb=0;

     for(int i=0 ; i<n ; i++){

        int x ;

        cin>>x;

        suma+=x;

        a.insert(x);

     }

     for(int i=0 ; i<m ; i++){

        int x ;

        cin>>x;

        sumb+=x;

        if(a.find(x)!=a.end()){

            a.erase(a.find(x));

        }

        else{

            b.insert(x);

        }

     }

     if(suma!=sumb){

        cout<<"No"<<endl;

        return ;

     }

     while(!b.empty() && !a.empty() && a.size()>=b.size() && *a.begin()<=*b.begin()){

        int x =*b.begin();

        b.erase(b.begin());

        if(x==*a.begin()){

            a.erase(a.begin());

        }

        else{

            b.insert(x/2);

            b.insert((x+1)/2);

        }



     }

     if(b.empty() && a.empty()){

        cout<<"Yes"<<endl;

     }

     else{

        cout<<"No"<<endl;

     }





}

signed main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    int t = 1;

    cin >> t;

    while (t--)

        solve();

    return 0;

}