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> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace std;
using namespace __gnu_pbds;

#pragma GCC optimize("O3,unroll-loops")

using ll = long long;
using ld = long double;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;

constexpr ll inf=2e18;
constexpr ld eps=1e-9;
constexpr ll mod=1e9+7;

#define F first
#define S second
#define int long long
#define pb push_back
#define all(x) x.begin(), x.end()

template<typename T>
istream& operator>>(istream &istream, vector<T> &v)
{
	for(auto &it : v)
		cin>>it;
	return istream;
}

template<typename T>
ostream& operator<<(ostream &ostream, const vector<T> &c)
{
	for(auto &it : c)
		cout<<it<<" ";
	return ostream;
}

vector<int> fact_dp(2e5+2,-1);

int binpow(int a, int b, int m=mod)
{
	if(b==0)
		return 1;

	int x = binpow(a,b/2);
	if(b&1)
		return ((x*x)%m*a)%m;
	return (x*x)%m;
}

int modinv(int x, int m=mod)
{
	return binpow(x,m-2,m);
}

int fact(int x){
	if(x<=1) return 1;
	if(fact_dp[x] != -1) return fact_dp[x];

	return fact_dp[x] = (x%mod * fact(x-1)%mod)%mod;
}

int nCr(int n, int r){
	int x = (modinv(fact(r)) * modinv(fact(n-r)))%mod;
	int y = fact(n);
	return (x*y)%mod;
}

void solve()
{
	int n, m;
	cin >> n >> m;
	vector<int> a(n), b(m);
	cin >> a >> b;
	sort(all(a));
	sort(all(b));

	priority_queue<int, vector<int>, greater<int>> q;
	for(auto it : a){
		q.push(it);
	}

	int j = 0;
	while(!q.empty() && j<m){
		int cur = q.top();
		q.pop();

		if(cur==b[j]) j++;
		else{
			if(q.empty()){
				cout << "NO\n";
				return;
			}else{
				int cur2=q.top();

				if(abs(cur2-cur)<=1){
					q.pop();
					q.push(cur+cur2);
				}else{
					cout << "NO\n";
					return;
				}
			}
		}
	}

	if(q.empty() && j==m){
		cout << "YES\n";
	}else{
		cout << "NO\n";
	}
}

signed main()
{
#ifndef ONLINE_JUDGE
    freopen("input1.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << setprecision(12) << fixed;

	int t=1;
	cin>>t;
	while(t--){
		solve();
	}

	return 0;
}

Submission (verdict: Runtime error on test 1):
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace std;
using namespace __gnu_pbds;

#pragma GCC optimize("O3,unroll-loops")

using ll = long long;
using ld = long double;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;

constexpr ll inf=2e18;
constexpr ld eps=1e-9;
constexpr ll mod=1e9+7;

#define F first
#define S second
#define int long long
#define pb push_back
#define all(x) x.begin(), x.end()

template<typename T>
istream& operator>>(istream &istream, vector<T> &v)
{
	for(auto &it : v)
		cin>>it;
	return istream;
}

template<typename T>
ostream& operator<<(ostream &ostream, const vector<T> &c)
{
	for(auto &it : c)
		cout<<it<<" ";
	return ostream;
}

vector<int> fact_dp(2e5+2,-1);

int binpow(int a, int b, int m=mod)
{
	if(b==0)
		return 1;

	int x = binpow(a,b/2);
	if(b&1)
		return ((x*x)%m*a)%m;
	return (x*x)%m;
}

int modinv(int x, int m=mod)
{
	return binpow(x,m-2,m);
}

int fact(int x){
	if(x<=1) return 1;
	if(fact_dp[x] != -1) return fact_dp[x];

	return fact_dp[x] = (x%mod * fact(x-1)%mod)%mod;
}

int nCr(int n, int r){
	int x = (modinv(fact(r)) * modinv(fact(n-r)))%mod;
	int y = fact(n);
	return (x*y)%mod;
}

bool f(int val, map<int,int> &a){
	if(val==0) return 0;

	if(a[val]!=0){
		a[val]--;
		return 1;
	}

	bool x, y;
	if(val&1){
		x = f(val/2, a);
		y = f(val/2+1, a);
		return (x&y);
	}else{
		x = f(val/2, a);
		y = f(val/2, a);
		return (x&y);
	}

	return (x&y);
}

void solve()
{
	int n, m;
	cin >> n >> m;
	map<int,int>a;
	vector<int> b(m);
	for(int i = 0 ; i < n ; i++){
		int x ; cin >> x;
		a[x]++;
	}
	cin >> b;
	// sort(all(b));

	for(int i = 0 ; i < m ; i++){
		bool isPossible = f(b[i],a);
		if(!isPossible){
			cout << "NO\n";
			return;
		}
	}

	cout << "YES\n";
}

signed main()
{
#ifndef ONLINE_JUDGE
    freopen("input1.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << setprecision(12) << fixed;

	int t=1;
	cin>>t;
	while(t--){
		solve();
	}

	return 0;
}