Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 3):
// Problem: D. Kevin and Numbers
// Contest: Codeforces - IAEPC Preliminary Contest (Codeforces Round 999, Div. 1 + Div. 2)
// URL: https://codeforces.com/contest/2061/problem/D
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

//#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>
#define Begin ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define pii pair<int, int>
#define pdd pair<double, double>
#define lowbit(x) (x & -x)
#define all(x) x.begin(), x.end()

#define Rep(i, x) for(auto &i : x)
#define L(i, x, y) for(int i = x; i <= y; ++ i)
#define R(i, x, y) for(int i = x; i >= y; -- i)
#define rd(x) scanf("%lld", &(x))
#define p_b push_back
using namespace std;
template <class T> using vc = vector<T>;
template <class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
using i64 = long long;
using u64 = unsigned long long;
using u32 = unsigned;
const int N = 2e5 + 10;


































void solve() {
	int n, m; cin >> n >> m;
	vc<int> a(n), b(m);
	map<int, int> mp1, mp2;
	L(i, 0, n - 1) {
		cin >> a[i];
		mp1[a[i]] ++;
	}
	L(i, 0, m - 1) {
		cin >> b[i];
		mp2[b[i]] ++;
		auto it = mp1.find(b[i]);
		if(it != mp1.end()) {
			mp1[b[i]] --;
			mp2[b[i]] --;
		}
	}
	sort(a.begin(), a.end()), sort(b.begin(), b.end());
	i64 s1 = reduce(a.begin(), a.end()), s2 = reduce(b.begin(), b.end());
	if(s1 != s2) {
		cout << "No\n";
		return;
	}
	vc<int> dkkk;
	for(auto &[x1, y1] : mp1) {
		if(y1 == 0) continue;
		else {
			L(i, 0, y1 - 1) dkkk.p_b(x1);
		}
	}
	if(dkkk.empty()) {
		cout << "Yes\n";
		return;
	}
	//Rep(i, dkkk) cout << i << "\n";
	int sum = 0;
	L(i, 0, int(dkkk.size()) - 1) {
		if(sum == 0) {
			sum += dkkk[i];
			continue;
		}
		if(abs(dkkk[i] - sum) <= 1 && sum != 0) sum += dkkk[i];
		//cout << sum << "\n";
		auto it = mp2.find(sum);
		if(it != mp2.end() && it->second > 0) {
			//cout << it->second << "\n";
			sum = 0;
			it->second --;
		}
	}
	int ok = 1;
	for(auto [x2, y2] : mp2) {
		if(y2 > 0) ok = 0;
	}
	if(ok) cout << "Yes\n";
	else cout << "No\n";
}


int main() {
	Begin;
	int _; _ = 1;
	cin >> _;
	while(_--) solve();
	return 0;
}

Submission (verdict: Accepted):
// Problem: D. Kevin and Numbers
// Contest: Codeforces - IAEPC Preliminary Contest (Codeforces Round 999, Div. 1 + Div. 2)
// URL: https://codeforces.com/contest/2061/problem/D
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

//#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>
#define Begin ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define pii pair<int, int>
#define pdd pair<double, double>
#define lowbit(x) (x & -x)
#define all(x) x.begin(), x.end()

#define Rep(i, x) for(auto &i : x)
#define L(i, x, y) for(int i = x; i <= y; ++ i)
#define R(i, x, y) for(int i = x; i >= y; -- i)
#define rd(x) scanf("%lld", &(x))
#define p_b push_back
using namespace std;
template <class T> using vc = vector<T>;
template <class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
using i64 = long long;
using u64 = unsigned long long;
using u32 = unsigned;
const int N = 2e5 + 10;


































void solve() {
	int n, m; cin >> n >> m;
	vc<int> a(n), b(m);
	map<int, int> mp1, mp2;
	L(i, 0, n - 1) {
		cin >> a[i];
		mp1[a[i]] ++;
	}
	L(i, 0, m - 1) {
		cin >> b[i];
		mp2[b[i]] ++;
		auto it = mp1.find(b[i]);
		if(it != mp1.end() && mp1[b[i]] > 0) {
			mp1[b[i]] --;
			mp2[b[i]] --;
		}
	}
	sort(a.begin(), a.end()), sort(b.begin(), b.end());
	i64 s1 = reduce(a.begin(), a.end()), s2 = reduce(b.begin(), b.end());
	if(s1 != s2) {
		cout << "No\n";
		return;
	}
	priority_queue<int> pq1, pq2;
	for(auto &[x1, y1] : mp1) {
		if(y1 == 0) continue;
		else {
			L(i, 0, y1 - 1) pq1.push(x1);
		}
	}
	
	for(auto [x2, y2] : mp2) {
		L(i, 0, y2 - 1) pq2.push(x2);
	}
	int sum = 0;
	while(pq1.size()) {
		if(pq2.empty()) {
			cout << "No\n";
			return;
		}
		int x = pq2.top();
		pq2.pop();
		/*
		cout << x << "\n";
		cout << pq1.top() << "\n";
		*/
		if(x == pq1.top()) pq1.pop();
		else if(x < pq1.top()) {
			cout << "No\n";
			return;
		}
		else {
			pq2.push(x / 2);
			pq2.push((x + 1) / 2);
		}
	}
	if(pq2.size()) {
		cout << "No\n";
		return;
	}
	else {
		cout << "Yes\n";
	}
}


int main() {
	Begin;
	int _; _ = 1;
	cin >> _;
	while(_--) solve();
	return 0;
}