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

Previous submission (verdict: Wrong answer on test 1):

#include <bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#include "debug.h"
#else
#define deb(...)
#define debArr(...)
#endif
#define ll long long
#define ld long double
#define ull unsigned long long
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define allr(x) rbegin(x), rend(x)
#define alln(x) (begin(x) + 1), (end(x))
#define allrn(x) (rbegin(x)), (rbegin(x) + (sz(x) - 1))
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define FORs(i, a, b) for (int i = a; i <= b; ++i)
#define fi(a, n) for (int i = a; i <= n; ++i)
#define fj(a, n) for (int j = a; j <= n; ++j)
#define fk(a, n) for (int k = a; k <= n; ++k)
#define fl(a, n) for (int l = a; l <= n; ++l)
#define fiz(a, n) for (int i = a; i < n; ++i)
#define trv(x, a) for (auto &x : a)
#define endl '\n'
#define vvi vector<vi>
#define mat(n, m) (n, vector<int>(m, 0))
#define mem(x) memset(x, 0, sizeof x)
#define int ll

bool pair_sort(const pair<ll, ll> &a, const pair<ll, ll> &bb)
{
    if (a.first == bb.first)
    {
        return a.second < bb.second;
    }
    return (a.first > bb.first);
}

int dx[] = {0, 1, -1, 0, 0};
int dy[] = {0, 0, 0, 1, -1};

const int N = 200020;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;

const int inf = 1e18;

void solve()
{
    int n, m;
    cin >> n >> m;
    vi a(n + 1), b(n + 1);
    multiset<int> sa, sb;
    fi(1, n)
    {
        cin >> a[i];
        sa.insert(a[i]);
    }
    fi(1, m)
    {
        cin >> b[i];
        sb.insert(b[i]);
    }

    fi(1, m)
    {
        if (sa.count(b[i]))
        {
            sa.erase(sa.find(b[i]));
            sb.erase(sb.find(b[i]));
        }
    }

    while (sz(sa))
    {
        int first = *sa.begin();
        sa.erase(sa.find(first));
        int second = *sa.begin();

        if (sb.count(first))
        {
            sb.erase(sb.find(first));
        }
        else if (sb.count(second))
        {
            sa.insert(first);
            sa.erase(sa.find(second));
        }
        else if (sz(sa) and abs(second - first) <= 1)
        {
            sa.erase(sa.find(second));
            sa.insert(first + second);
        }
        else
        {
            return;
        }
    }
    // deb(sa, sb)
    if(sb.empty())
    cout << "YES" << endl;
    else
    cout << "NO" << endl;
}
bool tests = 1;
int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t = 1;
    if (tests)
        cin >> t;
    fi(1, t)
        solve();
    return 0;
}

Submission (verdict: Wrong answer on test 3):

#include <bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#include "debug.h"
#else
#define deb(...)
#define debArr(...)
#endif
#define ll long long
#define ld long double
#define ull unsigned long long
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define allr(x) rbegin(x), rend(x)
#define alln(x) (begin(x) + 1), (end(x))
#define allrn(x) (rbegin(x)), (rbegin(x) + (sz(x) - 1))
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define FORs(i, a, b) for (int i = a; i <= b; ++i)
#define fi(a, n) for (int i = a; i <= n; ++i)
#define fj(a, n) for (int j = a; j <= n; ++j)
#define fk(a, n) for (int k = a; k <= n; ++k)
#define fl(a, n) for (int l = a; l <= n; ++l)
#define fiz(a, n) for (int i = a; i < n; ++i)
#define trv(x, a) for (auto &x : a)
#define endl '\n'
#define vvi vector<vi>
#define mat(n, m) (n, vector<int>(m, 0))
#define mem(x) memset(x, 0, sizeof x)
#define int ll

bool pair_sort(const pair<ll, ll> &a, const pair<ll, ll> &bb)
{
    if (a.first == bb.first)
    {
        return a.second < bb.second;
    }
    return (a.first > bb.first);
}

int dx[] = {0, 1, -1, 0, 0};
int dy[] = {0, 0, 0, 1, -1};

const int N = 200020;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;

const int inf = 1e18;

void solve()
{
    int n, m;
    cin >> n >> m;
    vi a(n + 1), b(n + 1);
    multiset<int> sa, sb;
    fi(1, n)
    {
        cin >> a[i];
        sa.insert(a[i]);
    }
    fi(1, m)
    {
        cin >> b[i];
        sb.insert(b[i]);
    }

    fi(1, m)
    {
        if (sa.count(b[i]))
        {
            sa.erase(sa.find(b[i]));
            sb.erase(sb.find(b[i]));
        }
    }

    while (sz(sa))
    {
        int first = *sa.begin();
        sa.erase(sa.find(first));
        int second = *sa.begin();

        if (sb.count(first))
        {
            sb.erase(sb.find(first));
        }
        else if (sb.count(second))
        {
            sa.insert(first);
            sa.erase(sa.find(second));
            sb.erase(sb.find(second));
        }
        else if (sz(sa) and abs(second - first) <= 1)
        {
            sa.erase(sa.find(second));
            sa.insert(first + second);
        }
        else
        {
            cout << "NO" << endl;
            return;
            break;
        }
    }
    deb(sa, sb)
    if (sb.empty())
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
bool tests = 1;
int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t = 1;
    if (tests)
        cin >> t;
    fi(1, t)
        solve();
    return 0;
}