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.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";

    }

}

Submission (verdict: Accepted):
#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;

        cin >> n >> m;

        multiset<ll> sta, stb;

        ll sum = 0;

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

            cin >> a;

            sum += a;

            sta.insert(a);

        }

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

            cin >> b;

            sum -= b;

            stb.insert(b);

        }



        bool ok = (sum == 0);



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

            ll ca = *sta.rbegin();

            ll cb = *stb.rbegin();

            if(ca == cb) {

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

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

            } else if(ca < cb) {



                ll req1 = cb / 2;

                ll req2 = cb - req1;

                if(sta.find(req1) != sta.end()) {

                    sta.erase(sta.find(req1));

                } else {

                    stb.insert(req1);

                }



                if(sta.find(req2) != sta.end()) {

                    sta.erase(sta.find(req2));

                } else {

                    stb.insert(req2);

                }

                

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

                

                

            } else {

                ok = false;

            }

        }

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

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

    }

}