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

Solution 1 (runtime: 452 ms):
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#include <chrono>
#include <random>
using namespace std;


// HASH UTILS.
struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return hash<long long>()(((long long)x.first)^(((long long)x.second)<<32));
  }
};

struct custom_hash {
    // A 64-bit splitmix-like function
    static uint64_t splitmix64(uint64_t x) {
        x ^= x >> 33;
        x *= 0xff51afd7ed558ccdULL;
        x ^= x >> 33;
        x *= 0xc4ceb9fe1a85ec53ULL;
        x ^= x >> 33;
        return x;
    }

    size_t operator()(uint64_t x) const {
        // A random seed based on the current time
        static const uint64_t FIXED_RANDOM =
            (uint64_t)std::chrono::steady_clock::now().time_since_epoch().count();
        return static_cast<size_t>(splitmix64(x + FIXED_RANDOM));
    }
};

// datatypes base.
#define ll long long int
#define ull unsigned long long int

// Actual constants
const ll INF = 1ll << 60;
const ll MOD = 998244353;
const int N = 100023;
const double eps = 1e-6;

// Loops.
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define inputv(arr,n) for(ll i=0;i<n;i++){ll value;cin>>value;arr.pb(value);}

// Utilities on collections.
#define sz(a) ((ll)(a).size())
#define len(a) ((ll)(a).length())
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair


// STL contractions.
#define vi vector <int>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define vb vector <bool>
#define lumap unordered_map<ll, ll, custom_hash>


// IO UTILS.
#define IOS { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define precise cout<<fixed<<setprecision(8)
#define nl cout<<"\n"
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"

#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)

// Math utils.
inline ll max(ll a,ll b) {return ((a>b)?a:b);}
inline ll min(ll a,ll b) {return ((a>b)?b:a);}
inline ll gcd(ll a ,ll b) {if(b==0) return a;a%=b;return gcd(b,a);}

// Power utils.
ll power(ll a,ll b) {ll res=1; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a;a=(a*a);}return res;}
ll modPower(ll a,ll b) {a%=MOD;ll res=1; assert(b>=0); for(;b;b>>=1){if(b&1)res=(res*a)%MOD;a=(a*a)%MOD;}return res;}
ll modInverse(ll a){return modPower(a,MOD-2);}
ll uint64_log2(uint64_t n)
{
  #define S(k) if (n >= (UINT64_C(1) << k)) { i += k; n >>= k; }

  ll i = -(n == 0); S(32); S(16); S(8); S(4); S(2); S(1); return i;

  #undef S
}


