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

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

// JAY SHREE KRISHNA
// AUTHOR:- Solanki Nirmal Bhikhabhai

// ------------------------------------------------------------------------------------------------------------
#define hello ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ll long long
#define ld long double
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define pb push_back
#define pp pop_back
#define endl "\n"
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
// ------------------------------------------------------------------------------------------------------------

vector<ll> llToBin(ll n){
    vector<ll> ans;
    while(n!=0){
        ans.pb(n%2);
        n/=2;
    }
    reverse(all(ans));
    return ans;
}

vector<ll> isprime(1e6+1,1);
void sieve(int n){
    isprime[1]=0;
    for(ll i=2;i*i<1000000;i++){
        if(isprime[i]!=0){
            for(ll j=i*i;j<1000000;j+=i) isprime[j]=0;
        }
    }
}

void printvec(vector<ll> temp){
    for(ll i=0;i<temp.size();i++) cout<<temp[i]<<" ";
    cout<<endl;
}

void printmap(map<ll,ll> temp){
    for(auto it=temp.begin();it!=temp.end();it++) cout<<it->fi<<" "<<it->se<<endl;
}

ll ncr(ll n,ll r){
    ld sum=1;
    for(ll i=0;i<=r;i++) sum=sum*(n-r+i)/i;
    return (ll)sum;
}


// ------------------------------------------------------------------------------------------------------------
bool f(ll val, map<ll,ll>&mp)
{
    //cout<<val<<endl;
    if(mp[val]>0) 
    {
        mp[val]--;
        return true;
    }
    if(val==1) return false;
    ll v1=val/2,v2=val/2;
    if(val%2!=0) v2++;
    if(!f(v1,mp)) return false;
    if(!f(v2,mp)) return false;
    return true;
}
void solve(){
    ll n,m;		cin>>n>>m;
    vector<ll> a(n),b(m);
    for(ll i=0;i<n;i++) cin>>a[i];
    for(ll i=0;i<m;i++) cin>>b[i];

    map<ll,ll>mp;
    for(auto it:a) mp[it]++;
    bool flag=true;
    for(auto it:b)
    {
        if(!f(it,mp))
        {
            flag=false;
            break;
        }
    }
    for(auto it:mp) 
    {
        if(it.second>0)
        {
            flag=false;
            break;
        }
    }
    if(flag) yes;
    else no;
}

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

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

void solve()
{
	int n,m;
	cin>>n>>m;
	
	vector<int>a(n+1),b(m+1);
	
	map<int,int>mp;
	for(int i = 1; i <= n ; i++)
	{
		cin>>a[i];
		mp[a[i]]++;
	}
	
	priority_queue<int,vector<int>,greater<int>>q;
	
	for(int i = 1; i <= m ; i++)
	{
		cin>>b[i];
		//cout<<"b[i]="<<b[i]<<endl;
		if(mp[b[i]]>0)mp[b[i]]--;
		else 
		{
			q.push(b[i]);
		}
	}	
	//cout<<"->";

	while(!q.empty())
	{
		
		if(mp.empty())
		{
			cout<<"NO"<<endl;
			return ;
		}
		int t = q.top();

		q.pop();
		int t1,t2;
		t1 = t/2;
		t2 = t/2+(t%2);
		if(t1==0||t2==0)
		{
			//cout<<"3="<<endl;
			cout<<"NO"<<endl;
			return ;
		}
		
		if(mp[t1]>1)mp[t1]--;
		else if(mp[t1]==1)mp.erase(t1);
		else if(t1<mp.begin()->first)
		{
			//cout<<"1="<<endl;
			cout<<"NO"<<endl;
			return ;
		}
		else q.push(t1);

		if(mp[t2]>1)mp[t2]--;
		else if(mp[t2]==1)mp.erase(t2);
		else if(t2<mp.begin()->first)
		{
			//cout<<"2="<<endl;
			cout<<"NO"<<endl;
			return ;
		}
		else q.push(t2);
	}
	if(mp.begin()->second==0)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	
	return ;
}
int main()
{
	int t;
	cin>>t;
	
	while(t--)
	{
		solve();
	}
	return 0;
}