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

Code 1:
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<class T> using oset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
#define SMIT_FEFAR                  \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);                    \
  cout.tie(NULL)
#define MOD 1000000007
#define MOD2 998244353

#define pb push_back
#define ppb pop_back
#define vvi vector<vector<int>>
#define vvll vector<vector<ll>>
#define vvc vector<vector<char>>
#define vi vector<int>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define mp make_pair
#define PI 3.141592653589793238462
#define set_bits __builtin_popcountll
#define sz(x) ((ll)(x).size())
#define all(x) (x).begin(), (x).end()
#define vll vector<ll>
#define yes cout << "YES\n";
#define no cout << "NO\n";
#define minus cout<<-1<<"\n";
#define rep(l,r,i) for(ll i = l;i<r;i++)
#define repr(l,r,i) for(ll i = l;i>=r;i--)
#define print cout<<
#define nline "\n"
ll inf= 1e16;
ll expo(ll a,ll b){ll res=1;while(b>0){if(b&1){res=res*a;}b=b>>1;a*=a;}return res;}
ll expomod(ll a, ll b, ll mod){
  ll res=1;while(b>0){if(b&1){res=(res*a)%mod;}b=b>>1;a= (a*a)%mod;}return res;
}
struct triplet{
    ll x,y,gcd;
};
 
struct triplet extended_Euclid(ll a, ll b){
    if(b == 0){
        triplet ans;
        ans.gcd = a;
        ans.x = 1;
        ans.y = 0;
        return ans;
    }
    
    triplet ans2 = extended_Euclid(b, a%b);
    triplet finalAns;
    /*
    ax + by = gcd(a, b)
    gcd(a, b) = gcd(b, a%b)
    gcd(b, a%b) = bx1 + (a%b)y1
    a%b = a − (a/b) ∗ b 
    so...
    ax + by = bx1 + (a%b)y1
    ax + by = bx1 + (a − (a/b) ∗ b)y1
    ax + by = ay1 + b(x1 − (a/b) ∗ y1)
    
    so...
 
    x = y1
    y = x1 − (a/b) ∗ y1
    */
    finalAns.gcd = ans2.gcd;
    finalAns.x = ans2.y;
    finalAns.y = (ans2.x) - (a/b)*(ans2.y);
    return finalAns;
}
 
ll moduloInverse(ll num1, ll modulo){
triplet ans = extended_Euclid(num1,modulo);
//return ans.x; // for negative values allowed
return (ans.x + modulo)%modulo; // for only positive values
}
 
ll endNumber = 1000001;
vll smallestPrimeFactors(endNumber,0);
//O(N*log(log(n)))
void sieveMethodSmallesPrimeFactors(){
    rep(1,endNumber,i){
        smallestPrimeFactors[i] = i;
    }
    for(ll j = 2; j <= endNumber-1 ; j++){
        if(smallestPrimeFactors[j] == j){
            for(ll k = j*j;k < endNumber; k += j){
                if(smallestPrimeFactors[k] == k)
                smallestPrimeFactors[k] = j;
            }
        }
    }
}

class DSU{
public:
    long long n;
    vector<long long> size, par;
    vector<bool> vis;
 
    DSU(long long n){
        this -> n = n;
        size.resize(n);
        par.resize(n);
        vis.resize(n);
 
        for(long long i = 0; i < n; ++i){
            par[i] = i;
            size[i] = 1;
            vis[i] = 0;
        }
    }
 
    long long find_leader(long long u){
        if (u == par[u])
            return u;
        return par[u] = find_leader(par[u]);
    }
 
    void merge(long long u, long long v){
        vis[u] = 1;
        vis[v] = 1;
        u = find_leader(u); v = find_leader(v);
        if (u == v) return;

        if (size[u] < size[v]){
            swap(u, v);
        } 
        size[u] += size[v];
        par[v] = u;
    }
 
