Problem: 2061D - Kevin and Numbers
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 3):
#include<bits/stdc++.h>
 
using namespace std;
 
 
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
  
// Usage: insert, find, erase same as set;
// order_of_key(k): Number of items strictly smaller than k
// find_by_order(k): k-th element in a set (counting from zero)
 
 
#define ll long long
#define getunique(v) {sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end());}
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
typedef priority_queue<int> pq_max;
typedef priority_queue<int, vector<int>, greater<int>> pq_min;
 
const int MAXN = 200005 , INF = 1e9 , MOD = 998244353;//998244353 1e9 + 7
const ll inf = 1e18;
int dx[] = {1 , -1 , 0 , 0 ,1 , -1 , 1 , -1};
int dy[] = {0 , 0 , 1 , -1 ,1 , -1 , -1 , 1};
 
// fast power
long long binpow(long long a, long long b , long long MOD) {
    if (b == 0)
        return 1;
    long long res = binpow(a, b / 2 , MOD);
    if (b % 2)
        return res%MOD* res%MOD * a%MOD;
    else
        return res%MOD* res%MOD;
}
int mul(ll a, ll b) {
    return (1LL * a * b) % MOD;
}
 
int add(ll a, ll b) {
    ll s = (a+b);
    if (s>=MOD) s-=MOD;
    return s;
}
 
int sub(ll a, ll b) {
    int s = (a+MOD-b);
    if (s>=MOD) s-=MOD;
    return s;
}
 
int po(ll a, ll deg)
{
    if (deg==0) return 1;
    if (deg%2==1) return mul(a, po(a, deg-1));
    int t = po(a, deg/2);
    return mul(t, t);
}
 
int inv(ll n)
{
    return po(n, MOD-2);
}
 
 
const int LIM = 2e6 + 5;
 
vector<int> facs(LIM), invfacs(LIM);
 
void init()
{
    facs[0] = 1;
    for (int i = 1; i<LIM; i++) facs[i] = mul(facs[i-1], i);
    invfacs[LIM-1] = inv(facs[LIM-1]);
    for (int i = LIM-2; i>=0; i--) invfacs[i] = mul(invfacs[i+1], i+1);
}
 
int nCr(int n, int k)
{
    if (n<k) return 0;
    if (n<0 || k<0) return 0;
    return mul(facs[n], mul(invfacs[k], invfacs[n-k]));
}
 
int nPr(int n, int k)
{
    if (n<k) return 0;
    if (n<0 || k<0) return 0;
    return mul(facs[n],invfacs[n-k]);
}
 
int gcd(int a , int b){
	if(a == 0)return 0;
	if(b == 0)return 1;
	
 
	if(a >=b){
		int r = a%b;
		int k = a/b;
		if(k%2 == 1){
			return gcd(b , r) + k + k /2;
		}
		else return gcd(r , b) + k + k /2;
	}
	return 1 + gcd(b , abs(a - b));
}
 
/*
auto fun = [&](){
	
};
*/
 
// https://discuss.codechef.com/t/segment-tree-problems-of-codeforces-edu-with-code-and-some-explanation/82461/5
// https://docs.google.com/document/d/1E8j0FCoNbdptnaPxwmeaRqp6UkTGPg-6NUjLGJDNGMI/edit




// Solution part

struct DSU {
    vector<int> p, sz;
    int component = 0;
 
    DSU(int N) {
        p.resize(N + 1);
        iota(p.begin(), p.end(), 0);
        sz.resize(N + 1, 1);
        component = N;
    }
 
    int get(int u) {
        return u == p[u] ? u : p[u] = get(p[u]);
    }
 
    bool unite(int u, int v) {
        u = get(u);
        v = get(v);
 
        if (u == v)
            return false;
 
        if (sz[u] < sz[v])
            swap(u, v);
 
        p[v] = u;
        sz[u] += sz[v];
        component--; 
        return true;
    }
};


void solve(){	
	int n , m ;cin >> n>> m;
	map<int ,int > mp1 , mp2;
	for(int i =0 ;i< n;i++){
		int x; cin >> x;
		mp1[x]++;
	}
	
	for(int i =0 ;i <m ;i++){
		int x ; cin >> x;
		mp2[x]++;
	}
	
	for(auto it : mp2){
		int x = min(it.second , mp1[it.first]);
		mp1[it.first]-=x;
		mp2[it.first]-=x;
	}
	
	multiset<ll> a , b;
	for(auto it : mp1){
		for(int j = 0 ;j <it.second;j++)a.insert(it.first);
	}
	
	for(auto it : mp2){
		for(int j =0 ;j <it.second ;j++)b.insert(it.first);
	}
	
	int j = 0;
	ll sum = 0;
	n = sz(a);
	m = sz(b);
	if(n ==m && n == 0){
		cout <<"Yes\n";
		return;
	}
	if(a.empty() || b.empty()){
		cout <<"No\n";
		return;
	}
	
	while(sz(b) && sz(b) <=sz(a)){
		if(*a.rbegin() > *b.begin()){
			cout <<"No\n";
			return;
		}
		int x = *b.rbegin();
		b.erase(b.find(x));
		int l = x/2;
		int r = x - l;
		if(a.find(r)!=a.end()){
			a.erase(a.find(r));
		}
		else b.insert(r);
		if(a.find(l)!=a.end()){
			a.erase(a.find(l));
		}
		else b.insert(l);
	}
	
	if(sz(b) == 0 && sz(a) ==0){
		cout <<"Yes\n";
	}
	else cout <<"No\n";
	
}
// a is the len of the max diameter;
// the shortest diameter is len(a + 1)/2 
 
