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

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

using namespace std;



#define ll long long

#define db long double

#define vii vector<ll>

#define pll pair<ll, ll>

#define F first

#define S second





const ll N = (ll) 3e5 + 5;

const ll mod = (ll) 1e9 + 7;

const ll inf = (ll) 1e18;



int main() {

    ios_base::sync_with_stdio(0);

    cin.tie(0);



    int t = 1;

    cin >> t;

    while(t--) {

        ll a, b, c, i, j, k, m, n, o, x, y, z;

        bool ok = true;

        cin >> n >> m;

        multiset<ll> sta, stb;

        for(i = 0; i < n; i++) {

            cin >> a;

            sta.insert(a);

        }

        for(i = 0; i < m; i++) {

            cin >> b;

            stb.insert(b);

        }



        while(ok && sta.size() && stb.size()) {

            ll ca = *sta.begin();

            ll cb = *stb.begin();

            if(ca == cb) {

                sta.erase(sta.begin());

                stb.erase(stb.begin());

            } else if(ca < cb) {

                sta.erase(sta.begin());

                if(sta.size()) {

                    ll na = *sta.begin();

                    if(na <= ca + 1) {

                        sta.erase(sta.begin());

                        sta.insert(ca + na);

                    } else {

                        ok = false;

                    }

                } else {

                    ok = false;

                }

            } else {

                ok = false;

            }

        }

        ok &= (sta.size() == 0 && stb.size() == 0);

        cout << (ok ? "YES" : "NO") << "\n";

    }

}

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

using namespace std;



#define ll long long

#define db long double

#define vii vector<ll>

#define pll pair<ll, ll>

#define F first

#define S second





const ll N = (ll) 3e5 + 5;

const ll mod = (ll) 1e9 + 7;

const ll inf = (ll) 1e18;



int main() {

    ios_base::sync_with_stdio(0);

    cin.tie(0);



    int t = 1;

    cin >> t;

    while(t--) {

        ll a, b, c, i, j, k, m, n, o, x, y, z;

        bool ok = true;

        cin >> n >> m;

        multiset<ll> sta, stb;

        for(i = 0; i < n; i++) {

            cin >> a;

            sta.insert(a);

        }

        for(i = 0; i < m; i++) {

            cin >> b;

            stb.insert(b);

        }



        while(ok && sta.size() && stb.size()) {

            ll ca = *sta.begin();

            ll cb = *stb.begin();

            if(ca == cb) {

                sta.erase(sta.find(ca));

                stb.erase(stb.find(cb));

            } else if(ca < cb) {

                sta.erase(sta.find(ca));

                if(sta.size()) {

                    ll na = *sta.begin();

                    if(na <= ca + 1) {

                        sta.erase(sta.find(na));

                        sta.insert(ca + na);

                    } else {

                        ok = false;

                    }

                } else {

                    ok = false;

                }

            } else {

                ok = false;

            }

        }

        ok &= (sta.size() == 0 && stb.size() == 0);

        cout << (ok ? "YES" : "NO") << "\n";

    }

}