Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>
#define prll(a, b, c, d) cout << a << ' ' << b << ' ' << c << ' ' << d << '\n';
#define FOR(a, b, i) for (long long i = a; i < b; i++)
#define FORR(a, b, i) for (long long i = a; i > b; --i)
#define FOR_vec(vec, i) for (auto &i : vec)
#define OUT(a) FOR_vec(a, i) cout << i << ' '; cout << "\n";
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define inf INT_MAX

using namespace std;
using ll = long long;
using db = long double;
using str = string;

const ll mod = 998244353;

bool rec(ll a, multiset<ll> &vec){
    auto it = find(all(vec), a);
    if (it != vec.end()){
        vec.erase(it);
        return 1;
    }
    if (a == 1) return 0;
    if (a % 2) return (rec(a/2, vec) && rec(a/2+1, vec));
    else return (rec(a/2, vec) && rec(a/2, vec));
}

void logik(){
    ll n, m;
    cin >> n >> m;
    multiset<ll> vec;
    FOR(0, n, i){
        ll a;
        cin >> a;
        vec.insert(a);
    }
    FOR(0, m, j){
        ll a;
        cin >> a;
        if (!rec(a, vec)){
            cout << "No\n";
            return;
        }
    }
    if (vec.size() == 0) cout << "Yes\n";
    else cout << "No\n";
//    cout.flush();
}

int main() {
    FAST;
//    OUT(vec);
    ll t;
    cin >> t;
    while (t--){
        logik();
    }
}


Submission (verdict: Time limit exceeded on test 7):
#include <bits/stdc++.h>
#define prll(a, b, c, d) cout << a << ' ' << b << ' ' << c << ' ' << d << '\n';
#define FOR(a, b, i) for (long long i = a; i < b; i++)
#define FORR(a, b, i) for (long long i = a; i > b; --i)
#define FOR_vec(vec, i) for (auto &i : vec)
#define OUT(a) FOR_vec(a, i) cout << i << ' '; cout << "\n";
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define inf INT_MAX

using namespace std;
using ll = long long;
using db = long double;
using str = string;



void logik(){
    ll n, m;
    cin >> n >> m;
    multiset<ll> vec, used;
    FOR(0, n, i){
        ll a;
        cin >> a;
        vec.insert(a);
    }
    FOR(0, m, j){
        ll a;
        cin >> a;
        used.insert(a);
    }
    ll cnt = 0;
    while (cnt < n-m){
        if (!used.size() || !vec.size()){
            cout << "No\n";
            return;
        }
        ll a = *prev(used.end());
        auto it = find(all(vec), a);
        if (it != vec.end()){
            vec.erase(it);
        }else{
            cnt++;
            used.insert(a/2);
            used.insert(ceil(a / 2.0));
        }
        used.erase(prev(used.end()));
//        OUT(vec);
//        OUT(used);
    }
    if (vec.size() == used.size()){
        ll z = vec.size();
        FOR(0, z, i){
            ll a = *(used.begin()), b = *(vec.begin());
            if (a != b){
                cout << "No\n";
//                cout.flush();
                return;
            }
            used.erase(used.begin());
            vec.erase(vec.begin());
        }
        cout << "Yes\n";
    }else cout << "No\n";
//    cout.flush();
}

int main() {
    FAST;
//    OUT(vec);
    ll t;
    cin >> t;
    while (t--){
        logik();
    }
}