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

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

using namespace std;

typedef long long ll;

#define dbg(x) cout << #x << " = " << x << "\n"

#define pb push_back

#define x first

#define y second

#define INF 1e18

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

#define set_bits(x) __builtin_popcountll(x)



ll gcd(ll a,ll b) { if (b==0) return a; return gcd(b, a%b); }

ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }









void solve(){

    ll n,m; cin >> n >> m;

    vector<ll> v(n), b(m);



    for(auto &it: v) cin >> it;

    for(auto &it: b) cin >> it;



    sort(all(v));



    vector<int> a;



    int i = 0;



    map<ll,ll> mp;



    for(auto it: b) mp[it]++;



    for(auto it: v){

        if(mp.count(it)){

            mp[it]--;

            if(mp[it] == 0) mp.erase(it);

        }

        else{

            a.push_back(it);

        }

    }





    auto No = [&](){

        cout << "No\n";

    };



    if(a.size() == 0){

        cout << "Yes\n";

        return; 

    }



    while(i < a.size() - 1){

        if(mp.count(a[i])){

            mp[a[i]]--;

            if(mp[a[i]] == 0){

                mp.erase(a[i]);

            }

            i++;

        }

        else{

            if(a[i + 1] - a[i] <= 1){

                a[i + 1] += a[i];

                i++;

            }

            else{

                No();

                return;

            }

        }

    }



    if(mp.count(a[i]) and mp[a[i]] == 1 and mp.size() == 1){

        cout << "Yes\n";

        return;

    }



    No();



}





int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);



    int tc;

    tc=1;

    cin>>tc;



    while(tc--){

        solve();

    }

    return 0;

}

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

using namespace std;

typedef long long ll;

#define dbg(x) cout << #x << " = " << x << "\n"

#define pb push_back

#define x first

#define y second

#define INF 1e18

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

#define set_bits(x) __builtin_popcountll(x)



ll gcd(ll a,ll b) { if (b==0) return a; return gcd(b, a%b); }

ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }









void solve(){

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

    

    priority_queue<ll> a,b;



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

        ll num; cin >> num;

        a.push(num);

    }



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

        ll num; cin >> num;

        b.push(num);

    }

    int sz = n - m;



    auto No = [&](){

        cout << "No\n";

    };



    while(!a.empty() and !b.empty() and sz >= 0){

        // cout << a.top() << " " << b.top() << " \n";

        if(a.top() == b.top()){

            a.pop();

            b.pop();

            continue;

        }



        else if(b.top() > a.top()){

            ll temp = b.top();

            ll num1 = temp/2;

            ll num2 = temp - num1;



            b.pop();

            b.push(num1);

            b.push(num2);

            sz--;



            

        }

        else{

            No();

            return;

        }

    }



    if(a.empty() and b.empty() and sz == 0){

        cout << "Yes\n";

        return;

    }



    No();



    // while(!b.empty()){

    //     cout << b.top() << " ";

    //     b.pop();

    // }



    // cout << "\n";

    



}





int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);



    int tc;

    tc=1;

    cin>>tc;



    while(tc--){

        solve();

    }

    return 0;

}