Problem: 2061D - Kevin and Numbers
Language: C++17 (GCC 7-32)

Previous submission (verdict: Memory limit exceeded on test 1):
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <fstream>
#include <ostream>
#include <sstream>
#include <set>
#include <stack>
#include <set>
#include <queue>
#include <deque>
#include <bits/stdc++.h>
#include <fstream>
#include <numeric>
#include <cstdio>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;

using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;


typedef long long ll;

ll MOD = 1e9 + 7;

/* long long fast_power(long long base, long long power) {
    long long result = 1;
    while(power > 0) {

        if(power % 2 == 1) { // Can also use (power & 1) to make code even faster
            result = (result*base) % MOD;
        }
        base = (base * base) % MOD;
        power = power / 2; // Can also use power >>= 1; to make code even faster
    }
    return result;
} */

/*ll UpSearch(vector<ll> &v , int low , int high , ll x) {
    int ans = -1;
    while(low <= high) {
        int mid = low + (high - low) / 2;
        if(v[mid] >= x) {
            ans = mid;
            high = mid - 1;
        }
        else low = mid + 1;
    }
    return ans;
}*/
/*ll LowSearch(vector<ll> &v , int low , int high , ll x) {
    int ans = -1;
    while(low <= high) {
        int mid = low + (high - low) / 2;
        if(v[mid] <= x) {
            ans = mid;
            low = mid + 1;
        }
        else high = mid - 1;
    }
    return ans;
}*/

/* ll search(vector<ll> &v , int low , int high , ll x) {
    int ans = -1;
    while(low <= high) {
        int mid = low + (high - low) / 2;
        if(v[mid] <= x) {
            ans = mid;
            low = mid + 1;
        }
        else high = mid - 1;
    }
    return ans;
} */

/* void findSubsets(vector<ll> nums, int n, vector<pair<ll , int>> &AllSubSets)
{
    // Loop through all possible subsets using bit manipulation
    for (int i = 0; i < (1 << n); i++) {

        ll sum = 0;
        int siz = 0;

        // Loop through all elements of the input array
        for (int j = 0; j < n; j++) {

            // Check if the jth bit is set in the current subset
            if ((i & (1 << j)) != 0) {

                // If the jth bit is set, add the jth element to the subset
                sum += nums[j];
                siz++;
            }
        }
        AllSubSets.push_back({sum , siz});
    }
} */

/* void findstrings(vector<string> &v , int n) {
    for (int i = 0; i < (1 << n); i++) {
        bitset<32> b(i);
        v.push_back(b.to_string().substr(32-n));
    }
} */


void solve() {
    int n , m;
    cin >> n >> m;
    queue<int> q;
    map<int , int> freq;

    for(int i = 0 ; i < n ; i++) {
        int a; cin >> a;
        freq[a]++;
    }
    int sz = m;
    for(int i = 0 ; i < m ; i++) {
        int a ; cin >> a;
        q.push(a);
        while(!q.empty()) {
            int test = q.front();
            q.pop();
            if(freq[test] > 0) {
                freq[test]--;
                continue;
            }
            if(test / 2 != 0) q.push(test / 2);
            if((test + 1) / 2 != 1) q.push((test + 1) / 2);
            sz++;
        }
    }
    if(sz == n) cout << "YES" << endl;
    else cout << "NO" << endl;
}

int main(){

    int t;
    cin >> t;
    while(t--) solve();

    return 0;
}


Submission (verdict: Accepted):
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <fstream>
#include <ostream>
#include <sstream>
#include <set>
#include <stack>
#include <set>
#include <queue>
#include <deque>
#include <bits/stdc++.h>
#include <fstream>
#include <numeric>
#include <cstdio>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;

using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;


typedef long long ll;

ll MOD = 1e9 + 7;

/* long long fast_power(long long base, long long power) {
    long long result = 1;
    while(power > 0) {

        if(power % 2 == 1) { // Can also use (power & 1) to make code even faster
            result = (result*base) % MOD;
        }
        base = (base * base) % MOD;
        power = power / 2; // Can also use power >>= 1; to make code even faster
    }
    return result;
} */

/*ll UpSearch(vector<ll> &v , int low , int high , ll x) {
    int ans = -1;
    while(low <= high) {
        int mid = low + (high - low) / 2;
        if(v[mid] >= x) {
            ans = mid;
            high = mid - 1;
        }
        else low = mid + 1;
    }
    return ans;
}*/
/*ll LowSearch(vector<ll> &v , int low , int high , ll x) {
    int ans = -1;
    while(low <= high) {
        int mid = low + (high - low) / 2;
        if(v[mid] <= x) {
            ans = mid;
            low = mid + 1;
        }
        else high = mid - 1;
    }
    return ans;
}*/

/* ll search(vector<ll> &v , int low , int high , ll x) {
    int ans = -1;
    while(low <= high) {
        int mid = low + (high - low) / 2;
        if(v[mid] <= x) {
            ans = mid;
            low = mid + 1;
        }
        else high = mid - 1;
    }
    return ans;
} */

/* void findSubsets(vector<ll> nums, int n, vector<pair<ll , int>> &AllSubSets)
{
    // Loop through all possible subsets using bit manipulation
    for (int i = 0; i < (1 << n); i++) {

        ll sum = 0;
        int siz = 0;

        // Loop through all elements of the input array
        for (int j = 0; j < n; j++) {

            // Check if the jth bit is set in the current subset
            if ((i & (1 << j)) != 0) {

                // If the jth bit is set, add the jth element to the subset
                sum += nums[j];
                siz++;
            }
        }
        AllSubSets.push_back({sum , siz});
    }
} */

/* void findstrings(vector<string> &v , int n) {
    for (int i = 0; i < (1 << n); i++) {
        bitset<32> b(i);
        v.push_back(b.to_string().substr(32-n));
    }
} */


void solve() {
    int n , m;
    cin >> n >> m;
    queue<int> q;
    map<int , int> freq;

    for(int i = 0 ; i < n ; i++) {
        int a; cin >> a;
        freq[a]++;
    }
    int sz = m;
    for(int i = 0 ; i < m ; i++) {
        int a ; cin >> a;
        q.push(a);
        while(!q.empty() && q.size() <= n) {
            int test = q.front();
            q.pop();
            if(freq[test] > 0) {
                freq[test]--;
                continue;
            }
            if(test / 2 != 0) q.push(test / 2);
            if((test + 1) / 2 != 1) q.push((test + 1) / 2);
            sz++;
        }
    }
    if(sz == n) cout << "YES" << endl;
    else cout << "NO" << endl;
}

int main(){

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

    return 0;
}