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

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

int main() {
	
	int t;
	cin>>t;
	
	while(t--){
	    
	  int n,m;
	  cin>>n>>m;
	  
	  multiset<int> a;
	  multiset<int> b;
	  
	  for(int i=0;i<n;i++){
	      int x;
	      cin>>x;
	      a.insert(x);
	  }
	  
	  for(int i=0;i<m;i++){
	      int x;
	      cin>>x;
	      b.insert(x);
	  }
	  
	  bool cc = 1;
	  
	  int op = n - m;
	  
	  while(op && a.size() && b.size()){
	      
	      int x = *(a.rbegin());
	      
	      int y = *(b.rbegin());
	      
	      if(x==y){
	          
	          a.erase(a.find(x));
	          b.erase(b.find(x));
	          
	      }
	      else{
	          
	           op--;
	           b.erase(b.find(y));
	           b.insert(y/2);
	           b.insert((y+1)/2);
	           
	      }
	      
	  }
	  
	  while(a.size() && b.size()){
	      
	      int x = *(a.rbegin());
	      
	      int y = *(b.rbegin());
	      
	      if(x==y){
	          
	          a.erase(a.find(x));
	          b.erase(b.find(x));
	          
	      }
	      else{
	          break;
	      }
	      
	  }
	  
	  if(a.size() or b.size()){
	      cc = 0;
	  }
	  if(cc){
	      
	      cout<<"YES"<<endl;
	      
	  }
	  else{
	      
	      cout<<"NO"<<endl;
	      
	  }
	   
	}

}


Solution 2 (runtime: 406 ms):
#include<bits/stdc++.h>
//#define in freopen ("input.txt", "r", stdin);
//#define out freopen("output.txt", "w", stdout);
#define ll long long
#define FILE1
#define yes cout<<"YES\n";
#define no cout<< "NO\n";
const int  val = 2e5+6;
const long long mod=1e9+7;
const long long INF=1e16+7;
ll binpow(ll x , ll n){
    ll ans = 1;
    while(n > 0){
        if(n % 2){
            n--;
            ans = ans * x % mod;
        }else {
        n /= 2;
        x = x * x % mod;
        }
    }
    return ans;
}
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;

using namespace std;

long long mx=0;
long long p[val],w[val];
long long l[val],r[val],s[val];
int shef(int x){
   return (x==p[x] ? x : p[x] = shef(p[x]));
}
map<long long,long long> mp;
bool ans=true;
void join(int x , int y){
    x=shef(x);
    y=shef(y);
    if(x==y){
        return;
    }
    if(w[x]<w[y]){
        swap(x,y);
    }
    w[x]+=w[y];
    mx=max(mx,w[x]);
    p[y]=x;

}
void rec(long long x){
	if(!ans){
		return;
	}
	
	if(mp[x]>0){
		mp[x]--;
		return;
	}
	if(x==1){
		ans=false;
		return;
	}
	rec(x/2);
	rec(x/2+x%2);
}
long long a[val],b[val];
void solve(){
	int n,m;
	cin>>n>>m;
	mp.clear();
	long long sum=0,sum1=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		sum+=a[i];
		mp[a[i]]++;
	}
	ans=true;
	for(int i=0;i<m;i++){
		cin>>b[i];
		sum1+=b[i];	
	}
	if(sum!=sum1){
		cout<< "NO\n";
		return;
	}
	for(int i=0;i<m;i++){
		
		rec(b[i]);
	}
	if(ans==false){
		cout<< "NO\n";
	}
	else{
		cout<< "YES\n";
	}
}
int main ()
{


    #ifdef FILE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    ios::sync_with_stdio(0);
    //cin.tie(0);
    long long t;
    cin>>t;
    while(t--){
        solve ();
    }
}





/*8 6
3 2 5
1 2 5
3 2 5
2 4 7




2 1 2
3 1 7
*/