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

Solution 1 (runtime: 749 ms):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>

// const int M=1e9+7;
// const int N=2e5+10;
// ll dppower[N];
// ll segtree[2*N];

// ll findroot(ll n){
// 	ll low=1;
// 	ll high=n;
// 	while(high-low>1){
// 		ll mid=low+(high-low)/2;
// 		if(mid*mid==n) return mid;
// 		if(mid*mid>n) high=mid;
// 		else low=mid;
// 	}
// 	return low;
// }

// ll powerll(ll x,ll y){
// 	ll temp;
// 	if(dppower[y]!=0) return dppower[y];
//     if (y == 0)
//         return 1LL;
//     temp = powerll(x, y / 2);
//     if (y % 2 == 0)
//         return dppower[y]=(temp * temp)%M;
//     else
//         return dppower[y]=((x%M) * ((temp * temp)%M))%M;
// }

// void buildsegtree(vector<int>& vec)  
// {
// 	int n=vec.size();
//     // insert leaf nodes in tree 
//     for (int i=0; i<n; i++)     
//         segtree[n+i] = vec[i]; 
      
//     // build the tree by calculating parents 
//     for (int i = n - 1; i > 0; --i)      
//         segtree[i] = segtree[i<<1] + segtree[i<<1 | 1];     
// }

// // function to update a tree node 
// void updateTreeNode(int p, int value, int n)  
// {  
//     // set value at position p 
//     segtree[p+n] = value; 
//     p = p+n; 
      
//     // move upward and update parents 
//     for (int i=p; i > 1; i >>= 1) 
//         segtree[i>>1] = segtree[i] + segtree[i^1]; 
// } 

// // function to get sum on interval [l, r) 
// int querysegtree(int l, int r, int n)  
// {  
//     int res = 0; 
      
//     // loop to find the sum in the range 
//     for (l += n, r += n; l < r; l >>= 1, r >>= 1) 
//     { 
//         if (l&1)  
//             res += segtree[l++]; 
      
//         if (r&1)  
//             res += segtree[--r]; 
//     } 
      
//     return res; 
// }

//---------------------------------------------------------------------
void check(int f,int s,int ctf,int cts,map<int,int>& a){

	
	if(s==0){
		a[0]++;
		return;
	}

	int dctf=ctf;
	ctf=max(0,ctf-a[f]);
	a[f]=max(0,a[f]-dctf);

	int dcts=cts;
	cts=max(0,cts-a[s]);
	a[s]=max(0,a[s]-dcts);

	map<int,int> topass;
	bool rec=false;
	if(ctf>0){
		int fs=f>>1;
		int ff=f-fs;
		topass[fs]+=ctf;
		topass[ff]+=ctf;
		rec=true;
	}
	if(cts>0){
		int ss=s>>1;
		int sf=s-ss;
		topass[ss]+=cts;
		topass[sf]+=cts;
		rec=true;
	}

	if(!rec) return;

	vector<pii> param;
	for(auto it:topass){
		param.push_back({it.first,it.second});
	}

	if(param.size()==1){
		int pf=param[0].first;
		int cps=param[0].second / 2;
		int cpf=param[0].second - cps;
		check(pf,pf,cpf,cps,a);
	}
	else{
		int pf=param[1].first;
		int ps=param[0].first;
		int cps=param[0].second;
		int cpf=param[1].second;
		check(pf,ps,cpf,cps,a);
	}
}
void solve(){
	int n,m; cin>>n>>m;
	map<int,int> a;
	ll sum=0;
	for(int i=0;i<n;i++){
		int temp;
		cin>>temp;
		sum+=1LL*temp;
		a[temp]++;
	}
	vector<int> b;
	for(int i=0;i<m;i++){
		int temp;
		cin>>temp;
		sum-=1LL*temp;
		if(a[temp]>0) a[temp]--;
		else b.push_back(temp);
	}
	if(sum != 0){
		cout<<"No"<<endl;
		return;
	}

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

	m=b.size();

	for(int i=0;i<m;i++){
		int second=b[i]>>1;
		int first=b[i]-second;
		check(first,second,1,1,a);
		if(a[0]>0){
			cout<<"No"<<endl;
			return;
		}
	}
	cout<<"Yes"<<endl;
}

int main(){
	int t; cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

Solution 2 (runtime: 202 ms):
#include <bits/stdc++.h>



#define pb push_back

#define eb emplace_back

#define all0(a) a.begin(), a.end()

#define all1(a) a.begin() + 1, a.end()

#define int long long

using namespace std;

typedef long long LL;

typedef pair<int, int> PII;

typedef pair<double, int> PDI;

const int N = 2e5 + 10, INF = 0x3f3f3f3f3f3f3f3f, MOD = 998244353, mod = 1e9 + 7;



void solve() {

    int n, m;

    cin >> n >> m;

    priority_queue<int> a, b;

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

        int x;cin >> x;

        a.push(x);

    }

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

        int x;

        cin >> x;

        b.push(x);

    }

    while(a.size()){

        if(b.empty() || b.size() > a.size()){

            cout << "No\n";

            return;

        }

        int x = b.top();

        b.pop();

        if(x < a.top()){

            cout << "No\n";

            return;

        }

        if(x == a.top())    a.pop();

        else{

            b.push(x / 2);

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

        }

    }

    if(b.size())    cout << "No\n";

    else cout << "Yes\n";

}

signed main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr), cout.tie(nullptr);

    // freopen("in.txt", "r", stdin);

    // freopen("out.txt", "w", stdout);

    int T = 1;

    cin >> T;

    while (T--) {

        solve();

    }

    return 0;

}