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

Solution 1 (runtime: 327 ms):
#include<bits/stdc++.h>
using namespace std;
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define gcd(a,b) __gcd(a,b)
#define MOD 1000000007
#define MOD1 998244353
#define INF 1e18
#define nline "\n"
#define pub push_back
#define pob pop_back

#define ff first
#define ss second
#define PI 3.141592653589793238462
#define set_bits __builtin_popcountll//TO FIND NUMBER OF SET BITS __builtin_popcountll(n);-->>set_bits(n);
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
ll lcm(ll a,ll b)
{
return (a*b)/__gcd(a,b);
}
ll LOWERBOUND(vector<ll> &vp,ll n,ll search)
{
ll ans=-1;
ll l=0,r=n-1;
while(l<=r)
{
ll mid=l+(r-l)/2;
if(vp[mid]<=search)
{
ans=mid;
l=mid+1;
}
else
r=mid-1;
}
return ans+1;

}
ll UPPERBOUND(vector<ll> &vp,ll n,ll search)
{
ll ans=-1;
ll l=0,r=n-1;
while(l<=r)
{
ll mid=l+(r-l)/2;
if(vp[mid]>=search)
{
ans=mid;
r=mid-1;
}
else
l=mid+1;
}
return ans+1;

}
int ispal(string &s)
{
string s1=s;
reverse(s1.begin(),s1.end());
if(s1==s)
return 1;
return 0;
}
void div(ll &a,ll &b,ll index1,ll index2,vector<pair<ll,ll>> &ans)
{
while(a!=b&&(a!=2||b!=2))
{
if(a<b)
{
b=(a+b-1)/a;
ans.push_back({index2,index1});
}
else
{
a=(a+b-1)/b;
ans.push_back({index1,index2});
}
}
}
ll mex(vector<ll> vp)
{
sort(vp.begin(),vp.end());
ll mex1=0;
ll n=vp.size();
for(ll ind=0;ind<n;ind++)
{
if(vp[ind]==mex1)
{
mex1+=1;
}

}
return mex1;
}
ll log_a_to_base_b(ll a, ll b)
{
return log2(a) / log2(b);
}

ll toggleKthBit(ll n, int k)
{
//0-th indexed
return (n ^ (1ll << (k)));
}
bool kthbitset(ll n,int k)
{
return ((n>>k)&1);
}
bool iscomp(ll n){
for(int i=2;i<=sqrt(n);i++){
if(n%i==0)
return 1;
}
return 0;

}

int compute(int x,int y,set<pair<int,int>> &vis,vector<vector<char>> &a,int n,int m){

if( x<0||y<0||x>=n||y>=m)
return 0;
if(vis.find({x,y})!=vis.end())
{
return 0;
}
if(a[x][y]!='?')
{
char move=a[x][y];
vis.insert({x,y});
if(move=='U')
{
return 1+compute(x-1,y,vis,a,m,n);
}
else if(move=='R')
{
return 1+compute(x-1,y,vis,a,m,n);
}
else if(move=='D')
{
return 1+compute(x-1,y,vis,a,m,n);
}
else if(move=='L')
{
return 1+compute(x-1,y,vis,a,m,n);
}
}
else
{
//when we go up

//when we go right

//when we go down

//when we go left


}

}

void dfs(int flag,ll val,map<ll,vector<ll>> &m,set<ll> &s1,set<ll> &s2,int n,bool done[])
{
if(done[val]){
return;
}
done[val]=1;
if(flag==0)
{
if(s1.find(val)==s1.end())
{
s1.insert(val);
for(auto it:m[val])
{
dfs(1,it,m,s1,s2,n,done);
}
}

}
else
{
if(s2.find(val)==s2.end())
{
s2.insert(val);
for(auto it:m[val])
{
dfs(0,it,m,s1,s2,n,done);
}
}  
}


}

void solve() 
{
 ll n,m;
 cin>>n>>m;
 ll a[n],b[m];
 for(int i=0;i<n;i++)
   cin>>a[i];  
 for(int i=0;i<m;i++)
   cin>>b[i];
 
 sort(a,a+n);
 sort(b,b+m);
 ll count=n;
 map<ll,ll> mp;
 for(auto it:a){
   mp[it]++;
 }
 
 
 multiset<ll> s;
 for(int i=0;i<m;i++){
   if(mp[b[i]]){
      mp[b[i]]--;
      count--;
   }
   else{
      s.insert(b[i]);
   }
 }
 //cout<<(n-count)+(s.size())<<nline;
 while(s.size() && count&& (n-count)+(s.size())<=n){
      //return;
      auto it=s.find(*s.rbegin());   
      ll num=*it;
      if(mp[num]){
         mp[num]--;
         count--;
         s.erase(it);
      }
      else{
         s.insert((num+1)/2);
         s.insert(num/2);
         s.erase(it);
         
      }
}
//cout<<count<<nline;
if(count==0 && s.size()==0 ){
   cout<<"Yes\n";
}
else
cout<<"No\n";





}
int main() 
{


ios_base::sync_with_stdio(0);
cin.tie(0);

#ifndef ONLINE_JUDGE
//for getting input from input.txt
freopen("input.txt","r",stdin);
//for getting output from output.txt
freopen("output.txt","w",stdout);
#endif
//generatenos("",0,5);
int t=1;

cin>>t;              

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


}