    long long count_components(){
        long long cnt = 0;
        for (long long i = 0; i < n; ++i){
            if (par[i] == i) ++cnt;
        }
 
        return cnt;
    }
};struct segNode
{
    long long sum;

    segNode()
    {
        sum = 0;
    }

    void merge(segNode &x, segNode &y, ll ind)
    {
        if(ind%2 == 1)
        sum = x.sum | y.sum;
        else
        sum = x.sum & y.sum;
    }

    void update(long long val)
    {
        sum = val;
    }
};

class segTree
{
    long long n;
    vector<segNode> tree;

public:
    segTree() {}

    segTree(long long n)
    {
        this->n = n;
        tree.resize(4 * n);
    }

    segTree(vector<long long> &v, long long n)
    {
        this->n = n;
        tree.resize(4 * n);
        fill(all(tree), segNode());

        build(1, 0, n - 1, v);
    }

    void build(long long node, long long l, long long r, vector<long long> &v)
    {
        if (l == r)
        {
            tree[node].update(v[l]);
            return;
        }

        long long mid = l + (r - l) / 2;
        build(node << 1, l, mid, v);
        build(node << 1 | 1, mid + 1, r, v);

        tree[node].merge(tree[node << 1], tree[node << 1 | 1],mid);
    }

    void update(long long pos, long long val)
    {
        update(1, 0, n - 1, pos, val);
    }

    void update(long long node, long long l, long long r, long long pos, long long val)
    {
        if (l == r)
        {
            tree[node].update(val);
            return;
        }

        long long mid = l + (r - l) / 2;
        if (pos <= mid)
        {
            update(node << 1, l, mid, pos, val);
        }
        else
        {
            update(node << 1 | 1, mid + 1, r, pos, val);
        }

        tree[node].merge(tree[node << 1], tree[node << 1 | 1], mid);
    }

    long long query(long long s, long long e)
    {
        segNode ans = query(1, 0, n - 1, s, e);

        return ans.sum;
    }

    segNode query(long long node, long long l, long long r, long long s, long long e)
    {
        if (l >= s && r <= e)
            return tree[node];

        if (l > e || r < s)
            return segNode();

        long long mid = l + (r - l) / 2;

        segNode ans, left, right;
        left = query(node << 1, l, mid, s, e);
        right = query(node << 1 | 1, mid + 1, r, s, e);
        ans.merge(left, right, mid);

        return ans;
    }
};

void solve()
{
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    vector<int> b(m);
    for (int i = 0; i < m; i++) {
      cin >> b[i];
    }
    sort(a.begin(), a.end());
    multiset<int> s;
    for (int i = 0; i < m; i++) {
      s.insert(b[i]);
    }
    int lft = n;
    while (lft > 0 && !s.empty() && int(s.size()) <= lft) {
      auto it = prev(s.end());
      int x = *it;
      s.erase(it);
      if (x == a[lft - 1]) {
        lft -= 1;
        continue;
      }
      if (x < a[lft - 1]) {
        break;
      }
      s.insert(x / 2);
      s.insert((x + 1) / 2);
    }
    if (lft == 0 && s.size() == 0) {
      cout << "Yes" << '\n';
    } else {
      cout << "No" << '\n';
    }
}

int main()
{
  // sieveMethodSmallesPrimeFactors();
  SMIT_FEFAR;
  bool test_cases = 1;
  ll t=1;
  if(test_cases)cin>>t;
  while (t--) solve();
  return 0;
}

Code 2:
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<class T> using oset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
#define SMIT_FEFAR                  \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);                    \
  cout.tie(NULL)
#define MOD 1000000007
#define MOD2 998244353

