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

Solution 1 (runtime: 1311 ms):
#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;
#define int long long
#define mod 1000000007
#define INF 1000000000
#define nINF -1000000000
template<class T> using oset =tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update> ; //find_by_order, order_of_key

int32_t power(int a, int b) {
    int res = 1;
    while (b > 0) {
        if (b % 2 == 1) {
            res = (res * a) % mod;
        }
        a = (a * a) % mod;
        b /= 2;
    }
    return res;
}

int32_t inv_mod(int a, int b){
    return (a%mod)*(power(b, mod-2)%mod)%mod; 
}
bool isPrime(int num) {
    int cnt = 0; 
    if(num<=1) return false; 
    for(int i = 1; i*i<=num; ++i){
        if(num%i == 0){
            ++cnt; 
            if(i != num/i) ++cnt; 
        }
    }
    return cnt == 2; 
}
int gcd(int a, int b){
    if(a == 0) return b; 
    if(b == 0) return a; 
    if(a == b) return a; 
    if(a>b) return gcd(a%b, b); 
    else return gcd(a, b%a); 
}

void solve(){
    int n, m; cin>>n>>m; 
    vector<int> a(n), b(m); 
    for(int i = 0; i<n; ++i) cin>>a[i]; 
    for(int i = 0; i<m; ++i) cin>>b[i];
    map<int, int> m1, m2; 
    set<int> st1, st2; 
    for(auto &it: a){
        m1[it]++; 
        st1.insert(it);
    }
    for(auto &it: b){
        m2[it]++; st2.insert(it); 
    }
    while(true){
        if(st1.empty() && st2.empty()){
            cout<<"YES"<<endl; 
            return; 
        }
        if(st1.empty() || st2.empty()){
            cout<<"NO"<<endl; 
            return;
        }
        int maxA = *st1.begin(); 
        int maxB = *st2.begin(); 
        if(maxA > maxB){
            cout<<"NO"<<endl; 
            return; 
        }
        if(m1[maxB]){
            int mn = min(m1[maxB], m2[maxB]); 
            m1[maxB] -= mn; 
            m2[maxB] -= mn; 
            if(m1[maxB] == 0){
                st1.erase(maxB);  
            }
            if(m2[maxB] == 0){
                st2.erase(maxB); 
            }
        }
        else{
            int first = maxB/2; 
            int second = (maxB + 1)/2; 
            m2[first] += m2[maxB]; 
            m2[second] += m2[maxB]; 
            m2[maxB] = 0; 
            st2.insert(first); 
            st2.insert(second); 
            st2.erase(maxB); 
        }
    }
}

int32_t main(){
    int t;
    cin>>t; 
    while(t--){
        solve();
    }
}

Solution 2 (runtime: 983 ms):

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
template<typename T>
using ordered_set = tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>;
typedef unsigned long long int ull;
#define vi vector<int>
#define vpi vector<pair<int,int> >
#define mpi map<int,int>
#define  si set<int>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define reP(i,a,n) for(int i=a;i<=n;i++)
#define YES cout<<"YES\n";
#define NO cout<<"NO\n";
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define case(i,n) Case<<" "<<i<<": "<<n<<endl;
#define endl "\n"
#define w(t) int t;cin>>t;while(t--)
#define all(x) (x).begin(), (x).end()
#define sz(a) (int)(a).size()
#define MOD 1000000007


void solve(){


ll n,m;
cin>>n>>m;
set<ll>a,b;
map<ll,ll>mp1,mp2;
ll x;
rep(i,0,n)
{
	cin>>x;
	mp1[x]++;
	a.insert(x);
}rep(i,0,m)
{
	cin>>x;
	mp2[x]++;
	b.insert(x);
}
while(true){
	if(a.empty() && b.empty()){
		YES
		return;
	}
	if(a.empty() || b.empty()){
		NO 
		return;
	}
	ll mxa= *a.rbegin();
	ll mxb= *b.rbegin();
	if(mxa>mxb){
		NO 
		return;
	}
	if(mp1[mxb]){
		ll mn = min(mp1[mxb],mp2[mxb]);
		mp1[mxb]-=mn;
		mp2[mxb]-=mn;
		if(mp1[mxb]==0){
			a.erase(mxb);
		}if(mp2[mxb]==0){
			b.erase(mxb);
		}
	}
	else
	{
		ll l = mxb/2;
		ll r = (mxb+1)/2;
		mp2[l]+=mp2[mxb];
		mp2[r]+=mp2[mxb];
		mp2[mxb]=0;
		b.insert(l);
		b.insert(r);
		b.erase(mxb);
	}



}


}
int main()
{
     #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
int t;
clock_t z =  clock();
t=1;
cin>>t;
while(t--)
{
solve();
}

cerr<<"Run Time : "<<((double)(clock()-z)/CLOCKS_PER_SEC);
}