void solve()
{
  ll n, m, x;
  map<ll, ll> a, b;
  cin>>n>>m;
  rep(i, n) {
    cin>>x;
    a[x]++;
  }
  rep(i, m) {
    cin>>x;
    b[x]++;
  }
  ll moves = 0;
  while(moves < n - m && !b.empty()) {
    auto bit = b.rbegin();
    ll id = bit->first;
    // cout<<"processing id "<<id;nl;
    if(a.find(id) == a.end()) {
      b[id]--;
      if(b[id] == 0) b.erase(id);

      moves++;
      if(id == 1) {
        NO;
        return;
      }
      // cout<<"adding moves for element "<<id;nl;
      if(id%2 == 0) b[id/2] += 2;
      else b[(id-1)/2]+=1, b[(id+1)/2]+=1;

      continue;
    }

    x = min(a[id], b[id]);
    a[id]-=x;
    b[id]-=x;
    if(b[id] == 0) b.erase(id);
    if(a[id] == 0) a.erase(id);
  }
  // cout<<"moves is "<<moves;nl;
  // cout<<"a is \n";
  // for(auto x: a) cout<<x.first<<":"<<x.second<<" ";
  // nl;
  // cout<<"b is \n";
  // for(auto x: b) cout<<x.first<<":"<<x.second<<" ";
  // nl;
  if (a.size() != b.size()) {
    NO;
    return;
  }
  for(auto it: a) {
    if (b.find(it.first) == b.end() || a[it.first] != b[it.first]) {
      NO;
      return;
    }
  }
  YES;
}
int main()
{
    IOS;
    int T=1;
    cin>>T;
    int t=0;
    while(t++<T)
    {
        //cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}


Solution 2 (runtime: 374 ms):
#include "bits/stdc++.h"
using namespace std;

#define send {ios_base::sync_with_stdio(false);}
#define help {cin.tie(NULL);}
#define f first
#define s second
#define getunique(v) {sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end());}

using ll = long long;
using vl = vector<ll>;
using pl = pair<ll, ll>;

typedef long double ld;
typedef unsigned long long ull;

const string PAIR_LEFT = "(";
const string PAIR_RIGHT = ")";
const string IT_LEFT = "[";
const string IT_RIGHT = "]";
const string PAIR_SEP = ", ";
const string IT_SEP = ", ";

// benq - print any container + pair
template<typename T, typename = void> struct is_iterable : false_type {};
template<typename T> struct is_iterable<T, void_t<decltype(begin(declval<T>())),decltype(end(declval<T>()))>> : true_type {};
template<typename T> typename enable_if<is_iterable<T>::value&&!is_same<T, string>::value,ostream&>::type operator<<(ostream &cout, T const &v);
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << PAIR_LEFT << p.f << PAIR_SEP << p.s << PAIR_RIGHT; }
template<typename T> typename enable_if<is_iterable<T>::value&&!is_same<T, string>::value,ostream&>::type operator<<(ostream &cout, T const &v) {
    cout << IT_LEFT; 
    for (auto it = v.begin(); it != v.end();) {
        cout << *it;
        if (++it != v.end()) cout << IT_SEP;
    }
    return cout << IT_RIGHT;
}
template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p) {
    cin >> p.first;
    return cin >> p.second;
}

template<typename T> void debug(string s, T x) {cerr << "\033[1;34m" << s << "\033[0;32m = \033[35m" << x << "\033[0m\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {for (int i=0, b=0; i<(int)s.size(); i++) if (s[i] == '(' || s[i] == '{') b++; else
        if (s[i] == ')' || s[i] == '}') b--; else if (s[i] == ',' && b == 0) {cerr << "\033[1;34m" << s.substr(0, i) << "\033[0;32m = \033[35m" << x << "\033[31m | "; debug(s.substr(s.find_first_not_of(' ', i + 1)), args...); break;}}
template<typename T> void debug_nameless(T x) {cerr << "\033[35m" << x << "\033[0m\n";}
template<typename T, typename... Args> void debug_nameless(T x, Args... args) {cerr << "\033[35m" << x << "\033[31m | "; debug_nameless(args...);}

#define pr(...) debug(#__VA_ARGS__, __VA_ARGS__)
#define prs(...) debug_nameless(__VA_ARGS__)

mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 rng(61378913);
/* usage - just do rng() */

const ll mod = 1000000007;
// const ll mod = 998244353;
// ll mod;



ll n, m, q, k, l, r, x, y, z;
ll a[1000005];
ll b[1000005];
ll c[1000005];
string s, t;

ll ans = 0;




void solve(int tc = 0) {
	cin >> n >> m;
	
	map<ll, ll> mp;
	for (ll i = 0; i < n; i++) {
		cin >> a[i];
		++mp[a[i]];
	}
	priority_queue<ll> pq;
	for (ll i = 0; i < m; i++) {
		cin >> b[i];
		pq.push(b[i]);
	}
	
	while (pq.size()) {
        ll x = pq.top();
        pq.pop();
        
        if (mp[x] > 0) {
            --mp[x];
            if (mp[x] == 0) mp.erase(x);
			continue;
        }
		--n;
		if (n < m) break;
		pq.push(x / 2);
		pq.push((x + 1) / 2);
	}
	
	if (n == m) {
		cout << "YES\n";
	} else {
		cout << "NO\n";
	}
}

int main() {
	send help
	
	cout << setprecision(15) << fixed;
	cerr << setprecision(4) << fixed;
	
    int tc = 1;
	cin >> tc;
	for (int t = 0; t < tc; t++) {
		// pr(t); prs(string(50, '-'));
		solve(t);
		// prs(string(50, '-') + "\n");
	}
}