#define pb push_back
#define ppb pop_back
#define vvi vector<vector<int>>
#define vvll vector<vector<ll>>
#define vvc vector<vector<char>>
#define vi vector<int>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define mp make_pair
#define PI 3.141592653589793238462
#define set_bits __builtin_popcountll
#define sz(x) ((ll)(x).size())
#define all(x) (x).begin(), (x).end()
#define vll vector<ll>
#define yes cout << "YES\n";
#define no cout << "NO\n";
#define minus cout<<-1<<"\n";
#define rep(l,r,i) for(ll i = l;i<r;i++)
#define repr(l,r,i) for(ll i = l;i>=r;i--)
#define print cout<<
#define nline "\n"
ll inf= 1e16;
ll expo(ll a,ll b){ll res=1;while(b>0){if(b&1){res=res*a;}b=b>>1;a*=a;}return res;}
ll expomod(ll a, ll b, ll mod){
  ll res=1;while(b>0){if(b&1){res=(res*a)%mod;}b=b>>1;a= (a*a)%mod;}return res;
}
struct triplet{
    ll x,y,gcd;
};
 
struct triplet extended_Euclid(ll a, ll b){
    if(b == 0){
        triplet ans;
        ans.gcd = a;
        ans.x = 1;
        ans.y = 0;
        return ans;
    }
    
    triplet ans2 = extended_Euclid(b, a%b);
    triplet finalAns;
    /*
    ax + by = gcd(a, b)
    gcd(a, b) = gcd(b, a%b)
    gcd(b, a%b) = bx1 + (a%b)y1
    a%b = a − (a/b) ∗ b 
    so...
    ax + by = bx1 + (a%b)y1
    ax + by = bx1 + (a − (a/b) ∗ b)y1
    ax + by = ay1 + b(x1 − (a/b) ∗ y1)
    
    so...
 
    x = y1
    y = x1 − (a/b) ∗ y1
    */
    finalAns.gcd = ans2.gcd;
    finalAns.x = ans2.y;
    finalAns.y = (ans2.x) - (a/b)*(ans2.y);
    return finalAns;
}
 
ll moduloInverse(ll num1, ll modulo){
triplet ans = extended_Euclid(num1,modulo);
//return ans.x; // for negative values allowed
return (ans.x + modulo)%modulo; // for only positive values
}
 
ll endNumber = 1000001;
vll smallestPrimeFactors(endNumber,0);
//O(N*log(log(n)))
void sieveMethodSmallesPrimeFactors(){
    rep(1,endNumber,i){
        smallestPrimeFactors[i] = i;
    }
    for(ll j = 2; j <= endNumber-1 ; j++){
        if(smallestPrimeFactors[j] == j){
            for(ll k = j*j;k < endNumber; k += j){
                if(smallestPrimeFactors[k] == k)
                smallestPrimeFactors[k] = j;
            }
        }
    }
}

class DSU{
public:
    long long n;
    vector<long long> size, par;
    vector<bool> vis;
 
    DSU(long long n){
        this -> n = n;
        size.resize(n);
        par.resize(n);
        vis.resize(n);
 
        for(long long i = 0; i < n; ++i){
            par[i] = i;
            size[i] = 1;
            vis[i] = 0;
        }
    }
 
    long long find_leader(long long u){
        if (u == par[u])
            return u;
        return par[u] = find_leader(par[u]);
    }
 
    void merge(long long u, long long v){
        vis[u] = 1;
        vis[v] = 1;
        u = find_leader(u); v = find_leader(v);
        if (u == v) return;

        if (size[u] < size[v]){
            swap(u, v);
        } 
        size[u] += size[v];
        par[v] = u;
    }
 
    long long count_components(){
        long long cnt = 0;
        for (long long i = 0; i < n; ++i){
            if (par[i] == i) ++cnt;
        }
 
        return cnt;
    }
};struct segNode
{
    long long sum;

    segNode()
    {
        sum = 0;
    }

    void merge(segNode &x, segNode &y, ll ind)
    {
        if(ind%2 == 1)
        sum = x.sum | y.sum;
        else
        sum = x.sum & y.sum;
    }

    void update(long long val)
    {
        sum = val;
    }
};

class segTree
{
    long long n;
    vector<segNode> tree;

public:
    segTree() {}

    segTree(long long n)
    {
        this->n = n;
        tree.resize(4 * n);
    }

