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

Code 1:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll N=1e4+5;

int main(){
    ll T;
    cin>>T;
    while(T--){
        ll n;
        cin>>n;
        ll m;
        cin>>m;
        ll a[n],b[m];
        map<ll,ll> ma,mb;
        queue<ll> q;
        for(ll i=0;i<n;i++){
            cin>>a[i];
            ma[a[i]]=0;
            mb[a[i]]=0;
        }
        for(ll i=0;i<m;i++){
            cin>>b[i];
            ma[b[i]]=0;
        }
        sort(a,a+n);
        sort(b,b+m);
        for(ll i=0;i<m;i++){
            ma[b[i]]++;
        }
        ll count=0;
        ll mini=1e12;
        for(ll i=0;i<n;i++){
            if(ma[a[i]]>0) ma[a[i]]--;
            else{
                mb[a[i]]++;
                count++;
                mini=min(mini,a[i]);
            }
        }
        for(auto z:ma){
            if(z.second>0){
                for(ll i=0;i<z.second;i++) q.push(z.first);
            }
        }
        ll mini1=1e12;
        ll flag=0;
        while(q.empty()==0){
            ll x=q.size();
            if(x>count){
                flag=1;
                break;
            }
            for(ll i=0;i<x;i++){
                ll pp=q.front();
                q.pop();
                ll c=pp/2;
                ll d=pp-c;
                if(mb[c]>0){
                    mb[c]--;
                    count--;
                }
                else{
                    q.push(c);
                    mini1=min(mini1,c);
                }
                if(mb[d]>0){
                    mb[d]--;
                    count--;
                }
                else{
                    q.push(d);
                    mini1=min(mini1,d);
                }
            }
            if(mini1<mini){
                flag=1;
                break;
            }
        }
        if(flag==1 || count>0) cout<<"No"<<endl;
        else cout<<"Yes"<<endl;
    }
    return 0;
}

Code 2:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll N=1e4+5;

int main(){
    ll T;
    cin>>T;
    ll c=0;
    while(T--){
        ll n;
        cin>>n;
        ll m;
        cin>>m;
        ll a[n],b[m];
        map<ll,ll> ma;
        for(ll i=0;i<n;i++){
            cin>>a[i];
            ma[a[i]]=0;
        }
        for(ll i=0;i<m;i++){
            cin>>b[i];
            ma[b[i]]=0;
        }
        sort(a,a+n);
        sort(b,b+m);
        for(ll i=0;i<m;i++){
            ma[b[i]]++;
        }
        priority_queue<ll,vector<ll>,greater<ll>> pq;
        ll flag=0;
        for(ll i=0;i<n;i++){
            if(ma[a[i]]>0) ma[a[i]]--;
            else pq.push(a[i]);
        }
        ll sz=pq.size();
        while(sz>1){
            ll x=pq.top();
            pq.pop();
            sz--;
            if(ma[x]>0) ma[x]--;
            else{
                ll y=pq.top();
                pq.pop();
                if(abs(x-y)>1){
                    flag=1;
                    break;
                }
                pq.push(x+y);
            }
        }
        if(sz>0){
        ll pp=pq.top();
        if(ma[pp]>0){
            ma[pp]--;
            pq.pop();
            sz--;
        }
        }
        for(auto z:ma){
            if(z.second>0) flag=1;
        }
        if(sz>0) flag=1;
        if(flag==1) cout<<"NO"<<endl;
        else cout<<"YES"<<endl;
    }
    return 0;
}

Answer: 1