void setIO(string s){
    freopen((s+".in").c_str(),"r",stdin);
    freopen((s+".out").c_str(),"w",stdout);
}
 
int main(){
	
	ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    // setIO("Walk");
    // init();
    
	int multitest = 1;
	cin >> multitest;
	while(multitest--){
		solve();
	}
	return 0;
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
 
using namespace std;
 
 
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
  
// Usage: insert, find, erase same as set;
// order_of_key(k): Number of items strictly smaller than k
// find_by_order(k): k-th element in a set (counting from zero)
 
 
#define ll long long
#define getunique(v) {sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end());}
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
typedef priority_queue<int> pq_max;
typedef priority_queue<int, vector<int>, greater<int>> pq_min;
 
const int MAXN = 200005 , INF = 1e9 , MOD = 998244353;//998244353 1e9 + 7
const ll inf = 1e18;
int dx[] = {1 , -1 , 0 , 0 ,1 , -1 , 1 , -1};
int dy[] = {0 , 0 , 1 , -1 ,1 , -1 , -1 , 1};
 
// fast power
long long binpow(long long a, long long b , long long MOD) {
    if (b == 0)
        return 1;
    long long res = binpow(a, b / 2 , MOD);
    if (b % 2)
        return res%MOD* res%MOD * a%MOD;
    else
        return res%MOD* res%MOD;
}
int mul(ll a, ll b) {
    return (1LL * a * b) % MOD;
}
 
int add(ll a, ll b) {
    ll s = (a+b);
    if (s>=MOD) s-=MOD;
    return s;
}
 
int sub(ll a, ll b) {
    int s = (a+MOD-b);
    if (s>=MOD) s-=MOD;
    return s;
}
 
int po(ll a, ll deg)
{
    if (deg==0) return 1;
    if (deg%2==1) return mul(a, po(a, deg-1));
    int t = po(a, deg/2);
    return mul(t, t);
}
 
int inv(ll n)
{
    return po(n, MOD-2);
}
 
 
const int LIM = 2e6 + 5;
 
vector<int> facs(LIM), invfacs(LIM);
 
void init()
{
    facs[0] = 1;
    for (int i = 1; i<LIM; i++) facs[i] = mul(facs[i-1], i);
    invfacs[LIM-1] = inv(facs[LIM-1]);
    for (int i = LIM-2; i>=0; i--) invfacs[i] = mul(invfacs[i+1], i+1);
}
 
int nCr(int n, int k)
{
    if (n<k) return 0;
    if (n<0 || k<0) return 0;
    return mul(facs[n], mul(invfacs[k], invfacs[n-k]));
}
 
int nPr(int n, int k)
{
    if (n<k) return 0;
    if (n<0 || k<0) return 0;
    return mul(facs[n],invfacs[n-k]);
}
 
int gcd(int a , int b){
	if(a == 0)return 0;
	if(b == 0)return 1;
	
 
	if(a >=b){
		int r = a%b;
		int k = a/b;
		if(k%2 == 1){
			return gcd(b , r) + k + k /2;
		}
		else return gcd(r , b) + k + k /2;
	}
	return 1 + gcd(b , abs(a - b));
}
 
/*
auto fun = [&](){
	
};
*/
 
// https://discuss.codechef.com/t/segment-tree-problems-of-codeforces-edu-with-code-and-some-explanation/82461/5
// https://docs.google.com/document/d/1E8j0FCoNbdptnaPxwmeaRqp6UkTGPg-6NUjLGJDNGMI/edit




// Solution part

struct DSU {
    vector<int> p, sz;
    int component = 0;
 
    DSU(int N) {
        p.resize(N + 1);
        iota(p.begin(), p.end(), 0);
        sz.resize(N + 1, 1);
        component = N;
    }
 
    int get(int u) {
        return u == p[u] ? u : p[u] = get(p[u]);
    }
 
    bool unite(int u, int v) {
        u = get(u);
        v = get(v);
 
        if (u == v)
            return false;
 
        if (sz[u] < sz[v])
            swap(u, v);
 
        p[v] = u;
        sz[u] += sz[v];
        component--; 
        return true;
    }
};


void solve(){	
	int n , m ;cin >> n>> m;
	
	multiset<int> a ,b;
	for(int i =0 ;i< n;i++){
		int x; cin >> x;
		a.insert(x);
	}
	
	for(int i =0 ;i <m ;i++){
		int x ; cin >> x;
		b.insert(x);
	}
	
	
	while(sz(b) && sz(b) <=sz(a)){
		int x = *b.rbegin();
		b.erase(b.find(x));
		if(a.find(x)!=a.end()){
			a.erase(a.find(x));
			continue;
		}
		int l = x/2;
		int r = x - l;
		if(a.find(r)!=a.end()){
			a.erase(a.find(r));
		}
		else b.insert(r);
		if(a.find(l)!=a.end()){
			a.erase(a.find(l));
		}
		else b.insert(l);
	}
	
	// for(auto it : b)cout <<it<<" ";
	if(sz(b) == 0 && sz(a) ==0){
		cout <<"Yes\n";
	}
	else cout <<"No\n";
	
}
// a is the len of the max diameter;
// the shortest diameter is len(a + 1)/2 
 
void setIO(string s){
    freopen((s+".in").c_str(),"r",stdin);
    freopen((s+".out").c_str(),"w",stdout);
}
 
int main(){
	
	ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    // setIO("Walk");
    // init();
    
	int multitest = 1;
	cin >> multitest;
	while(multitest--){
		solve();
	}
	return 0;
}