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

Previous submission (verdict: Time limit exceeded on test 41):
#include <bits/stdc++.h>
#define ll long long
#define int ll
#define pii pair<int, int> 
#define endl '\n'
#define mod 998244353
using namespace std;
bool f(int x, multiset<int>& v)
{
    if (x % 2 == 0)
    {
        auto moxi = v.find(x);
        if (moxi != v.end())
        {
            v.erase(moxi);
            return 1;
        }
        else if (x / 2)
        {
            int f1 = f(x / 2, v);
            int f2 = f(x / 2, v);
            return (f1 && f2);
        }
return 0;
    }
    else
    {
        auto moxi = v.find(x);
        if (moxi != v.end())
        {
            v.erase(moxi);
            return 1;
        }
        else if (*v.begin() > x)
            return 0;
        else if (x / 2)
        {
            int f1 = f(x / 2, v);
            int f2 = f(x / 2 + 1, v);
            return (f1 && f2);
        }
return 0;

    }
}


void solve()
{
    int n, m;   cin >> n >> m;
    int s1 = 0, s2 = 0;
    vector<int> b(m);
    multiset<int> a;

    for (int i = 0; i < n; i++)
    {
        int x;  cin >> x;
        a.insert(x);
        s1 += x;
    }

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

    if (s1 != s2)
        return cout << "No" << endl, void();

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

    cout << "Yes" << endl;
}


signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;  cin >> t;
    
    while (t--)
        solve();

    return 0;
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
#define ll long long
#define int ll
#define pii pair<int, int> 
#define endl '\n'
#define mod 998244353
using namespace std;
bool f(int x, multiset<int>& v)
{
    if (x % 2 == 0)
    {
        auto moxi = v.find(x);
        if (moxi != v.end())
        {
            v.erase(moxi);
            return 1;
        }
else if (*v.begin() > x)
            return 0;

        else if (x / 2)
        {
            int f1 = f(x / 2, v);
            int f2 = f(x / 2, v);
            return (f1 && f2);
        }
return 0;
    }
    else
    {
        auto moxi = v.find(x);
        if (moxi != v.end())
        {
            v.erase(moxi);
            return 1;
        }
        else if (*v.begin() > x)
            return 0;
        else if (x / 2)
        {
            int f1 = f(x / 2, v);
            int f2 = f(x / 2 + 1, v);
            return (f1 && f2);
        }
return 0;

    }
}


void solve()
{
    int n, m;   cin >> n >> m;
    int s1 = 0, s2 = 0;
    vector<int> b(m);
    multiset<int> a;

    for (int i = 0; i < n; i++)
    {
        int x;  cin >> x;
        a.insert(x);
        s1 += x;
    }

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

    if (s1 != s2)
        return cout << "No" << endl, void();

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

    cout << "Yes" << endl;
}


signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;  cin >> t;
    
    while (t--)
        solve();

    return 0;
}