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

Solution 1 (runtime: 375 ms):
#include <bits/stdc++.h>

using namespace std;

#define int long long
#define IOS ios::sync_with_stdio(false); cin.tie(nullptr);

// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//std::mt19937 rnd(std::chrono::steady_clock::now().time_since_epoch().count());

const int INF = 1e18 + 7;
const long double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 100;

inline void solve() {
    int n, m;
    cin >> n >> m;
    map<int, int> cnt;
    int sa = 0, sb = 0;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        ++cnt[x];
        sa += x;
    }
    vector<int> b(m);
    for (int i = 0; i < m; ++i) {
        cin >> b[i];
        sb += b[i];
    }
    if (sa != sb) {
        cout << "No\n";
        return;
    }
    sort(b.begin(), b.end());

    function<bool(int)> check = [&] (int x) {
        if (x == 0) return false;
        if (cnt[x] >= 1) {
            --cnt[x];
            return true;
        }
        if (x % 2 == 0) {
            return check(x / 2) && check(x / 2);
        }
        return check(x / 2) && (check((x - 1) / 2) || check((x + 1) / 2));
    };

    for (auto i : b) {
        if (!check(i)) {
            cout << "No\n";
            return;
        }
    }
    cout << "Yes\n";
}

int32_t main() {
    IOS;
    pmr::monotonic_buffer_resource memory;
    pmr::set_default_resource(&memory);
    //    freopen("input.txt", "r", stdin);
    //    freopen("seq.out", "w", stdout);
    // clock_t tStart = clock();

    int tt = 1;
    cin >> tt;
    while (tt --> 0) {
        solve();
    }
    //    cerr << "Runtime is:" << (long double) (clock() - tStart) / CLOCKS_PER_SEC << '\n';
    return 0;
}

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

typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while(t--){
        int n, m;
        cin >> n >> m;
        vector<ll> a(n);
        vector<ll> b(m);
        for(auto &x: a) cin >> x;
        for(auto &x: b) cin >> x;
        ll sum_a = 0, sum_b = 0;
        for(auto x: a) sum_a += x;
        for(auto x: b) sum_b += x;
        if(sum_a != sum_b){
            cout << "No\n";
            continue;
        }
        sort(a.begin(), a.end(), greater<ll>());
        // Sort b in descending order
        sort(b.begin(), b.end(), greater<ll>());
        // Use a max heap for b
        priority_queue<ll> pq;
        for(auto x: b) pq.push(x);
        // Sort a descending
        sort(a.begin(), a.end(), greater<ll>());
        int idx = 0;
        bool ok = true;
        while(!pq.empty()){
            ll current = pq.top(); pq.pop();
            if(idx < n && current == a[idx]){
                idx++;
                continue;
            }
            if(current < (idx < n ? a[idx] : 1)){
                ok = false;
                break;
            }
            if(current == 1){
                ok = false;
                break;
            }
            // Split current into two parts
            ll half1 = current / 2;
            ll half2 = current - half1;
            if(half1 < 1 || half2 < 1){
                ok = false;
                break;
            }
            pq.push(half1);
            pq.push(half2);
        }
        if(idx == n && ok){
            cout << "Yes\n";
        }
        else{
            cout << "No\n";
        }
    }
}