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;
	}
	int sum = dkkk.front();
	L(i, 1, int(dkkk.size()) - 1) {
		if(sum == 0) sum += dkkk[i];
		if(abs(dkkk[i] - sum) <= 1 && sum != 0) sum += dkkk[i];
		auto it = mp2.find(sum);
		if(it != mp2.end() && it->second > 0) {

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