Problem: 2061D - Kevin and Numbers
Language: c++23 

Code 1:
#include <iostream>
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
const ll mod = 1e9 + 7;
const ll modd = 998244353;


void solve() {
    ll n, m;
    cin>>n>>m;
    map<ll, ll>m1, m2;
    for(ll i = 0; i<n; i++) {
        ll x;
        cin>>x;
        m1[x]++;
    }
    for(ll i = 0; i<m; i++) {
        ll x;
        cin>>x;
        m2[x]++;
    }

    set<ll>s1, s2;
    for(auto&i:m1) {
        if(m2.find(i.first)!=m2.end()){
            ll k = m2[i.first];
            if(k>i.second) {
                m2[i.first]-=i.second;
                s1.insert(i.first);
            }
            else {
                i.second-=k;
                s2.insert(i.first);
                if(i.second == 0) s1.insert(i.first);
            }
        }
    }
    for(auto&i:s1) {
        m1.erase(i);
    }
    for(auto&i:s2) {
        m2.erase(i);
    }
    vector<ll>a, b;
    for(auto&i:m1) {
        ll k = i.second;
       //  cout<<i.first<<" "<<k<<"\n";
        while(k--) {
            a.push_back(i.first);
           //  cout<<i.first<<" ";
        }
    }
  //  cout<<"\n";

    for(auto&i:m2) {
        ll k = i.second;
       // cout<<i.first<<" "<<k<<"\n";
        while(k--) {
            b.push_back(i.first);
           // <F5> cout<<i.first<<" ";
        }
    }
   //  cout<<"\n";
    n = a.size(), m = b.size();
    if(n<m) {
        cout<<"NO\n";
        return;
    }

    ll i = 0, j = 0;

    while(i<n && j<m) {
        if(a[i]==b[j]) {
            i++;
            j++;
        }
        else if(b[j]<a[i]) {
            cout<<"NO\n";
            return;
        }
        else {
            ll prev = -1, s = 0;
            while(i<n && (prev == -1 ||abs(a[i]-prev<=1)) ){
                s+=a[i];
                prev = s;
                i++;
                if(b[j]==s) {
                    j++;
                    break;
                }
                else if(s>b[j]) {
                    cout<<"NO\n";
                    return;
                }
            }
  
        }
    }
    if(i<n ||  j<m) {
        cout<<"NO\n";
        return;
    }
    cout<<"YES\n";


}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t = 1;
    cin >> t;
    
    while (t--) solve();

    return 0;
}


Code 2:
#include <iostream>
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
const ll mod = 1e9 + 7;
const ll modd = 998244353;


void solve() {
    ll n, m;
    cin>>n>>m;
    multiset<ll>s1, s2;
    for(ll i = 0; i<n; i++) {
        ll x;
        cin>>x;
        s1.insert(x);
    }
    for(ll i = 0; i<m; i++) {
        ll x;
        cin>>x;
        s2.insert(x);
    }
    for(auto&i:s2) {
        auto it = s1.find(i);
        if(it!=s1.end()) {
            s1.erase(it);
        }
        else {
            ll a = i>>1ll, b = i>>1ll;
            if(a+b!=i) b++;
            queue<ll>q;
            q.push(a);
            q.push(b);
            while(!q.empty()) {
                ll e = q.front();
                q.pop();
                auto it1 = s1.find(e);
                if(it1!=s1.end()) {
                    s1.erase(it1);
                }
                else {
                    if(q.size()>s1.size()) {
                        cout<<"NO\n";
                        return;
                    }
                    ll c = e>>1ll, d = e>>1ll;
                    if(c==0) {
                        cout<<"NO\n";
                        return;
                    }
                    if(c+d!=e) d++;
                    q.push(c);
                    q.push(d);
                }
            }
        }
    }
    if(!s1.empty()) {
        cout<<"NO\n";
        return;
    }
    cout<<"YES\n";

}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t = 1;
    cin >> t;
    
    while (t--) solve();

    return 0;
}


Answer: 2