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

Solution 1 (runtime: 343 ms):
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fastIO\
    ios::sync_with_stdio(false);\
    cin.tie(0);\
    cout.tie(0);\
    cout.precision(numeric_limits<double>::max_digits10);
#define vi vector<int>
#define vvi vector<vector<int>>
#define vpii vector<pair<int, int>>
#define pii pair<int, int>
#define mii map<int, int>
#define pb push_back
#define all(x) (x).begin(), (x).end()
const int P = 1e9+7;

// stack is using DFS (depth first search)
int32_t main(){
    fastIO;
    int t;
    cin >> t;

    while(t--){
        int n, m;
        cin >> n >> m;
        vi ai(n), bi(m);

        int sum1 = 0, sum2 = 0;
        mii mp;

        for(int& i : ai){
            cin >> i;
            sum1 += i;
            mp[i]++;
        }
        for(int& i : bi){
            cin >> i;
            sum2 += i;
        }

        if(sum1 == sum2){
            int flag = 1; // default: it will work
            stack<int> st;

            for(int& b : bi){
                st.push(b);

                while(!st.empty()){
                    int a = st.top();
                    if(mp[a] > 0){
                        mp[a]--;
                        st.pop();
                    }
                    else{
                        if(a == 1){
                            flag = 0;
                            break;
                        }
                        else{
                            st.pop();
                            st.push(a/2);
                            st.push(a/2+a%2);
                        }
                    }
                }

                if(flag == 0){
                    break;
                }
            }

            if(flag == 1){
                cout << "Yes\n";
            }
            else{
                cout << "No\n";
            }

        }
        else{
            cout << "No\n";
        }

    }

    return 0;
}

/* 
// Memory limit exceeded - Using queue and working on one element at once
// queue is using BFS (breadth first search)

int32_t main(){
    fastIO;
    int t;
    cin >> t;

    while(t--){
        int n, m;
        cin >> n >> m;
        vi ai(n), bi(m);

        int sum1 = 0, sum2 = 0;
        mii mp;

        for(int& i : ai){
            cin >> i;
            sum1 += i;
            mp[i]++;
        }
        for(int& i : bi){
            cin >> i;
            sum2 += i;
        }

        if(sum1 == sum2){
            int flag = 1; // default: it will work
            queue<int> q;

            for(int& b : bi){
                q.push(b);

                while(!q.empty()){
                    int a = q.front();
                    if(mp[a] > 0){
                        mp[a]--;
                        q.pop();
                    }
                    else{
                        if(a == 1){
                            flag = 0;
                            break;
                        }
                        else{
                            q.pop();
                            q.push(a/2);
                            q.push(a/2+a%2);
                        }
                    }
                }

                if(flag == 0){
                    break;
                }
            }

            if(flag == 1){
                cout << "Yes\n";
            }
            else{
                cout << "No\n";
            }

        }
        else{
            cout << "No\n";
        }

    }

    return 0;
} */

/* 
// Memory limit exceeded - Using priority_queue and working on all element at once

int32_t main(){
    fastIO;
    int t;
    cin >> t;

    while(t--){
        int n, m;
        cin >> n >> m;
        vi ai(n), bi(m);
        priority_queue<int> pq;

        int sum1 = 0, sum2 = 0;
        mii mp;

        for(int& i : ai){
            cin >> i;
            sum1 += i;
            mp[i]++;
        }
        for(int& i : bi){
            cin >> i;
            sum2 += i;
            pq.push(i);
        }

        if(sum1 == sum2){
            int flag = 1; // default: it will work

            while(!pq.empty()){
                int a = pq.top();
                if(mp[a] > 0){
                    mp[a]--;
                    pq.pop();
                }
                else{
                    if(a == 1){
                        flag = 0;
                        break;
                    }
                    else{
                        pq.pop();
                        pq.push(a/2);
                        pq.push(a/2+a%2);
                    }
                }
            }

            if(flag == 1){
                cout << "Yes\n";
            }
            else{
                cout << "No\n";
            }

        }
        else{
            cout << "No\n";
        }

    }

    return 0;
} */

