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

Previous 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();
    }
}


Submission (verdict: Accepted):
#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;
    priority_queue<ll> used;
    map<ll, ll> vec;
    FOR(0, n, i){
        ll a;
        cin >> a;
        vec[a]++;
    }
    FOR(0, m, j){
        ll a;
        cin >> a;
        used.push(a);
    }
    ll cnt = 0, sz = n;
    while (cnt < n-m){
        if (!used.size() || !vec.size()){
            cout << "No\n";
            return;
        }
        ll a = used.top();
        if (vec[a]){
            vec[a]--;
            sz--;
        }else{
            cnt++;
            used.push(a/2);
            used.push(ceil(a / 2.0));
        }
        used.pop();
    }
    if (sz == used.size()){
        while (used.size()){
            ll a = used.top();
            if (vec[a] == 0){
                cout << "No\n";
                return;
            }
            vec[a]--;
            used.pop();
        }
        cout << "Yes\n";
    }else cout << "No\n";
}

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