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

Code 1:

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
template<typename T>
using ordered_set = tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>;
typedef unsigned long long int ull;
#define vi vector<int>
#define vpi vector<pair<int,int> >
#define mpi map<int,int>
#define  si set<int>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define reP(i,a,n) for(int i=a;i<=n;i++)
#define YES cout<<"YES\n";
#define NO cout<<"NO\n";
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define case(i,n) Case<<" "<<i<<": "<<n<<endl;
#define endl "\n"
#define w(t) int t;cin>>t;while(t--)
#define all(x) (x).begin(), (x).end()
#define sz(a) (int)(a).size()
#define MOD 1000000007


void solve(){


ll n,m;
cin>>n>>m;
set<ll>a,b;
map<ll,ll>mp1,mp2;
ll x;
rep(i,0,n)
{
	cin>>x;
	mp1[x]++;
	a.insert(x);
}rep(i,0,m)
{
	cin>>x;
	mp2[x]++;
	b.insert(x);
}
while(true){
	if(a.empty() && b.empty()){
		YES
		return;
	}
	if(a.empty() || b.empty()){
		NO 
		return;
	}
	ll mxa= *a.rbegin();
	ll mxb= *b.rbegin();
	if(mxa>mxb){
		NO 
		return;
	}
	if(mp1[mxb]){
		ll mn = min(mp1[mxb],mp2[mxb]);
		mp1[mxb]-=mn;
		mp2[mxb]-=mn;
		if(mp1[mxb]==0){
			a.erase(mxb);
		}if(mp2[mxb]==0){
			b.erase(mxb);
		}
	}
	else
	{
		ll l = mxb/2;
		ll r = (mxb+1)/2;
		mp2[l]+=mp2[mxb];
		mp2[r]+=mp2[mxb];
		mp2[mxb]=0;
		b.insert(l);
		b.insert(r);
		b.erase(mxb);
	}



}


}
int main()
{
     #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
int t;
clock_t z =  clock();
t=1;
cin>>t;
while(t--)
{
solve();
}

cerr<<"Run Time : "<<((double)(clock()-z)/CLOCKS_PER_SEC);
}




Code 2:

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
template<typename T>
using ordered_set = tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>;
typedef unsigned long long int ull;
#define vi vector<int>
#define vpi vector<pair<int,int> >
#define mpi map<int,int>
#define  si set<int>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define reP(i,a,n) for(int i=a;i<=n;i++)
#define YES cout<<"YES\n";
#define NO cout<<"NO\n";
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define case(i,n) Case<<" "<<i<<": "<<n<<endl;
#define endl "\n"
#define w(t) int t;cin>>t;while(t--)
#define all(x) (x).begin(), (x).end()
#define sz(a) (int)(a).size()
#define MOD 1000000007


void solve(){


ll n,m;
cin>>n>>m;
vector<ll>ar(n);
vector<ll>br(m);
map<ll,ll>mp1,mp2;
rep(i,0,n)
{
	cin>>ar[i];
	mp1[ar[i]]++;
}
ll sum=0;

rep(i,0,m)
{
	cin>>br[i];
	if(mp1[br[i]]>0){
		mp1[br[i]]--;
		//cout<<"hi "<<br[i]<<" "<<mp1[br[i]]<<endl;
	}
	else
	{
		mp2[br[i]]++;
	}
	sum+=br[i];
	// cout<<sum<<endl;
}

if(sum<n){
	//cout<<"hi"<<endl;
	NO 
	return;
}
vector<ll>a,b;
for(auto it:mp1){
	rep(i,0,it.se){
		a.pb(it.fi);
	}
}
for(auto it:mp2){
	rep(i,0,it.se){
		b.pb(it.fi);
	}
}
int cnt = sz(a)-sz(b);
ll l;
if(sz(a)>0)
l=a[0];
for(int i=1;i<sz(a);i++){
		if(abs(l-a[i])<=1){
				l+=a[i];

				if(mp2[l]>0){

					mp2[l]--;

					if(i+1<sz(a)){
						l=a[i+1];
						i++;
					}
				}
		}
		else
		{
			NO 
			return;
		}
}

for(auto it:mp2){
	if(it.se!=0){
		NO 
		return;
	}
}
YES

}
int main()
{
     #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
// ios_base::sync_with_stdio(false);
//     cin.tie(NULL);
int t;
clock_t z =  clock();
t=1;
cin>>t;
while(t--)
{
solve();
}

cerr<<"Run Time : "<<((double)(clock()-z)/CLOCKS_PER_SEC);
}




Answer: 1