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> a(n), b(m);



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

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



    sort(all(a));



    int i = 0;



    map<ll,ll> mp;



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





    auto No = [&](){

        cout << "No\n";

    };



    while(i < n - 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: 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;

}