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

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

using namespace std;



#ifdef LOCAL

#include "debug.h"

#else

#define debug()

#define db(x)

#endif



#define INF 1e18

#define endl '\n'

#define ff first

#define ss second

#define pb push_back

#define int long long

#define mod 1000000007

#define pii  2 * acos(0.0)

#define double long double

#define sz(x) ((int)(x).size())

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

#define rall(a) (a).rbegin(),(a).rend()

#define deci(x) cout << fixed << setprecision(x);

#define rmv(x,a) x.erase(remove(x.begin(),x.end(),a),x.end())

#define unq(x) {x.erase(unique(x.begin(),x.end()),x.end());}

#define shera() ios_base::sync_with_stdio(1);cin.tie(NULL);cout.tie(NULL)

template<typename T1>istream &operator>>(istream &cin, vector<T1>&a) {for (auto&x : a)cin >> x; return cin;}





bool solve(multiset<int>& a, int n) {

    if (a.empty()) return false;

    if (a.count(n)) {

        a.erase(a.find(n));

        return true;

    } else {

        if (n == 1)return false;

    }



    int left = n / 2;

    int right = n - left;



    if (solve(a, left) && solve(a, right)) return true;



    return false;

}





int32_t main() {

    shera();

    debug();



    int tc; tc = 1;

    cin >> tc;

    for (int ii = 1; ii <= tc; ii++) {



        int n, m ; cin >> n >> m;

        multiset<int>a, b;

        vector<int>v(n);

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

            int x; cin >> x;

            v[i] = x;

            a.insert(x);

        }

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

            int x; cin >> x;

            b.insert(x);

        }





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

            if (b.find(v[i]) != b.end()) {

                a.erase(a.find(v[i]));

                b.erase(b.find(v[i]));

            }

        }



        if (a.empty()) {

            if (b.empty()) {

                cout << "Yes" << endl;

            }

            else {

                cout << "No" << endl;

            }

            continue;

        }

        if (b.empty()) {

            cout << "No" << endl;

            continue;

        }



        bool ok = 1;

        db(a)

        db(b)





        for (auto u : b ) {

            ok &= solve(a, u);

            db(ok)

        }



        if (ok) {

            cout << "Yes" << endl;

        } else {

            cout << "No" << endl;

        }





    }



    return 0;

}

Submission (verdict: Accepted):
#include<bits/stdc++.h>

using namespace std;



#ifdef LOCAL

#include "debug.h"

#else

#define debug()

#define db(x)

#endif



#define INF 1e18

#define endl '\n'

#define ff first

#define ss second

#define pb push_back

#define int long long

#define mod 1000000007

#define pii  2 * acos(0.0)

#define double long double

#define sz(x) ((int)(x).size())

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

#define rall(a) (a).rbegin(),(a).rend()

#define deci(x) cout << fixed << setprecision(x);

#define rmv(x,a) x.erase(remove(x.begin(),x.end(),a),x.end())

#define unq(x) {x.erase(unique(x.begin(),x.end()),x.end());}

#define shera() ios_base::sync_with_stdio(1);cin.tie(NULL);cout.tie(NULL)

template<typename T1>istream &operator>>(istream &cin, vector<T1>&a) {for (auto&x : a)cin >> x; return cin;}





bool solve(multiset<int>& a, int n) {

    if (a.empty()) return false;

    if (a.count(n)) {

        a.erase(a.find(n));

        return true;

    } else {

        if (n == 1)return false;

    }



    int left = n / 2;

    int right = n - left;



    if (solve(a, left) && solve(a, right)) return true;



    return false;

}





int32_t main() {

    shera();

    debug();



    int tc; tc = 1;

    cin >> tc;

    for (int ii = 1; ii <= tc; ii++) {



        int n, m ; cin >> n >> m;

        multiset<int>a, b;

        vector<int>v(n);

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

            int x; cin >> x;

            v[i] = x;

            a.insert(x);

        }

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

            int x; cin >> x;

            b.insert(x);

        }





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

            if (b.find(v[i]) != b.end()) {

                a.erase(a.find(v[i]));

                b.erase(b.find(v[i]));

            }

        }



        if (a.empty()) {

            if (b.empty()) {

                cout << "Yes" << endl;

            }

            else {

                cout << "No" << endl;

            }

            continue;

        }

        if (b.empty()) {

            cout << "No" << endl;

            continue;

        }



        bool ok = 1;

        db(a)

        db(b)





        for (auto u : b ) {

            ok &= solve(a, u);

            db(ok)

        }



        if (ok && a.empty()) {

            cout << "Yes" << endl;

        } else {

            cout << "No" << endl;

        }

























    }



    return 0;

}