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())
    {
        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 a2 = *sa.begin();
            sa.erase(sa.begin());
            if (a2 - a1 > 2)
                break;
            else
            {
                sa.insert(a1 + a2);
            }
        }
    }
    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: 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;
}