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;
#define int long long
#define ld long double
#define mset multiset
#define umap unordered_map
#define PII pair<int, int>
#define fi first
#define se second
#define lc u << 1
#define rc u << 1 | 1
#define lowbit(x) (x & (-x))
#define PI acos(-1)
#define ll long long
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
const int mod = 998244353;
const int INF = 1e18;
const int N = 1e5 + 10;
//==================================================================================
void solve()
{
    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(m);
    for (auto &x : a)
        cin >> x;
    for (auto &x : b)
        cin >> x;
    multiset<int> sa, sb;
    for (auto x : a)
        sa.insert(x);
    for (auto x : b)
        sb.insert(x);
    while (sa.size() != sb.size() && (sa.size()) && sb.size())
    {
        if (*sa.begin() == *sb.begin())
        {
            sa.erase(sa.begin());
            sb.erase(sb.begin());
        }
        if (*sa.begin() > *sb.begin())
            break;
        if (*sa.begin() < *sb.begin())
        {
            int a1 = *sa.begin();
            sa.erase(sa.begin());
            int b1 = *sb.begin();
            int a2 = b1 - a1;
            if (sa.find(a2) != sa.end())
            {
                if (a2 - a1 >= 0 && a2 - a1 <= 1)
                {
                    sa.erase(sa.find(a2));
                    sb.erase(sb.find(b1));
                }
            }
            else
            {
                a2 = *sa.begin();
                sa.erase(sa.begin());
                if (a2 - a1 >= 0 && a2 - a1 <= 1)
                {
                    sa.insert(a1 + a2);
                }
                else
                    break;
            }
        }
    }
    if (sa != sb)
        return cout << "NO" << '\n', void();
    return cout << "YES" << "\n", void();
}
//==================================================================================
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    // freopen("test.in", "r", stdin);
    // freopen("test.out", "w", stdout);
    int T_T = 1;
    cin >> T_T;
    while (T_T--)
        solve();
    return 0;
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define mset multiset
#define umap unordered_map
#define PII pair<int, int>
#define fi first
#define se second
#define lc u << 1
#define rc u << 1 | 1
#define lowbit(x) (x & (-x))
#define PI acos(-1)
#define ll long long
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
const int mod = 998244353;
const int INF = 1e18;
const int N = 1e5 + 10;
//==================================================================================
void solve()
{
    int n, m;
    cin >> n >> m;
    multiset<int> a, b;
    for (int i = 1; i <= n; i++)
    {
        int x;
        cin >> x;
        a.insert(x);
    }
    for (int i = 1; i <= m; i++)
    {
        int x;
        cin >> x;
        b.insert(x);
    }
    while (b.size() && b.size() < a.size())
    {
        int tb = *b.rbegin();
        if (a.find(tb) != a.end())
        {
            a.erase(a.find(tb));
            b.erase(b.find(tb));
        }
        else
        {
            int b1 = tb / 2;
            int b2 = tb - b1;
            b.erase(b.find(tb));
            b.insert(b1);
            b.insert(b2);
        }
    }
    if (a == b)
        return cout << "Yes" << '\n', void();
    return cout << "No" << '\n', void();
}
//==================================================================================
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    // freopen("test.in", "r", stdin);
    // freopen("test.out", "w", stdout);
    int T_T = 1;
    cin >> T_T;
    while (T_T--)
        solve();
    return 0;
}