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

Previous submission (verdict: Wrong answer on test 3):
#include<bits/stdc++.h>
using namespace std;
#define int long long 
using ll = long long;
using pii = pair<int,int>;
#define _rep(i,a,b) for(int i = (a);i <= (b);i ++)
#define _for(i,a,b) for(int i = (a);i < (b) ;i ++)
#define pb push_back
void solve(){
	int n , m; cin >> n >> m;
	priority_queue<int,vector<int>,greater<int>> q1;
	priority_queue<int,vector<int>,greater<int>> q2;
	vector<int> a(n);
	vector<int> b(m);
	map<int,int> f;
	multiset<int> s;
	for(int i = 0; i < n; ++ i){
		int x; cin >> x;
		s.insert(x);
		f[x] ++; 
	}for(int i = 0; i < m; ++ i){
		int x; cin >> x; q2.push(x);
	}
	
	while(q2.size()){
		auto t = q2.top(); 
		if(f[t]){
			f[t] --; 
			auto t1 = s.find(t);
			s.erase(t1);
			q2.pop();
		}else{
			if(t % 2 == 0){
				if(f[t / 2] >= 2){
					f[t / 2] -= 2;
					auto t1 = s.find(t / 2);
					s.erase(t1);
					auto t2 = s.find(t / 2);
					s.erase(t2);
					q2.pop();
				}else{
					if(s.size() < 2){
						cout << "No" << endl;
						return ;
					}
					auto t1 = *s.begin();
					auto t2 = * ++ s.begin();
					s.erase(s.begin());
					s.erase(s.begin());
					f[t1] --; f[t2] --;
					if(abs(t1 - t2) <= 1) {
						f[t1 + t2] ++;
						s.insert(t1 + t2);
					}else{
						cout << "No" << endl;
						return; 
					}
				}
			}else{
				if(f[(t + 1) / 2] && f[t / 2]){
					f[(t + 1) / 2] --;
					auto t1 = s.find((t + 1) / 2);
					s.erase(t1);
					f[t / 2] --;
					t1 = s.find(t  / 2);
					s.erase(t1);
					 q2.pop();
				}else{
					if(s.size() < 2){
						cout << "No" << endl;
						return ;
					}
					auto t1 = *s.begin();
					auto t2 = * ++ s.begin();
					s.erase(s.begin());
					s.erase(s.begin());
					f[t1] --; f[t2] --;
					if(abs(t1 - t2) <= 1) {
						f[t1 + t2] ++;
						s.insert(t1 + t2);
					}else{
						cout << "No" << endl;
						return; 
					}
				}
			}
		}
	}
	if(q2.size()|| s.size()){
		cout << "No" << endl;
	}else cout << "Yes" << endl;
	return;
}
signed main(){
	std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
	int _;cin >> _;
	while(_--){
		solve();
	}
	return 0;
}
/*   /\_/\
*   (= ._.)
*   / >  \>
*/


Submission (verdict: Wrong answer on test 3):
#include<bits/stdc++.h>
using namespace std;
#define int long long 
using ll = long long;
using pii = pair<int,int>;
#define _rep(i,a,b) for(int i = (a);i <= (b);i ++)
#define _for(i,a,b) for(int i = (a);i < (b) ;i ++)
#define pb push_back
void solve(){
	int n , m; cin >> n >> m;
	priority_queue<int,vector<int>,greater<int>> q1;
	priority_queue<int,vector<int>,greater<int>> q2;
	vector<int> a(n);
	vector<int> b(m);
	map<int,int> f;
	multiset<int> s;
	for(int i = 0; i < n; ++ i){
		int x; cin >> x;
		s.insert(x);
		f[x] ++; 
	}for(int i = 0; i < m; ++ i){
		int x; cin >> x; q2.push(x);
	}
	
	while(q2.size()){
		auto t = q2.top(); 
		if(f[t]){
			f[t] --; 
			auto t1 = s.find(t);
			s.erase(t1);
			q2.pop();
		}else{
			if(t % 2 == 0){
				if(f[t / 2] >= 2){
					f[t / 2] -= 2;
					auto t1 = s.find(t / 2);
					s.erase(t1);
					auto t2 = s.find(t / 2);
					s.erase(t2);
					q2.pop();
					continue;
				}
				q2.pop();
				if(f[t / 2] == 1) {
					q2.push(t / 2);
					f[t / 2] --;
					auto  t1 = s.find(t / 2);
					s.erase(t1);
					continue;
				}
				else q2.push(t / 2),q2.push(t / 2);
			}else{
				
				if(f[(t + 1) / 2] && f[t / 2]){
					f[(t + 1) / 2] --;
					auto t1 = s.find((t + 1) / 2);
					s.erase(t1);
					f[t / 2] --;
					t1 = s.find(t  / 2);
					s.erase(t1);
					 q2.pop();
					 continue;
				}
				q2.pop();
				if(f[(t + 1) / 2]){
					q2.push(t / 2);
					f[(t + 1) / 2] --;
					auto t1 = s.find((t + 1) / 2);
					s.erase(t1);
					continue;
				}
				else if(f[t  / 2]) {
					q2.push((t + 1) / 2);
					f[t / 2] --;
					auto t1 = s.find(t / 2);
					s.erase(t1);
					continue;
				}else{
					q2.push((t + 1)/ 2);
					q2.push(t / 2);
				} 
			}
					if(s.size() < 2){
						cout << "No" << endl;
						return ;
					}
					auto t1 = *s.begin();
					auto t2 = * ++ s.begin();
					s.erase(s.begin());
					s.erase(s.begin());
					f[t1] --; f[t2] --;
					if(abs(t1 - t2) <= 1) {
						f[t1 + t2] ++;
						s.insert(t1 + t2);
					}else{
						cout << "No" << endl;
						return; 
					}
		}
	}
	if(q2.size()|| s.size()){
		cout << "No" << endl;
	}else cout << "Yes" << endl;
	return;
}
signed main(){
	std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
	int _;cin >> _;
	while(_--){
		solve();
	}
	return 0;
}
/*   /\_/\
*   (= ._.)
*   / >  \>
*/