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

Code 1:
#include <bits/stdc++.h>
using namespace std;
#define int long long
int mod = 998244353;
#define fr(i, n) for (int i = 0; i < n; i++)
#define fr1(i, n) for (int i = 1; i < n; i++)
#define vi vector<int>
int hcf(int a, int g)
{
    if (g == 0)
        return a;
    else
        return hcf(g, a % g);
}
int lcm(int a, int g) { return (a * g) / hcf(a, g); }
int modInverse(int a, int mod) {
    int res = 1, p = mod - 2;
    while (p > 0) {
        if (p & 1) res = (res * a) % mod;
        a = (a * a) % mod;
        p >>= 1;
    }
    return res;
}
int N=1e6;
vi f(N+1,1),inv_f(N+1,1);
void precompute() {
    for (int i = 2; i <= N; ++i) {
        f[i] = (f[i - 1] * i) % mod;
    }
    inv_f[N] = modInverse(f[N], mod);
    for (int i = N - 1; i >= 1; --i) {
        inv_f[i] = (inv_f[i + 1] * (i + 1)) % mod;
    }
}
int ncr(int n, int r) {
    if (r > n) return 0;
    return (f[n] * inv_f[r] % mod) * inv_f[n - r] % mod;
}

void solve()
{
    int n,m;
    cin>>n>>m;
    vi a(n);
    vi b(m);
    fr(i,n) cin>>a[i];
    fr(i,m) cin>>b[i];
    map<int,int> ma,mb;
    fr(i,m){
        mb[b[i]]++;
    }
    fr(i,n){
        ma[a[i]]++;
    }
    sort(a.begin(),a.end());
    fr(i,m){
        if(ma[b[i]]>0 && mb[b[i]]>0){
            int y=min(ma[b[i]],mb[b[i]]);
            ma[b[i]]-=y;
            mb[b[i]]-=y;
        }
    }
    int f=0,x=0;

    for(int i=0;i<n;i++){
        if(ma[a[i]]==0) continue;
        else{
            if(f==0){
                x=a[i];
                ma[x]--;
                f=1;
            }
            else if(a[i]-x<=1){
                if(mb[x+a[i]]>0){ 
                mb[x+a[i]]--;
                f=0;
                x=0;
                }
                else x=x+a[i];
                ma[a[i]]--;
            }
        
        }
    }
    if(x!=0){
        cout<<"NO"<<endl;
        return;
    }
    fr(i,m){
        if(mb[b[i]]==0 && ma[b[i]]==0) continue;
        else{
            cout<<"NO"<<endl;
            return;
        }
    }
    cout<<"YES"<<endl;
   

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


Code 2:
#include <bits/stdc++.h>
using namespace std;
#define int long long
int mod = 998244353;
#define fr(i, n) for (int i = 0; i < n; i++)
#define fr1(i, n) for (int i = 1; i < n; i++)
#define vi vector<int>
int hcf(int a, int g)
{
    if (g == 0)
        return a;
    else
        return hcf(g, a % g);
}
int lcm(int a, int g) { return (a * g) / hcf(a, g); }
int modInverse(int a, int mod) {
    int res = 1, p = mod - 2;
    while (p > 0) {
        if (p & 1) res = (res * a) % mod;
        a = (a * a) % mod;
        p >>= 1;
    }
    return res;
}
int N=1e6;
vi f(N+1,1),inv_f(N+1,1);
void precompute() {
    for (int i = 2; i <= N; ++i) {
        f[i] = (f[i - 1] * i) % mod;
    }
    inv_f[N] = modInverse(f[N], mod);
    for (int i = N - 1; i >= 1; --i) {
        inv_f[i] = (inv_f[i + 1] * (i + 1)) % mod;
    }
}
int ncr(int n, int r) {
    if (r > n) return 0;
    return (f[n] * inv_f[r] % mod) * inv_f[n - r] % mod;
}

void solve()
{
    int n,m;
    cin>>n>>m;
    priority_queue<int> a,b;
    fr(i,n){
        int x;
        cin>>x;
        a.push(x);
    }
    fr(i,m){
        int x;
        cin>>x;
        b.push(x);
    }
    while(!a.empty()){
        if(b.empty() || b.size()>a.size()){
            cout<<"no"<<endl;
            return;
        }
        int y=b.top();
        b.pop();
        if(a.top()>y){
             cout<<"no"<<endl;
            return;
        }
        if(a.top()==y){
            a.pop();
        }
        else{
            b.push(y/2);
            b.push((y+1)/2);
        }

    }
    if(!b.empty()){
         cout<<"no"<<endl;
            return;
    }
    cout<<"yes"<<endl;
   

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


Answer: 2