Problem: 2061D - Kevin and Numbers
Language: C++17 (GCC 7-32)

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

// JAY SHREE KRISHNA
// AUTHOR:- Solanki Nirmal Bhikhabhai

// ------------------------------------------------------------------------------------------------------------
#define hello ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ll long long
#define ld long double
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define pb push_back
#define pp pop_back
#define endl "\n"
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
// ------------------------------------------------------------------------------------------------------------

vector<ll> llToBin(ll n){
    vector<ll> ans;
    while(n!=0){
        ans.pb(n%2);
        n/=2;
    }
    reverse(all(ans));
    return ans;
}

vector<ll> isprime(1e6+1,1);
void sieve(int n){
    isprime[1]=0;
    for(ll i=2;i*i<1000000;i++){
        if(isprime[i]!=0){
            for(ll j=i*i;j<1000000;j+=i) isprime[j]=0;
        }
    }
}

void printvec(vector<ll> temp){
    for(ll i=0;i<temp.size();i++) cout<<temp[i]<<" ";
    cout<<endl;
}

void printmap(map<ll,ll> temp){
    for(auto it=temp.begin();it!=temp.end();it++) cout<<it->fi<<" "<<it->se<<endl;
}

ll ncr(ll n,ll r){
    ld sum=1;
    for(ll i=0;i<=r;i++) sum=sum*(n-r+i)/i;
    return (ll)sum;
}


// ------------------------------------------------------------------------------------------------------------

void solve(){
    ll n,m;		cin>>n>>m;
    vector<ll> a(n),b(m);
    for(ll i=0;i<n;i++) cin>>a[i];
    for(ll i=0;i<m;i++) cin>>b[i];

    priority_queue<ll,vector<ll>,greater<ll>>pqa (a.begin(),a.end());
    priority_queue<ll,vector<ll>,greater<ll>>pqb (b.begin(),b.end());
    bool flag=true;
    ll b1=pqb.top();
    while(!pqa.empty())
    {
        ll a1=pqa.top();
        if(a1>b1) break;
        if(a1==b1) break;
        pqa.pop();
        if(pqa.empty())
        {
            flag=false;
            break;
        }
        ll a2=pqa.top();
        pqa.pop();
        if(a2-a1>1) 
        {
            flag=false;
            break;
        }
        if(a1+a2>=b1)
        {
            pqa.push(a1);
            pqa.push(a2);
            break;
        }
        else{
            pqa.push(a1+a2);
        }
    }

    if(!flag) no;
    else
    {
        map<ll,ll>mp;
        while(!pqa.empty())
        {
            mp[pqa.top()]++;
            pqa.pop();
        }
        // for(auto it:mp)
        // {
        //     cout<<it.first<<" "<<it.second<<endl;
        // }
        while(!pqb.empty() && !mp.empty())
        {
            ll val=pqb.top();
            b1=val;
            pqb.pop();
            if(mp.find(val)!=mp.end())
            {
                mp[val]--;
                if(mp[val]==0)
                {
                    mp.erase(val);
                }
                continue;
            }
            //cout<<val<<endl;
            auto it=mp.begin();
            ll a1=it->first;
           // cout<<val<<" "<<a1<<endl;
            mp[a1]--;
            if(mp[a1]==0)
            {
                mp.erase(a1);
            }
            if(a1>val)
            {
             flag=false;
             break;   
            }
            if(a1==val) continue;

            ll a2=val-a1;
            if(a2-a1>1)
            {
                flag=false;
                break;
            }
            // cout<<a2<<endl;
            // cout<<mp[a2]<<endl;
            if(mp[a2]>=1)
            {
                mp[a2]--;
                if(mp[a2]==0)
                {
                    mp.erase(a2);
                }
            }
            else{
                flag=false;
                break;
            }
        }
        // for(auto it:mp)
        // {
        //     cout<<it.first<<" "<<it.second<<endl;
        // }
        // cout<<pqb.size()<<" "<<mp.size()<<" "<<flag<<endl;
        if(!pqb.empty() || !mp.empty() || !flag) no;
        else yes;
    }
}

int32_t main(){
    hello;
    int t;			cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

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

// JAY SHREE KRISHNA
// AUTHOR:- Solanki Nirmal Bhikhabhai

// ------------------------------------------------------------------------------------------------------------
#define hello ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ll long long
#define ld long double
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define pb push_back
#define pp pop_back
#define endl "\n"
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
// ------------------------------------------------------------------------------------------------------------

vector<ll> llToBin(ll n){
    vector<ll> ans;
    while(n!=0){
        ans.pb(n%2);
        n/=2;
    }
    reverse(all(ans));
    return ans;
}

vector<ll> isprime(1e6+1,1);
void sieve(int n){
    isprime[1]=0;
    for(ll i=2;i*i<1000000;i++){
        if(isprime[i]!=0){
            for(ll j=i*i;j<1000000;j+=i) isprime[j]=0;
        }
    }
}

void printvec(vector<ll> temp){
    for(ll i=0;i<temp.size();i++) cout<<temp[i]<<" ";
    cout<<endl;
}

void printmap(map<ll,ll> temp){
    for(auto it=temp.begin();it!=temp.end();it++) cout<<it->fi<<" "<<it->se<<endl;
}

ll ncr(ll n,ll r){
    ld sum=1;
    for(ll i=0;i<=r;i++) sum=sum*(n-r+i)/i;
    return (ll)sum;
}


// ------------------------------------------------------------------------------------------------------------
bool f(ll val, map<ll,ll>&mp)
{
    //cout<<val<<endl;
    if(mp[val]>0) 
    {
        mp[val]--;
        return true;
    }
    if(val==1) return false;
    ll v1=val/2,v2=val/2;
    if(val%2!=0) v2++;
    if(!f(v1,mp)) return false;
    if(!f(v2,mp)) return false;
    return true;
}
void solve(){
    ll n,m;		cin>>n>>m;
    vector<ll> a(n),b(m);
    for(ll i=0;i<n;i++) cin>>a[i];
    for(ll i=0;i<m;i++) cin>>b[i];

    map<ll,ll>mp;
    for(auto it:a) mp[it]++;
    bool flag=true;
    for(auto it:b)
    {
        if(!f(it,mp))
        {
            flag=false;
            break;
        }
    }
    for(auto it:mp) 
    {
        if(it.second>0)
        {
            flag=false;
            break;
        }
    }
    if(flag) yes;
    else no;
}

int32_t main(){
    hello;
    int t;			cin>>t;
    while(t--){
        solve();
    }
    return 0;
}