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

Previous submission (verdict: Wrong answer on test 3):
#include<bits/stdc++.h>
#define int long long
using namespace std;
int mo = 998244353;

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

    vector<int> a(n + 1),b(m + 1);
    map<int,int> mp1,mp2;
    int sum1 = 0,sum2 = 0;
    for(int i=1;i<=n;i++) {
        cin >> a[i];
        sum1 += a[i];
        mp1[a[i]] ++;
    }

    sort(a.begin() + 1,a.end());

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

    sort(b.begin() + 1,b.end());

    if(sum1 != sum2)
    {
        cout << "No\n";
        return;
    }

    for(int i=1;i<=m;i++)
    {
        if(mp1.count(b[i]))
        {
            mp1[b[i]]--;

            if(mp1[b[i]] == 0)
            {
                mp1.erase(b[i]);
            }
            continue;
        }
        
        auto dfs = [&](auto dfs,int x) ->bool
        {
            if(mp1.count(x))
            {
                mp1[x]--;

                if(mp1[b[i]] == 0)
                {
                    mp1.erase(b[i]);
                }

                return true;
            }

            if(mp1.size() == 0 || (*mp1.begin()).first > x)
            {
                return false;
            }

            bool ok1 = dfs(dfs,x/2);
            bool ok2 = 0;
            if(x % 2 == 0) ok2 =  dfs(dfs,x/2);
            else ok2 =  dfs(dfs,x/2 + 1);

            return (ok1 & ok2);
        };

        bool ok = dfs(dfs,b[i]);

        if(ok == false)
        {
            cout << "No\n";
            return;
        }
    }

    cout << "Yes\n";

}

signed main()
{
    int t = 1;
    cin>>t;
    while (t--)
    {
        solve();
    }
    
}

Submission (verdict: Wrong answer on test 3):
#include<bits/stdc++.h>
#define int long long
using namespace std;
int mo = 998244353;

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

    vector<int> a(n + 1),b(m + 1);
    map<int,int> mp1,mp2;
    int sum1 = 0,sum2 = 0;
    for(int i=1;i<=n;i++) {
        cin >> a[i];
        sum1 += a[i];
        mp1[a[i]] ++;
    }

    sort(a.begin() + 1,a.end());

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

    sort(b.begin() + 1,b.end());

    if(sum1 != sum2)
    {
        cout << "No\n";
        return;
    }

    for(int i=1;i<=m;i++)
    {
        auto dfs = [&](auto dfs,int x) ->bool
        {
            if(mp1.count(x))
            {
                mp1[x]--;

                if(mp1[b[i]] == 0)
                {
                    mp1.erase(b[i]);
                }

                return true;
            }

            if(mp1.size() == 0 || (*mp1.begin()).first > x)
            {
                return false;
            }

            bool ok1 = dfs(dfs,x/2);
            bool ok2 = 0;
            if(x % 2 == 0) ok2 =  dfs(dfs,x/2);
            else ok2 =  dfs(dfs,x/2 + 1);

            return (ok1 & ok2);
        };

        bool ok = dfs(dfs,b[i]);

        if(ok == false)
        {
            cout << "No\n";
            return;
        }
    }

    cout << "Yes\n";

}

signed main()
{
    int t = 1;
    cin>>t;
    while (t--)
    {
        solve();
    }
    
}