Solution 2 (runtime: 656 ms):
// Problem: D. Kevin and Numbers
// Contest: Codeforces - IAEPC Preliminary Contest (Codeforces Round 999, Div. 1 + Div. 2)
// URL: https://codeforces.com/contest/2061/problem/D
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
using namespace std;
#define boost                    \
	ios::sync_with_stdio(false); \
	cin.tie(0);                  \
	cout.tie(0)

///-----new feature----///
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
///-end of new feature-///

#define scan(x)                                                                   \
	do                                                                            \
	{                                                                             \
		while ((x = getchar()) < '0')                                             \
			;                                                                     \
		int _;                                                                    \
		for (x -= '0'; '0' <= (_ = getchar()); x = (x << 3) + (x << 1) + _ - '0') \
			;                                                                     \
	} while (0)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x.size())
#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define dbg(x) cerr << "  - " << #x << ": " << x << endl;
#define dbgp(x) cerr << "  - " << #x << ": " << x.fi << " , " << x.se << endl;
#define dbg2(x, y) cerr << "  - " << #x << ": " << x << "\t\t" << #y << ": " << y << endl;
#define dbgv(v, n)                                                      \
	cerr << #v << " : " << "\n";                                        \
	for (int i = 0; i < n; i++)                                         \
		cerr << "\t" << #v << "[" << i << "]" << " : " << v[i] << "\n"; \
	cerr << endl;
#define sep() cerr << "--------------------" << endl;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, b, a) for (int i = (b) - 1; i >= (a); i--)
#define GO(c, itr) for (auto itr = (c).begin(); itr != (c).end(); ++itr)

#define nl "\n"
#define YES cout << "YES" << nl
#define NO cout << "NO" << nl
#define yes cout << "yes" << nl
#define no cout << "no" << nl
#define Yes cout << "Yes" << nl
#define No cout << "No" << nl
#define pyprint(x) cout << x << nl
#define errprint(x) cerr << x << nl

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
const ll mod = 1e9 + 7;
const ll inf = 1e18;

//---> Short Data Structures:
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // aka indexed_set

template <typename T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;
// ordered_set<int> s;
// s.insert(1);
// s.order_of_key(3);
// s.find_by_order(1);
// s.find(1);

//---> Graph :
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

//---> Number Theory :
ll gcd(ll a, ll b)
{
	while (b)
	{
		swap(a, b);
		b %= a;
	}
	return (a);
}
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
ll po2(ll b, ll e)
{
	if (e == 0)
		return 1;
	ll res = 1;
	while (e > 1)
	{
		if (e % 2)
			res = (res * b) % mod;
		e /= 2;
		b = (b * b) % mod;
	}
	return (res * b) % mod;
}
ll modInverse(ll a) { return po2(a, mod - 2); }
bool sortFirst(const pair<ll, ll> &a, const pair<ll, ll> &b)
{
	if (a.first == b.first)
	{
		return a.second > b.second;
	}
	return a.first > b.first;
}

void solve() {
    ll n, m;
    cin >> n >> m;
    vector<ll> a(n), b(m);
    map<ll, int> mpa, mpb;

    // Read input and count occurrences
    for (ll i = 0; i < n; i++) {
        cin >> a[i];
        mpa[a[i]]++;
    }
    for (ll j = 0; j < m; j++) {
        cin >> b[j];
        mpb[b[j]]++;
    }

    // Remove common elements from both maps
    for (auto it : mpa) {
        if (mpb[it.first] != 0) {
            int mn = min(mpa[it.first], mpb[it.first]);
            mpa[it.first] -= mn;
            mpb[it.first] -= mn;
        }
    }

    vector<ll> aa, bb;
    for (auto it : mpa) {
        for (int i = 0; i < it.second; i++) {
            aa.push_back(it.first);
        }
    }
    priority_queue<ll>q;
    for (auto it : mpb) {
        for (int i = 0; i < it.second; i++) {
            q.push(it.first);
        }
    }

    sort(aa.begin(), aa.end());
    sort(bb.begin(), bb.end());

    ll ans = 0;
    bool t = false;
    vector<int> vis(bb.size(), 0);
	int op = n-m;
    while(!q.empty()&&op>0){
    	ll nb =q.top();
    	q.pop();
    	if(nb%2==0){
    		if(mpa[nb/2]>=2){
    			mpa[nb/2]-=2;
    		}else{
    			if(mpa[nb/2]>=1){
    				mpa[nb/2]-=1;
    				q.push(nb/2);
    			}else{
    				q.push(nb/2);
    				q.push(nb/2);
    			}
    		}
    	}else{
    		if(mpa[nb/2]>=1&&mpa[nb/2+1]>=1){
    			mpa[nb/2]-=1;
    			mpa[nb/2+1]-=1;
    		}else if(mpa[nb/2]>=1){
    			mpa[nb/2]--;
    			q.push(nb/2+1);
    		}else if(mpa[nb/2+1]>=1){
    			mpa[nb/2+1]--;
    			q.push(nb/2);
    		}else{
    			q.push(nb/2);
    			q.push(nb/2+1);
    		}
    	}
    	op--;
    }
    if(q.empty()){
    	for(auto it:mpa){
    		if(it.second>0){
    			cout<<"NO"<<endl;
    			return;
    		}
    	}
    	cout<<"YES"<<endl;
    	return;
    }
    cout<<"NO"<<endl;
}

int main()
{
	boost;

	int t = 1;
	cin >> t;
	while (t--)
		solve();
	return 0;
}