    segTree(vector<long long> &v, long long n)
    {
        this->n = n;
        tree.resize(4 * n);
        fill(all(tree), segNode());

        build(1, 0, n - 1, v);
    }

    void build(long long node, long long l, long long r, vector<long long> &v)
    {
        if (l == r)
        {
            tree[node].update(v[l]);
            return;
        }

        long long mid = l + (r - l) / 2;
        build(node << 1, l, mid, v);
        build(node << 1 | 1, mid + 1, r, v);

        tree[node].merge(tree[node << 1], tree[node << 1 | 1],mid);
    }

    void update(long long pos, long long val)
    {
        update(1, 0, n - 1, pos, val);
    }

    void update(long long node, long long l, long long r, long long pos, long long val)
    {
        if (l == r)
        {
            tree[node].update(val);
            return;
        }

        long long mid = l + (r - l) / 2;
        if (pos <= mid)
        {
            update(node << 1, l, mid, pos, val);
        }
        else
        {
            update(node << 1 | 1, mid + 1, r, pos, val);
        }

        tree[node].merge(tree[node << 1], tree[node << 1 | 1], mid);
    }

    long long query(long long s, long long e)
    {
        segNode ans = query(1, 0, n - 1, s, e);

        return ans.sum;
    }

    segNode query(long long node, long long l, long long r, long long s, long long e)
    {
        if (l >= s && r <= e)
            return tree[node];

        if (l > e || r < s)
            return segNode();

        long long mid = l + (r - l) / 2;

        segNode ans, left, right;
        left = query(node << 1, l, mid, s, e);
        right = query(node << 1 | 1, mid + 1, r, s, e);
        ans.merge(left, right, mid);

        return ans;
    }
};

void solve()
{
    ll n,m; cin >> n >> m;
    vll a(n),b(m);
    rep(0,n,i){
        cin>>a[i];
    }
    rep(0,m,i)cin>>b[i];
    sort(all(a));
    sort(all(b));
    map<ll,ll> m2;
    rep(0,m,i){
        m2[b[i]]++;
    }
    vll at;
    map<ll,ll> ma;
    rep(0,n,i){
        if(m2.find(a[i]) != m2.end()){
            // m[b[i]]--;
            ma[a[i]]++;
            if(m2[a[i]] > 1)m2[a[i]]--;
            else m2.erase(a[i]);
        }
    }
    rep(0,n,i){
        if(ma.find(a[i]) != ma.end()){
            if(ma[a[i]] > 1)ma[a[i]]--;
            else ma.erase(a[i]);
        }
        else{
            at.pb(a[i]);
        }
    }
    ll l1 = 0;
    ll l2 = 0;
    n = at.size();
    vll bt;
    for(auto i : m2){
        ll num = i.second;
        rep(0, num ,j){
            bt.pb((ll)i.first);
        }
    }
    m = bt.size();
    while(l1 < n && l2 < m){
        if(at[l1] > bt[l2]){
            no
            return;
        }
        else{
            if(l1 == n-1){
                no
                return;
            }
            else{
                if(at[l1] + at[l1+1] < bt[l2]){
                    if(abs(at[l1] - at[l1+1]) <= 1){
                        at[l1+1] = at[l1]+at[l1+1];
                    }
                    else{
                       no
                       return; 
                    }
                    l1++;
                }
                else if(at[l1] + at[l1+1] > bt[l2]){
                    no
                    return;
                }
                else{
                    if(abs(at[l1] - at[l1+1]) <= 1){
                        l1++;
                        l1++;
                        l2++;
                    }
                    else{
                        no
                        return;
                    }
                }
            }
        }
    }
    if(l1 ==n && l2 == m){
        yes
        return;
    }
    no
}

int main()
{
  // sieveMethodSmallesPrimeFactors();
  SMIT_FEFAR;
  bool test_cases = 1;
  ll t=1;
  if(test_cases)cin>>t;
  while (t--) solve();
  return 0;
}

Answer: 1