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

Solution 1 (runtime: 359 ms):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

#define  DBG(x         ) cerr<<#x<<" = "<<(x)<<endl;
#define DBG2(x, y      ) cerr<<#x<<" = "<<(x)<<", "<<#y<<" = "<<(y)<<endl;
#define DBG3(x, y, z   ) cerr<<#x<<" = "<<(x)<<", "<<#y<<" = "<<(y)<<", "<<#z<<" = "<<(z)<<endl;
#define DBG4(x, y, z, w) cerr<<#x<<" = "<<(x)<<", "<<#y<<" = "<<(y)<<", "<<#z<<" = "<<(z)<<", "<<#w<<" = "<<(w)<<endl;
#define SEPA cerr<<" ============ "<<endl;

#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fort(i, a, b) for(int i = int(a); i <= int(b); i++)

#define sz(s) int(s.size())
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define pb push_back
#define endl '\n'
#define fst first
#define snd second
#define pii pair<int, int>
#define pll pair<long long, long long>
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;

bool erase_numbers(int x, multiset<int> &sa){
    if(sa.find(x) != sa.end()){
        sa.erase(sa.find(x));
        return true;
    }
    if(x == 1) return false;
    int n1 = x / 2;
    int n2 = (x + 1) / 2;
    bool f1 = erase_numbers(n1, sa);
    if(!f1) return false;
    bool f2 = erase_numbers(n2, sa);
    if(!f2) return false;
    return true;
}

void run_case(){
    int n, m; cin>>n>>m;
    multiset<int> sa, sb;
    forn(i, n){
        int value; cin>>value;
        sa.insert(value);
    }
    forn(i, m){
        int value; cin>>value;
        sb.insert(value);
    }

    //for(int x : sa) cout<<x<<' '; cout<<endl; for(int x : sb) cout<<x<<' '; cout<<endl;

    for(auto it = sb.rbegin(); it != sb.rend(); it++){
        int x = *it;
        if(!erase_numbers(x, sa)){
            cout<<"No"<<endl;
            return;
        }
    }
    cout<<(sz(sa) == 0 ? "Yes" : "No")<<endl;
}

int main(){
    fast_io
    //freopen("input.in", "r", stdin);
    bool mtc = true;
    int tc = 1; if(mtc) cin>>tc;
    for(int i = 0; i < tc; i++) run_case();
    return 0;
}

Solution 2 (runtime: 968 ms):
#include <iostream>

#include <map>

#include<unordered_map>

#include <set>

#include <unordered_set>

#include<iterator>

#include<string>

#include<algorithm>

#include<vector>

#include<deque>

#include <random>

#include <numeric>

#include <chrono>

#include <bitset>

#include <stack>

#include <queue>





using namespace std;









int modpow(int x, int n, int m) {

    if (n == 0) return 1 % m;

    long long u = modpow(x, n / 2, m);

    u = (u * u) % m;

    if (n % 2 == 1) u = (u * x) % m;

    return u;

}

































map<long long int, long long int>C;

map<long long int, vector<long long int>> N0;



long long int scory(long long int x) {

    if (C.find(x) != C.end()) {

        return C[x];

    }

    else {

        if (N0.find(x) == N0.end()) {

            C[x] = x;

            return C[x];



        }

        else {

            vector<long long int> tmp = N0[x];

            long long int mx = x;

            for (auto e : tmp) {

                if (e != 1) {

                    mx = max(mx, scory(e + x - 1));

                }



            }

            C[x] = mx;

            return C[x];

        }

    }

}





bool* vis;

bool* parent;

vector<vector<int>> adj;



void dfs(int a)

{

    vis[a] = true;

    parent[a] = true;











    for (auto e : adj[a])

    {



        if (!vis[e])  dfs(e);





    }





    parent[a] = false;





}



class MinStack {

public:

    vector<int> st;

    MinStack() {

        st = vector<int>();

    }



    void push(int val) {

        st.push_back(val);

    }



    void pop() {

        st.pop_back();

    }



    int top() {

        return st.back();

    }



    int getMin() {

        return *min_element(st.begin(), st.end());

    }

};









int main() {



    int t;

    cin >> t;

    for (int i = 0; i < t; i++) {

        int n, m;

        cin >> n >> m;

        map<int, int> A, B;

        int a;

        int c;

        for (int j = 0; j < n; j++) {

            cin >> a;

            A[a]++;

        }

        for (int j = 0; j < m; j++) {

            cin >> a;

            B[a]++;

        }

        while ((B.size() != NULL) && (A.size() != NULL)) {

            if ((B.rbegin()->first < A.rbegin()->first)) {

                break;

            }

            a = B.rbegin()->first;

            c = B.rbegin()->second;

            B.erase(a);

            if (A[a] > c) {

                A[a] = A[a] - c;

            }

            else {

                c = c - A[a];

                A.erase(a);

                if (c != 0) {

                    if (a % 2 == 0) { //dissect

                        B[a / 2] = B[a / 2]+ 2 * c;

                    }

                    else {

                        B[a / 2] = B[a / 2]+c;

                        B[(a / 2) + 1] = B[(a / 2) + 1]+c;

                    }

                }



            }

        }

        if ((B.size() == 0) && (A.size() == 0)) {

            cout << "YES\n";

        }

        else {

            cout << "NO\n";

        }



    }

















}