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

Solution 1 (runtime: 202 ms):
/******************************************
* AUTHOR : kevin_007 *
******************************************/
#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 Speed_UP  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pt;
#define vi vector<int>
#define vll vector<ll>
#define N 100005
#define MOD 1000000007
#define dd double
#define rep(i, n) for(int i = 0; i < n; i++)
#define repe(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define sz(x) ((int)(x).size())
#define F first
#define S second
template<class T> using ordered_set = tree<T, null_type, less_equal<T>, 
rb_tree_tag,tree_order_statistics_node_update> ;
// order_of_key (k) : Number of items strictly smaller than k .
// find_by_order(k) : K-th element in a set (counting from zero).

int ans;

void func(priority_queue<int> &pq1, priority_queue<int> &pq2) {
    if(pq1.empty()) {
        if(!pq2.empty()) {
            ans = 0;
        }

        return;
    }

    int tp1 = pq1.top(), tp2 = pq2.top();

    if(tp1 > tp2) {
        ans = 0;    return;
    }
    else if(tp1 == tp2) {
        pq1.pop();  pq2.pop();

        func(pq1, pq2);

        return;
    }

    int x = tp2/2, y = (tp2+1)/2;

    pq2.pop();
    pq2.push(x);    pq2.push(y);

    func(pq1, pq2);
}

int solve() {
    int n,m;    cin>>n>>m;

    priority_queue<int> pq1, pq2;

    ll sum1 = 0, sum2 = 0;

    rep(i,n) {
        int x;  cin>>x;
        sum1 += x;
        pq1.push(x);
    }

    rep(i,m) {
        int x;  cin>>x;
        sum2 += x;
        pq2.push(x);
    }

    if(sum1 != sum2) {
        cout<<"No\n";   return 0;
    }

    ans = 1;

    func(pq1, pq2);

    if(ans) cout<<"Yes\n";
    else cout<<"No\n";

    return 0;
}

int main() {
    #ifndef ONLINE_JUDGE   
    freopen("input.txt", "r", stdin); 
    freopen("output.txt", "w", stdout);    
    #endif 
    Speed_UP


    int t;
    cin>>t;

    while(t--) {
        solve();
    }

    return 0;

}

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

int main() {
    
    int tt;
    cin >> tt;
    while(tt--) {
        
        long long n, m;
        cin >> n >> m;
        
        vector<long long>v(n), t(m);
        for(auto &x : v) cin >> x;
        for(auto &x : t) cin >> x;
        
        multiset<long long>st;
        deque<long long>dq;
        
        //sort(t.begin(), t.end());
        for(auto i : t) {
            dq.push_back(i);
        }
        
        for(auto i : v) {
            st.insert(i);
        }
        
        bool exist = true;
        
        while(true) {
            
            long long el = dq.front();
            // cout << "el : " << el << endl;
            
            // cout << "Before :- " << endl;
            // cout << "st : ";
            // for(auto j : st) {
            //     cout << j << " ";
            // } cout << endl;
            
            // cout << "dq : ";
            // for(auto j : dq) {
            //     cout << j << " ";
            // } cout << endl;
            
            if(el == 1 && st.find(el) == st.end()) {
                exist = false;
                break;
            }
            
            dq.pop_front();
            
            if(st.find(el) != st.end()) {
                st.erase(st.find(el));
            }
            else {
                long long left = el/2;
                long long right = el-left;
                
                if(st.find(left) == st.end() && st.find(right) == st.end()) {
                    dq.push_front(left);
                    dq.push_front(right);
                }
                else if(st.find(left) != st.end()) {
                    dq.push_front(right);
                    st.erase(st.find(left));
                }
                else {
                    dq.push_front(left);
                    st.erase(st.find(right));
                }
            }
            
            if((int)st.size() == 0) {
                break;
            }
            if((int)dq.size() == 0) {
                break;
            }
            
            // cout << "After :- " << endl;
            // cout << "st : ";
            // for(auto j : st) {
            //     cout << j << " ";
            // } cout << endl;
            
            // cout << "dq : ";
            // for(auto j : dq) {
            //     cout << j << " ";
            // } cout << endl;
        }
        
        if(exist == true && (int)st.size() == 0 && (int)dq.size() == 0) {
            cout << "Yes" << endl;
        }
        else cout << "No" << endl;
    }
}