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

Previous submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define endl '\n'
#define pb push_back
#define int long long int
#define deb(x) cerr << x << endl;
#define deb2(x, y) cerr << x << " " << y << endl;
#define deb3(x, y, z) cerr << x << " " << y << " " << z << endl;
#define f_(i, j, k) for (ll i = j; i < k; i++)
#define f__(i, j, k) for (ll i = j; i >= k; i--)

// order_of_key(k)   --> count of elements smaller than k (0 based index)
// find_by_order(k)  --> iterator to the kth element (k=0 for first element)
template <typename T> using maxpq = priority_queue<T, vector<T>>;
template <typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template <typename T> istream &operator>>(istream &in, vector<T> &v) { for (auto &x: v) cin >> x; return in; }
template <typename T> ostream &operator<<(ostream &out, vector<T> &v) { for (auto &x: v) cout << x << " "; return out; }
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pp;
typedef pair<int, pp> ppp;
const int INF = 1e18+5, MOD = 1e9+7;  // 998244353;
const int MAXN = 2e5+5;

int exp(int a, int b, int m) {
    if (!b) return 1LL;
    if (b%2 == 0) return exp((a*a)%m, b/2, m);
    else return (a * exp((a*a)%m, b/2, m)) % m;
}
 
int moiv(int n, int m) {
    return exp(n, m-2, m);
}

bool fun(int x, map<int, int> &mp) {
    if (x==1) {
        if (!mp[x]) return false;
        mp[x]--;
        return true;
    }
    bool flag = true;
    int a = x/2, b = x/2;
    if (x%2) a++;
    if (mp[a]) mp[a]--;
    else flag &= fun(a, mp);
    if (mp[b]) mp[b]--;
    else flag &= fun(b, mp);
    return flag;
}

void solve()
{
    int n, m;
    cin >> n >> m;

    vector<int> a(n), b(m);
    cin >> a >> b;

    int sa = accumulate(a.begin(), a.end(), 0LL);
    int sb = accumulate(b.begin(), b.end(), 0LL);
    if (sa != sb) {
        cout << "No" << endl;
        return;
    }

    map<int, int> mp;
    f_(i, 0, n) mp[a[i]]++;

    bool flag = true;
    f_(i, 0, m) {
        if (mp[b[i]]) mp[b[i]]--;
        else flag &= fun(b[i], mp);
        if (!flag) break;
    }

    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int t = 1;
    cin >> t;

    while (t--)
        solve();

    return 0;
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define endl '\n'
#define pb push_back
#define int long long int
#define deb(x) cerr << x << endl;
#define deb2(x, y) cerr << x << " " << y << endl;
#define deb3(x, y, z) cerr << x << " " << y << " " << z << endl;
#define f_(i, j, k) for (ll i = j; i < k; i++)
#define f__(i, j, k) for (ll i = j; i >= k; i--)

// order_of_key(k)   --> count of elements smaller than k (0 based index)
// find_by_order(k)  --> iterator to the kth element (k=0 for first element)
template <typename T> using maxpq = priority_queue<T, vector<T>>;
template <typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template <typename T> istream &operator>>(istream &in, vector<T> &v) { for (auto &x: v) cin >> x; return in; }
template <typename T> ostream &operator<<(ostream &out, vector<T> &v) { for (auto &x: v) cout << x << " "; return out; }
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pp;
typedef pair<int, pp> ppp;
const int INF = 1e18+5, MOD = 1e9+7;  // 998244353;
const int MAXN = 2e5+5;

int exp(int a, int b, int m) {
    if (!b) return 1LL;
    if (b%2 == 0) return exp((a*a)%m, b/2, m);
    else return (a * exp((a*a)%m, b/2, m)) % m;
}
 
int moiv(int n, int m) {
    return exp(n, m-2, m);
}

void solve()
{
    int n, m;
    cin >> n >> m;

    vector<int> a(n), b(m);
    cin >> a >> b;

    int sa = accumulate(a.begin(), a.end(), 0LL);
    int sb = accumulate(b.begin(), b.end(), 0LL);
    if (sa != sb) {
        cout << "No" << endl;
        return;
    }

    multiset<int> ma, mb;
    f_(i, 0, n) ma.insert(a[i]);
    f_(i, 0, m) mb.insert(b[i]);

    while (1) {
        if (mb.empty() || mb.size() > ma.size()) break;
        auto it = *mb.begin();
        if (ma.find(it) != ma.end()) ma.erase(ma.find(it));
        else {
            int x = it/2;
            mb.insert(x);
            if (it%2) x++;
            mb.insert(x);
        }
        mb.erase(mb.find(it));
    }

    if (mb.empty()) cout << "Yes" << endl;
    else cout << "No" << endl;
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int t = 1;
    cin >> t;

    while (t--)
        solve();

    return 0;
}