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

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

int main() {
    int t; 
    cin >> t;
    while (t--) {
        int n, m, add;   cin >> n >> m; 
        multiset<int> a; 
        vector<int> b(m); 
        
        for (int i = 0; i < n; i++) {
            cin >> add; 
            a.insert(add); 
        }
    
        for (int i = 0; i < m; i++) {
            cin >> b[i]; 
        }
    
        while (!b.empty()) {
            int ultimul = b.back();  
            b.pop_back(); 
            
            if (ultimul == 0) {
                a.insert(15);
                break;
            }
            
            if (a.count(ultimul)) {
                a.erase(a.find(ultimul)); 
                continue; 
            }
    
            b.push_back((ultimul + 1) / 2); 
            b.push_back(ultimul / 2);
        }
    
        if (a.empty()) {
            cout << "yes" << endl;
        } else {
            cout << "no" << endl;
        }
    }
}


Solution 2 (runtime: 390 ms):
#include<bits/stdc++.h>
using namespace std;
#ifdef ONLINE_JUDGE
#define debug(x)
#else
#define debug(x) cerr << #x <<"="; cerr<<x; cerr << endl;
#endif
//-----------------------------------------------------------------------------------------------------------------------------------------
#define int long long int
#define yes std::cout<<"YES"<<endl
#define no std::cout<<"NO"<<endl
#define FOR(i,c) for(int (i)=0;(i)<(c);(i)++)
#define pb push_back
#define pob pop_back
#define FORR(i,c) for(int (i)=(c);(i)>0;(i)--)
#define mod 1000000007
#define endl "\n"
#define min3(a,b,c) min(c,min(a,b))
#define min4(a,b,c,d) min(d,min(c,min(a,b)))
#define a_in(a,size)\
  FOR(i,size) cin>>a[i];
#define floop(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,a,b) for(int i=a;i>=b;i--)
#define s_in(s)\
        string s;\
        cin>>s;
#define print(x) cout<<x<<endl
#define vec_v vector<int> v
#define ff first 
#define sc second
#define vec_in(v,n)\
FOR(i,n){int x; cin>>x;v.pb(x);}
#define all(v) v.begin(),v.end()
#define maxi(v) *max_element(all(v));
#define mini(v) *min_element(all(v));
#define sum(v) acculumate(all(v),0ll);
#define removeDuplicates(v) v.resize(unique(v.begin(), v.end()) - v.begin());
int gcd(int a, int b){if (b == 0)return a;return gcd(b, a % b);} 
int lcm(int a, int b){return (a/gcd(a,b)*b);}
#define inf INT64_MAX

string decTobin(int n){string s="";int i = 0;while (n > 0) {s =to_string(n % 2)+s;n = n / 2;i++;}return s;}
int binTodecl(string n){string num = n;int dec_value = 0;int base = 1;int len = num.length();for(int i = len - 1; i >= 0; i--){if (num[i] == '1')dec_value += base;base = base * 2;}return dec_value;}
 
int n,m,k,l,g,h,i,j,q;

 //sort pair acc 2 second element //sort(v.begin(),v.end(),comparision)
bool comparision(const pair<int,int> &a,const pair<int,int> &b){ 
    return a.second<b.second; 
} 
char OR(char a, char b){
   char res;
    if(a=='1'||b=='1') res='1';
    else res='0';
  
  return res;
}
char XOR(char a,char b){
  if(a=='1'&&b=='1') return '0';
  else if(a=='0'&&b=='0') return '0';
  return '1';
}
//sieve()
 bool prime[100001];
void sieve(){
    FOR(i,100001) prime[i]=true;
    for (int p = 2; p * p <= 100000; p++) {
        if (prime[p] == true) {
            for (int i = p * p; i <= 100000; i += p)
                prime[i] = false;
        }
    } 
}
#define ll long long
int primeFactors(int n,int ans) 
{ 
    while (n % 2 == 0) 
    { 
        ans++;
        n = n / 2; 
    } 
    for (int i = 3; i <= sqrt(n); i = i + 2) 
    { 
        while (n % i == 0) 
        { 
            ans++;
            n = n / i; 
        } 
    } 
    if (n > 2) 
        ans++;
        return ans;
} 
int countSetBits( int n)
{
    int count = 0;
    while (n) {
        count += n & 1;
        n >>= 1;
    }
    return count;
}
// Returns factorial of n
long fact(int n)
{
      if(n==0)
      return 1;
    long res = 1;
    for (int i = 2; i <= n; i++)
        res = res * i;
    return res;
}
long nCr(int n, int r)
{
    return fact(n) / (fact(r) * fact(n - r));
}
// Function to calculate modular exponentiation
int fast_mul(int a, int b) {return ((a%mod)*(b%mod))%mod;}// keep mod to return power in mod
int power(int a, int b){
    if(b==0) return 1;
    int ans = power(a, b/2);
    ans = fast_mul(ans, ans);
    if(b%2){
        return fast_mul(ans, a);
    }
    return ans;
}
int stoint(string s){
    int n=s.length();
    int fact=1;
    int ans=0;
    FOR(i,n){
        ans*=10;
        ans+=(s[i]-'0');
    }
    return ans;
}



void solve(){
    int n,m;
    cin>>n>>m;
    vector<int> a,b;
    vec_in(a,n);
    vec_in(b,m);
    sort(all(a));
    sort(b.rbegin(),b.rend());
    map<int,int> mp;
    map<int,int>mpp;
    priority_queue<int> mh;
    FOR(i,m) {
       if(mpp[b[i]]==0){
        mh.push(b[i]);
       } mpp[b[i]]++;
    }
    FOR(i,n){
        mp[a[i]]++;
    }
    // cout<<1<<endl;
    while(mh.size()!=0){
        int k=mh.top();
        if(k==1) break;
        // debug(k);
        if(mp.find(mh.top())!=mp.end()){
             if(mpp[k]>mp[k]){
               if(mpp.find((int)(ceil(k*1.0/2)))==mpp.end()) mh.push((int)(ceil(k*1.0/2)));
               if(mpp.find(k/2)==mpp.end()) mh.push(k/2);
                mpp[(int)(ceil(k*1.0/2))]+=mpp[k]-mp[k];
                mpp[k/2]+=mpp[k]-mp[k];
                mpp[k]=mp[k];
             }
        }
        else{
            // cout<<i.ff<<endl;
            if(mpp.find((int)(ceil(k*1.0/2)))==mpp.end()) mh.push((int)(ceil(k*1.0/2)));
            if(mpp.find(k/2)==mpp.end()) mh.push(k/2);
            mpp[(int)(ceil(k*1.0/2))]+=mpp[k];
                mpp[k/2]+=mpp[k];
                mpp.erase(k);
        }
        mh.pop();
    }
    // for(auto i:mpp){
    //     cout<<i.ff<<" "<<i.sc<<endl;
    // }
    if(mp.size()!=mpp.size()){
        no;return;
    }
    FOR(i,n){
        if(mp[a[i]]!=mpp[a[i]]){
            no;
            return;
        }
    }
    yes;

    
}
    
signed main(){ 
  ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    
     int t;
     t=1;
     cin>>t;
    for(int i=1;i<=t;i++){
   solve();
     }
return 0;
}