Problem: 2061D - Kevin and Numbers
Language: c++17 

Solution 1 (runtime: 639 ms):
#include <bits/stdc++.h>
using namespace std;

#define fastIO ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);cout.precision(numeric_limits<double>::max_digits10);
#define int long long
#define ll long long
#define endl '\n'

// STL Input Outputs
#define vdef(v,n) vector<int> v((n)); for(int i=0;i<(n);i++) cin>>v[i]
#define vvdef(v,n,m) vector<vector<int>> v(n, vector<int>(m)); for(int i=0; i<n; i++) for(int j=0; j<m; j++) cin >> v[i][j];
#define vout(v) for(auto& el:v) cout<<el<<" "; cout << endl
#define vvout(vec) for(auto& v: vec){for(auto& ele: v){cout << ele <<" ";}cout << endl;}
#define mpdef(mp) map<int, int> mp
#define mpout(mp) for(auto& el: mp) { cout << el.first << " " << el.second << endl; }
#define strin(s) string s; cin >> s

// Pairs
#define pr pair<int, int>
#define ff first
#define ss second

// STL Functions Related
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend()

// Inputs and Outputs
#define rd1(x) int x; cin >> x
#define rd2(x, y) int x, y; cin >> x >> y
#define rd3(x, y, z) int x, y, z; cin >> x >> y >> z
#define rd4(x, y, z, w) int x, y, z, w; cin >> x >> y >> z >> w
#define ha cout << "YES" << endl
#define na cout << "NO" << endl
#define nl cout << endl
#define aout(ans) cout << ans << endl

const int MOD = 1000000007;
const int MOD2 = 998244353;

void solve() {
    rd2(n,m);
    multiset<int> s1, s2;
    for(int i=0; i<n; i++){
        rd1(x);
        s1.insert(x);
    } 
    for(int i=0; i<m; i++){
        rd1(x);
        s2.insert(x);
    }
    int count = 2*n;
    while(count--){
        if(s1.empty() || s2.empty()) break;
        int mx1 = *s1.rbegin(), mx2 = *s2.rbegin();
        if(mx1 == mx2){
            s1.erase(s1.find(mx1));
            s2.erase(s2.find(mx2));
        }else{
            int v1 = (mx2+1)/2, v2 = mx2/2;
            s2.erase(s2.find(mx2));
            s2.insert(v1);
            s2.insert(v2);
            
        }
    }
    if(s1.empty() && s2.empty()){
        ha;
    }else{
        na;
    }
}

signed main() {
    fastIO;
    int t = 1;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

Solution 2 (runtime: 358 ms):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll mod = 998244353;

#define Pll pair<long,long>

#define Pil pair<int,long>

#define Pli pair<long,int>

#define Pii pair<int,int>

#define pb(x) push_back(x)

#define pf(x) push_front(x)

#define Ve vector

#define For(x,y,z) for(ll x=y;x<=z;x++)

#define rFor(x,y,z) for(ll x=y;x>=z;x--)

const int N=200010;

ll a[N];

ll b[N];

void solve() {

	int n,m;

	cin>>n>>m;

	multiset<ll>s1,s2;

	ll sum=0;

	For(i,1,n)cin>>a[i],sum+=a[i];

	For(i,1,m)cin>>b[i],sum-=b[i];

	if(sum)

	{

		cout<<"NO"<<'\n';

		return;

	}

	For(i,1,n)s1.emplace(a[i]);

	For(i,1,m)s2.emplace(b[i]);

	while(!s1.empty()&&!s2.empty())

	{

		ll iy1=*s1.rbegin(),iy2=*s2.rbegin();

		if(iy1==iy2)

		{

			s1.erase(s1.find(iy1));

			s2.erase(s2.find(iy2));

		}

		else if(iy1<iy2)

		{

			s2.erase(s2.find(iy2));

			s2.emplace(iy2>>1);

				s2.emplace((iy2+1)>>1);	

		}

		else

		{

			cout<<"NO"<<'\n';

			return;

		}

	}

	if(s1.empty()&&s2.empty())cout<<"YES"<<'\n';

	else cout<<"NO"<<'\n';

}

int main() {

    ios::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

    int t;

    cin>>t;

    while(t--)

    solve();

}