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

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

bool check(llt &num, map<llt, llt> &mp)
{
    map<llt, llt> mp2;
    mp2[num]=1;
    
    while (true)
    {
        map<llt, llt> mp3;
        mp3 = mp2;
        if (mp2.size() == 0)
            break;
        for (auto i : mp3)
        {
            if (mp[i.first] >= i.second)
            {
                mp[i.first] -= i.second;
                mp2.erase(i.first);
                continue;
            }
            else if (mp[i.first] < i.second)
            {
                mp2[i.first] -= i.second;
                mp.erase(i.first);
            }
            if (i.first != 1)
                {
                    if (i.first % 2 == 1)
                    {
                        mp2[i.first / 2] = i.second;
                        mp2[i.first / 2 + 1] = i.second;
                    }
                    else if (i.first % 2 == 0)
                    {
                        mp2[i.first / 2] = i.second * 2;
                    }
                    mp2.erase(i.first);
                }
        }
        for (auto i : mp2)
        {
            if (i.first == 1 && mp[1] < i.second)
            {
                return false;
            }
        }
    }
    return true;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    llt t;
    cin >> t;
    while (t--)
    {
        llt n, m;
        cin >> n >> m;
        vector<llt> a(n), b(m);
        llt suma=0,sumb=0;

        for (int i = 0; i < n; i++){
            cin >> a[i];suma+=a[i];}
        for (int i = 0; i < m; i++){
            cin >> b[i];sumb+=b[i];}
        map<llt, llt> mp;
        if(suma!=sumb){
            cout<<"NO"<<endl;continue;
        }
        for (int i = 0; i < n; i++)
        {
            mp[a[i]]++;
        }
        string ans = "YES";
        for (int i = 0; i < m; i++)
        {
            if (check(b[i], mp))
            {
                continue;
            }
            else
            {
                ans = "NO";
                break;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

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

bool check(llt &num, map<llt, llt> &mp)
{
    map<llt, llt> mp2;
    mp2[num] = 1;

    while (true)
    {
        map<llt, llt> mp3;
        mp3 = mp2;
        if (mp2.size() == 0){
            break;
        }
        for (auto i : mp3)
        {
            if (mp[i.first] >= i.second)
            {
                mp[i.first] -= i.second;
                mp2.erase(i.first);
                continue;
            }
            else if (mp[i.first] < i.second)
            {
                mp2[i.first] -= mp[i.first];
                mp.erase(i.first);
            }
            if (i.first != 1)
            {
                if (i.first % 2 == 1)
                {
                    mp2[i.first / 2] = i.second;
                    mp2[i.first / 2 + 1] = i.second;
                }
                else if (i.first % 2 == 0)
                {
                    mp2[i.first / 2] = i.second * 2;
                }
                mp2.erase(i.first);
            }
        }
        for (auto i : mp2)
        {
            if (i.first == 1 && mp[1] < i.second)
            {
                return false;
            }
        }
    }
    return true;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    llt t;
    cin >> t;
    while (t--)
    {
        llt n, m;
        cin >> n >> m;
        vector<llt> a(n), b(m);
        llt suma = 0, sumb = 0;

        for (int i = 0; i < n; i++)
        {
            cin >> a[i];
            suma += a[i];
        }
        for (int i = 0; i < m; i++)
        {
            cin >> b[i];
            sumb += b[i];
        }
        map<llt, llt> mp;
        if (suma != sumb)
        {
            cout << "NO" << endl;
            continue;
        }
        for (int i = 0; i < n; i++)
        {
            mp[a[i]]++;
        }
        string ans = "YES";
        for (int i = 0; i < m; i++)
        {
            if (check(b[i], mp))
            {
                continue;
            }
            else
            {
                ans = "NO";
                break;
            }
        }
        cout << ans << endl;
    }
    return 0;
}