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

Previous submission (verdict: Time limit exceeded on test 6):
// 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) {
    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) & solve((cur+1)/2, mp, total);
        } else return solve(cur/2, mp, total*2);
    }
}

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);
            if (!pos) break;
        }
        for (auto const &[k, v] : mp) {
            if (v != 0) pos = false;
        }
        if (pos) cout << "YES" << "\n";
        else cout << "NO" << "\n";
    }
}

Submission (verdict: Time limit exceeded on test 6):
// 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) {
    if (total >= MAXN) 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) & solve((cur+1)/2, mp, total);
        } else return solve(cur/2, mp, total*2);
    }
}

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);
            if (!pos) break;
        }
        for (auto const &[k, v] : mp) {
            if (v != 0) pos = false;
        }
        if (pos) cout << "YES" << "\n";
        else cout << "NO" << "\n";
    }
}