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

Previous submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>
#define ll int64_t
using namespace std;

ll modPow(ll base,ll exponent,ll mod)
{
    ll result=1;
    while(exponent>0)
    {
        if(exponent%2==1) 
        {
            result=(result*base)%mod;
        }
        base=(base*base)%mod;
        exponent/=2;
    }
    result=result%mod;
    return result;
}

bool fun(ll n,map<ll,ll> &mc)
{
	if(mc[n]>0)
	{
		mc[n]--;
		return true;
	}
	if(n==1)
	{
		return false;
	}
	ll a=n/2;
	ll b=n/2;
	if(n&1)
	b++;
	if(mc[a]>0 && mc[b]>0)
	{
		mc[a]--;
		mc[b]--;
		return true;
	}
	else
	{
		if(mc[a]==0)
		{
			if(!fun(a,mc))
			{
				// cout<<a<<" ";
				return false;
			}
		}
		else
		mc[a]--;
		if(mc[b]==0)
		{
			if(!fun(b,mc))
			{
				// cout<<b<<" ";
				return false;
			}
		}
		else
		mc[b]--;
		return true;
	}
}

void solve()
{
	ll n,m;
	cin>>n>>m;
	vector<ll> a(n,0),b(m,0),c;
	map<ll,ll> ma,mb,mc;
	for(ll i=0;i<n;i++)
	{
		cin>>a[i];
		ma[a[i]]++;
	}
	for(ll i=0;i<m;i++)
	{
		cin>>b[i];
		mb[b[i]]++;
	}
	for(ll i=0;i<n;i++)
	{
		if(mb[a[i]]==0)
		{
			c.push_back(a[i]);
			mc[a[i]]++;
		}
		else
		{
			mb[a[i]]--;
		}
	}
	sort(c.begin(),c.end());
	if(c.size()==0)
	{
		cout<<"YES"<<endl;
		return;
	}
	if(c.size()==1)
	{
		cout<<"NO"<<endl;
		return;
	}
	sort(b.rbegin(),b.rend());
	for(ll i=0;i<c.size();i++)
	{
		if(mc[c[i]]>0)
		{
			if(mb[2*c[i]]>0 && mc[c[i]]>1)
			{
				mc[c[i]]-=2;
				mb[2*c[i]]--;
			}
			else if(mb[(2*c[i])+1]>0 && mc[c[i]+1]>0)
			{
				mc[c[i]]--;
				mc[c[i]+1]--;
				mb[(2*c[i])+1]--;
			}
			else if(mb[(2*c[i])+1]>0 || mb[2*c[i]]>0)
			{
				cout<<"NO"<<endl;
				return;
			}
		}
	}
	for(ll i=0;i<m;i++)
	{
		if(mb[b[i]]>0)
		{
			bool p=fun(b[i],mc);
			if(p)
			mb[b[i]]--;
			else
			{
				cout<<"NO"<<endl;
				return;
			}
		}
	}
	for(auto x:mb)
	{
		if(x.second>0)
		{
			cout<<"NO"<<endl;
			return;
		}
	}
	for(auto x:mc)
	{
		if(x.second>0)
		{
			cout<<"NO"<<endl;
			return;
		}
	}
	cout<<"YES"<<endl;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t1;
	cin >> t1;
	while (t1--)
	{
		solve();
	}
}

Submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>
#define ll int64_t
using namespace std;

ll modPow(ll base,ll exponent,ll mod)
{
    ll result=1;
    while(exponent>0)
    {
        if(exponent%2==1) 
        {
            result=(result*base)%mod;
        }
        base=(base*base)%mod;
        exponent/=2;
    }
    result=result%mod;
    return result;
}

bool fun(ll n,map<ll,ll> &mc)
{
	if(mc[n]>0)
	{
		mc[n]--;
		return true;
	}
	if(n==1)
	{
		return false;
	}
	ll a=n/2;
	ll b=n/2;
	if(n&1)
	b++;
	if(mc[a]>0 && mc[b]>0)
	{
		mc[a]--;
		mc[b]--;
		return true;
	}
	else
	{
		if(mc[a]==0)
		{
			if(!fun(a,mc))
			{
				// cout<<a<<" ";
				return false;
			}
		}
		else
		mc[a]--;
		if(mc[b]==0)
		{
			if(!fun(b,mc))
			{
				// cout<<b<<" ";
				return false;
			}
		}
		else
		mc[b]--;
		return true;
	}
}

void solve()
{
	ll n,m;
	cin>>n>>m;
	vector<ll> a(n,0),b(m,0),c;
	map<ll,ll> ma,mb,mc;
	for(ll i=0;i<n;i++)
	{
		cin>>a[i];
		ma[a[i]]++;
	}
	for(ll i=0;i<m;i++)
	{
		cin>>b[i];
		mb[b[i]]++;
	}
	for(ll i=0;i<n;i++)
	{
		if(mb[a[i]]==0)
		{
			c.push_back(a[i]);
			mc[a[i]]++;
		}
		else
		{
			mb[a[i]]--;
		}
	}
	sort(c.begin(),c.end());
	if(c.size()==0)
	{
		cout<<"YES"<<endl;
		return;
	}
	if(c.size()==1)
	{
		cout<<"NO"<<endl;
		return;
	}
	sort(b.rbegin(),b.rend());
	// for(ll i=0;i<c.size();i++)
	// {
		// if(mc[c[i]]>0)
		// {
			// if(mb[2*c[i]]>0 && mc[c[i]]>1)
			// {
				// mc[c[i]]-=2;
				// mb[2*c[i]]--;
			// }
			// else if(mb[(2*c[i])+1]>0 && mc[c[i]+1]>0)
			// {
				// mc[c[i]]--;
				// mc[c[i]+1]--;
				// mb[(2*c[i])+1]--;
			// }
			// else if(mb[(2*c[i])+1]>0 || mb[2*c[i]]>0)
			// {
				// cout<<"NO"<<endl;
				// return;
			// }
		// }
	// }
	for(ll i=0;i<m;i++)
	{
		if(mb[b[i]]>0)
		{
			bool p=fun(b[i],mc);
			if(p)
			mb[b[i]]--;
			else
			{
				cout<<"NO"<<endl;
				return;
			}
		}
	}
	for(auto x:mb)
	{
		if(x.second>0)
		{
			cout<<"NO"<<endl;
			return;
		}
	}
	for(auto x:mc)
	{
		if(x.second>0)
		{
			cout<<"NO"<<endl;
			return;
		}
	}
	cout<<"YES"<<endl;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t1;
	cin >> t1;
	while (t1--)
	{
		solve();
	}
}