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};

bool rec(multiset<ll>&sa, ll x){
    ll a=x/2, b=(x+1)/2;
    if(x==1 || x==0)return 0;
    bool flag1=0, flag2=0;
    if(sa.find(a)!=sa.end()){
        sa.erase(sa.find(a));
        flag1=1;
    }
    else flag1=rec(sa, a);

    if(sa.find(b)!=sa.end()){
        sa.erase(sa.find(b));
        flag2=1;
    }
    else flag2=rec(sa, b);

    return flag1 && flag2;

}

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]]++;
  }

  if(m>n){
    cout<<"NO"<<ENDL;
    return;
  }

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

  vll del;
  for(auto i=sb.begin(); i!=sb.end(); i++){
    if(sa.find(*i)!=sa.end()){
        sa.erase(sa.find(*i));
        del.push_back(*i);
    }
  }

  for(ll i: del)sb.erase(sb.find(i));

  while(sa.size()){
    if(sa.size()==1){
        if(sb.size()==1 && *sa.begin() == *sb.begin())cout<<"YES"<<ENDL;
        else cout<<"NO"<<ENDL;
        return;
    }

    ll x=*sa.begin();
    sa.erase(sa.begin());

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

    ll y=*sa.begin();
    sa.erase(sa.begin());

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

    if(abs(x-y)<=1)sa.insert(x+y);
    else{
        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: 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;
}