Problem: 2061D - Kevin and Numbers
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 6):
#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
*/

Submission (verdict: Accepted):
#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
*/