/* 
Tried - wrong

int32_t main(){
    fastIO;
    int t;
    cin >> t;

    while(t--){
        int n, m;
        cin >> n >> m;

        mii mp1, mp2;
        for(int i = 0; i < n; i++){
            int temp;
            cin >> temp;

            mp1[temp]++;
        }
        for(int i = 0; i < m; i++){
            int temp;
            cin >> temp;

            mp2[temp]++;
        }

        for(auto& i : mp1){
            int k = min(i.second, mp2[i.first]);

            i.second -= k;
            mp2[i.first] -= k;
        }

        priority_queue<int, vi, greater<int>> pqa, pqb;

        for(auto& i : mp1){
            while(i.second--){
                pqa.push(i.first);
            }
        }
        for(auto& i : mp2){
            while(i.second--){
                pqb.push(i.first);
            }
        }

        int flag = 1; // default: true

        while(!pqb.empty() && !pqa.empty()){

            if(pqa.top() == pqb.top()){

                pqa.pop();
                pqb.pop();
            }
            else if(pqa.top() < pqb.top()){

                int a1 = pqa.top();
                pqa.pop();

                if(pqa.empty() || (pqa.top()-a1) > 1){
                    flag = 0;
                    break;
                }
                else{
                    int a2 = pqa.top();
                    pqa.pop();

                    pqa.push(a1+a2);
                }
            }
            else{ // (pqa.top() > pqb.top())

                flag = 1;
                break;
            }
        }

        if(flag == 1 && pqa.empty() && pqb.empty()){
            cout << "Yes\n";
        }
        else{
            cout << "No\n";
        }

    }
    return 0;
} */


// Think from the result
// Think wrt range (only 26 alphabets/ operations, range of int)
// Think it as separate
// Think if it can be done linearly/ bitwise
// Observe the very basic thing that it follows
// Think of limits of answer
// Reduce the number of variables used (make 2 variables as +&- and convert to 1)
// Think to iterate from both left to right & right to left
// Think of result required before calculation
// Change the initial assumption which you set
// Dont use predefined function (set or map or sort) if the no. of elements is large
// Think it as very simple
// Change the order of operation in multiple for-loops
// Think if it can be done in dp

Solution 2 (runtime: 1780 ms):
// Source: https://usaco.guide/general/io
 
#include <bits/stdc++.h>
#include <sys/types.h>
using namespace std;
#define MAXN 200010
#define MOD 998244353
typedef long long ll;
typedef pair<ll, ll> pi;

bool solve(ll cur, map<ll, ll> &mp, ll total, int &n) {
    if (total > n) return false;
    ll k = min(total, mp[cur]);
    total -= k;
    mp[cur] -= k;
    if (total == 0) return true;
    else if (cur == 1) return false;
    else {
        if (cur % 2 == 1) {
            return solve(cur/2, mp, total, n) & solve((cur+1)/2, mp, total, n);
        } else return solve(cur/2, mp, total*2, n);
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int tt; cin >> tt;
    while (tt--) {
        int n, m; cin >> n >> m;
        vector<ll> b(m);
        map<ll, ll> mp;
        for (int i = 0; i < n; i++) {
            ll x; cin >> x;
            mp[x]++;
        }
        for (int i = 0; i < m; i++) cin >> b[i];
        // so first we remove all odd and even numbers which exist in both a and b
        // and we notice making a number is a unique procedure
        // which it is of course
        // and we can determine the procedure in log(x_i) time ~32 for 10^9
        // thus we just do this until we cant or we can
        bool pos = true;
        for (int i = 0; i < m; i++) {
            ll x = b[i];
            pos = solve(x, mp, 1, n);
            if (!pos) break;
        }
        for (auto const &[k, v] : mp) {
            if (v != 0) pos = false;
        }
        if (pos) cout << "YES" << "\n";
        else cout << "NO" << "\n";
    }
}