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

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>

using namespace std;



/// #DEFINEs

#define int long long

#define f first

#define s second

#define lb lower_bound

#define up upper_bound

#define pb push_back

#define pf push_front

#define sz size()

#define fori(n) for (int i = 0; i < n; i++)

#define forj(n) for (int j = 0; j < n; j++)



#define all(a) a.begin(), a.end()

#define SORT(v) sort(all(v))

#define REV(v) reverse(all(v))

#define lg2(x) __lg(x)

#define sp " "

#define fl "\n"

#define YN(x) cout << ((x) ? ("YES") : ("NO")) << fl;



/// TYPEDEFs

typedef long long ll;

typedef long double ld;

typedef pair<int, int> pii;

typedef vector<int> vi;

typedef vector<pii> vii;

typedef vector<bool> vb;



/// CONSTANTS

const int oo = 1e9 + 5;

const ll OO = (ll)1e18 + 5;

const ld pi = acos(-1.0);



/// CONSTRAINTS

const int maxn = 2e5 + 5;

const int mod = 998244353;

const ld eps = 1e-9;



int qpow(int a, int b)

{

    int res = 1;

    while (b)

    {

        if (b & 1)

            res = (res * a) % mod;

        a = (a * a) % mod;

        b >>= 1;

    }

    return res % mod;

}



/// +--------------------------------------+ CODE +--------------------------------------+



void solve()

{

    int n, m;

    cin >> n >> m;

    priority_queue<int> pq;

    fori(n)

    {

        int x;

        cin >> x;

        pq.push(-x);

    }

    vi b(m);

    fori(m) cin >> b[i];

    SORT(b);

    int idx = 0;

    bool flag = true;

    while (idx < m && !pq.empty())

    {

        int u = abs(pq.top());

        pq.pop();

        if (b[idx] == u)

        {

            idx++;

            continue;

        }

        if (pq.empty())

        {

            flag = false;

            break;

        }

        int v = abs(pq.top());

        pq.pop();

        if (v > b[idx])

        {

            flag = false;

            break;

        }

        if (abs(u - v) <= 1)

            pq.push(-(u + v));

        else

        {

            flag = false;

            break;

        }

    }

    if (!pq.empty())

        flag = false;

    YN(flag)

}



signed main()

{

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    //    cout.precision(12);

    //    cout<<fixed;

    int testcases = 1;

    cin >> testcases;

    while (testcases--)

        solve();

}

Submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>

using namespace std;



/// #DEFINEs

#define int long long

#define f first

#define s second

#define lb lower_bound

#define up upper_bound

#define pb push_back

#define pf push_front

#define sz size()

#define fori(n) for (int i = 0; i < n; i++)

#define forj(n) for (int j = 0; j < n; j++)



#define all(a) a.begin(), a.end()

#define SORT(v) sort(all(v))

#define REV(v) reverse(all(v))

#define lg2(x) __lg(x)

#define sp " "

#define fl "\n"

#define YN(x) cout << ((x) ? ("YES") : ("NO")) << fl;



/// TYPEDEFs

typedef long long ll;

typedef long double ld;

typedef pair<int, int> pii;

typedef vector<int> vi;

typedef vector<pii> vii;

typedef vector<bool> vb;



/// CONSTANTS

const int oo = 1e9 + 5;

const ll OO = (ll)1e18 + 5;

const ld pi = acos(-1.0);



/// CONSTRAINTS

const int maxn = 2e5 + 5;

const int mod = 998244353;

const ld eps = 1e-9;



int qpow(int a, int b)

{

    int res = 1;

    while (b)

    {

        if (b & 1)

            res = (res * a) % mod;

        a = (a * a) % mod;

        b >>= 1;

    }

    return res % mod;

}



/// +--------------------------------------+ CODE +--------------------------------------+



void solve()

{

    int n, m;

    cin >> n >> m;

    priority_queue<int> pq;

    fori(n)

    {

        int x;

        cin >> x;

        pq.push(-x);

    }

    vi b(m);

    fori(m) cin >> b[i];

    SORT(b);

    int idx = 0;

    bool flag = true;

    while (idx < m && !pq.empty())

    {

        int u = abs(pq.top());

        pq.pop();

        if (b[idx] == u)

        {

            idx++;

            continue;

        }

        if (pq.empty())

        {

            flag = false;

            break;

        }

        int v = abs(pq.top());

        pq.pop();

        if (v > b[idx])

        {

            flag = false;

            break;

        }

        if (abs(u - v) <= 1)

            pq.push(-(u + v));

        else

        {

            flag = false;

            break;

        }

    }

    if (idx != m || !pq.empty())

        flag = false;

    YN(flag)

}



signed main()

{

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    //    cout.precision(12);

    //    cout<<fixed;

    int testcases = 1;

    cin >> testcases;

    while (testcases--)

        solve();

}