Problem: 2061D - Kevin and Numbers
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Time limit exceeded on test 3):
#include <bits/stdc++.h>
using namespace std;

#define fastIO                   \
    ios::sync_with_stdio(false); \
    cin.tie(NULL);               \
    cout.tie(NULL);              \
    cout.precision(numeric_limits<double>::max_digits10);
#define int long long

const int M = 1e9 + 7;

bool check(int n, unordered_map<int, int> &mp, int mode)
{
    while (true)
    {
        if (mp.find(n) != mp.end() && mp[n] > 0)
        {
            mp[n]--;
            if (mode == 1)
            {
                mp[n]--;
            }
            if (mp[n] == 0)
            {
                mp.erase(n);
            }
            return true;
        }

        if (n == 1 && mp.find(1) == mp.end())
        {
            return false;
        }

        if (n & 1)
        {
            return check((n - 1) / 2, mp, 0) && check((n + 1) / 2, mp, 0);
        }

        n /= 2;
        mode = 1;
    }
}

void ved()
{
    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(m);
    unordered_map<int, int> mp;

    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        mp[a[i]]++;
    }

    for (int i = 0; i < m; i++)
    {
        cin >> b[i];
    }

    for (int i = 0; i < m; i++)
    {
        if (!check(b[i], mp, 0))
        {
            cout << "No" << endl;
            return;
        }
    }

    if (!mp.empty())
    {
        cout << "No" << endl;
        return;
    }

    cout << "Yes" << endl;
}

int32_t main()
{
    fastIO;

    int t;
    cin >> t;
    while (t--)
    {
        ved();
    }
    return 0;
}


Submission (verdict: Time limit exceeded on test 3):
#include <bits/stdc++.h>
using namespace std;

#define fastIO                   \
    ios::sync_with_stdio(false); \
    cin.tie(NULL);               \
    cout.tie(NULL);              \
    cout.precision(numeric_limits<double>::max_digits10);
#define int long long

const int M = 1e9 + 7;

bool check(int n, unordered_map<int, int> &mp, int mode)
{
    queue<pair<int, int>> q;
    q.push({n, mode});

    while (!q.empty())
    {
        auto [curr, mode] = q.front();
        q.pop();

        if (mp.find(curr) != mp.end() && mp[curr] > 0)
        {
            mp[curr]--;
            if (mode == 1)
            {
                mp[curr]--;
            }
            if (mp[curr] == 0)
            {
                mp.erase(curr);
            }
            continue;
        }

        if (curr == 1 && mp.find(1) == mp.end())
        {
            return false;
        }

        if (curr & 1)
        { 
            q.push({(curr - 1) / 2, 0});
            q.push({(curr + 1) / 2, 0});
        }
        else
        {
            q.push({curr / 2, 1});
        }
    }
    return true;
}


void ved()
{
    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(m);
    unordered_map<int, int> mp;

    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        mp[a[i]]++;
    }

    for (int i = 0; i < m; i++)
    {
        cin >> b[i];
    }

    for (int i = 0; i < m; i++)
    {
        if (!check(b[i], mp, 0))
        {
            cout << "No" << endl;
            return;
        }
    }

    if (!mp.empty())
    {
        cout << "No" << endl;
        return;
    }

    cout << "Yes" << endl;
}

int32_t main()
{
    fastIO;

    int t;
    cin >> t;
    while (t--)
    {
        ved();
    }
    return 0;
}