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

Previous submission (verdict: Wrong answer on test 3):
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#define ENDL '\n'
#define MAXN 100001
#define mod 998244353
#define ft first
#define sc second
using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef long double ld;
typedef tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, tree_order_statistics_node_update>ordered_set;

ll n, m, k;

ll binpow(ll a, ll b){
	if(b==0)return 1;
	if(b==1)return a;
	ll num=binpow(a,b>>1)%mod, p=1;
	if(b%2)p=a;
	ll part=(num*num)%mod;
	return (part*p)%mod;
}

const int mov_f[]={-1,0,1, 0};
const int mov_c[]={0,-1,0, 1};

void solve(){
  cin>>n;
  /*vll v(n);

  ll a=0, b=0;
  map<ll, ll>mp;
  for(int i=0; i<n; i++){
     cin>>v[i];
     mp[v[i]]++;
  }

  vll fact(n+1);
  fact[0]=1;
  for(int i=1; i<=n; i++)fact[i]=(fact[i-1]*i)%mod;

  ll dp[n][2];
  for(int i=0; i<n; i++)dp[i][0]=dp[i][1]=0;
  dp[0][0]=1;
  ll c=0;

  set<ll>s1, s0;
  if(v[0]!=0){
    dp[0][1]=-1; c++;
    s0.insert(0);
    s1.insert(1);
    }
  dp[0][1]++;


  for(int i=1; i<n; i++){
    dp[i][0]=dp[i-1][1];


    //cout<<i<<" "<<dp[i][0]<<" "<<dp[i][1]<<ENDL;
  }

  cout<<(dp[n-1][0]+dp[n-1][1])%mod<<ENDL;*/

  cin>>m;
  vll a(n), b(m);
  map<ll, ll>ca, cb;
  for(int i=0; i<n; i++){
    cin>>a[i];
    ca[a[i]]++;
  }

  for(int i=0; i<m; i++){
    cin>>b[i];
    cb[b[i]]++;
  }

  multiset<ll>sa, sb;
  for(int i:a)sa.insert(i);
  for(int i: b)sb.insert(i);

  while(sb.size() && sb.size()<sa.size()){
    ll x=*sb.rbegin();
    sb.erase(--sb.end());

    if(sa.find(x)!=sa.end()){
        sa.erase(sa.find(x));
        continue;
    }

    sb.insert(x/2);
    sb.insert((x+1)/2);
  }

  for(ll i: sb){
    if(sa.find(i)==sa.end()){
        cout<<"NO"<<ENDL;
        return;
    }
  }

  for(ll i: sa){
    if(sb.find(i)==sb.end()){
        cout<<"NO"<<ENDL;
        return;
    }
  }

  cout<<"YES"<<ENDL;


}

int32_t main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cout.precision(0);
    cout<<fixed;
	//freopen("fencedin.in", "r", stdin);
	//freopen("fencedin.out", "w", stdout);

	int t=1;
    cin>>t;
	while(t--)solve();

	return 0;
}


Submission (verdict: Accepted):
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#define ENDL '\n'
#define MAXN 100001
#define mod 998244353
#define ft first
#define sc second
using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef long double ld;
typedef tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, tree_order_statistics_node_update>ordered_set;

ll n, m, k;

ll binpow(ll a, ll b){
	if(b==0)return 1;
	if(b==1)return a;
	ll num=binpow(a,b>>1)%mod, p=1;
	if(b%2)p=a;
	ll part=(num*num)%mod;
	return (part*p)%mod;
}

const int mov_f[]={-1,0,1, 0};
const int mov_c[]={0,-1,0, 1};

void solve(){
  cin>>n;
  /*vll v(n);

  ll a=0, b=0;
  map<ll, ll>mp;
  for(int i=0; i<n; i++){
     cin>>v[i];
     mp[v[i]]++;
  }

  vll fact(n+1);
  fact[0]=1;
  for(int i=1; i<=n; i++)fact[i]=(fact[i-1]*i)%mod;

  ll dp[n][2];
  for(int i=0; i<n; i++)dp[i][0]=dp[i][1]=0;
  dp[0][0]=1;
  ll c=0;

  set<ll>s1, s0;
  if(v[0]!=0){
    dp[0][1]=-1; c++;
    s0.insert(0);
    s1.insert(1);
    }
  dp[0][1]++;


  for(int i=1; i<n; i++){
    dp[i][0]=dp[i-1][1];


    //cout<<i<<" "<<dp[i][0]<<" "<<dp[i][1]<<ENDL;
  }

  cout<<(dp[n-1][0]+dp[n-1][1])%mod<<ENDL;*/

  cin>>m;
  vll a(n), b(m);
  map<ll, ll>ca, cb;
  for(int i=0; i<n; i++){
    cin>>a[i];
    ca[a[i]]++;
  }

  for(int i=0; i<m; i++){
    cin>>b[i];
    cb[b[i]]++;
  }

  multiset<ll>sa, sb;
  for(int i:a)sa.insert(i);
  for(int i: b)sb.insert(i);

  while(sb.size() && sb.size()<sa.size()){
    ll x=*sb.rbegin();
    sb.erase(--sb.end());

    if(sa.find(x)!=sa.end()){
        sa.erase(sa.find(x));
        continue;
    }

    sb.insert(x/2);
    sb.insert((x+1)/2);
  }

  for(ll i: sb){
    if(sa.find(i)==sa.end()){
        cout<<"NO"<<ENDL;
        return;
    }
    sa.erase(sa.find(i));
  }

  for(ll i: sa){
    if(sb.find(i)==sb.end()){
        cout<<"NO"<<ENDL;
        return;
    }
    
    sb.erase(sb.find(i));
  }

  cout<<"YES"<<ENDL;


}

int32_t main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cout.precision(0);
    cout<<fixed;
	//freopen("fencedin.in", "r", stdin);
	//freopen("fencedin.out", "w", stdout);

	int t=1;
    cin>>t;
	while(t--)solve();

	return 0;
}