Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 29):
#include <bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
// #define endl "\n"
#define int long long int
#define deb(x) cout << #x << "=" << x << endl
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define read(a, n)             \
    for (int i = 0; i < n; ++i) \
        cin >> a[i];
#define print(a, n)               \
    for (int i = 0; i < n; ++i)    \
        if (i == n - 1)           \
        {                         \
            cout << a[i] << "\n"; \
        }                         \
        else                      \
        {                         \
            cout << a[i] << ' ';  \
        }
#define trav(it, x) for (auto it = x.begin(); it != x.end(); it++)
#define f(a, start, end) for (int a = start; a < end; a++)
#define ft(a, end) for (int a = 0; a < end; a++)
#define fi(a, start, end, inc) for (int a = start; a < end; a += inc)
#define si(x) scanf("%lld", &x)
#define sll(x) scanf("%lld", &x)
#define ss(s) scanf("%s", s)
#define pi(x) printf("%d\n", x)
#define pll(x) printf("%lld\n", x)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sortall(x) sort(all(x))
// #define PI 3.14159265

typedef vector<int> vi;
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

const int MOD = (int)(1e9 + 7);

int binexp(int a, int b){ 
   int ans = 1;
   while(b > 0){
        if(b&1){
            ans *= a;
            ans %= MOD;
        }
        a *= a;
        a %= MOD;
        b >>= 1;
   }
   return ans;
}

int modInverse(int A, int M){
    return binexp(A, M - 2);
}


void solve()
{
    int n, m ;
    cin>>n>>m;

    vi a(n);
    vi b(m);

    read(a, n);
    read(b, m);

    if( n <  m ){
      cout<<"No"<<endl;
      return;
    }

    sortall(a);
    sortall(b);
    int j= 0;

    vi temp_b;

    unordered_map<int,int> mp;
    int s = 0;
    int i = 0;

    for( ;i < n && j <m ; i++, j++){
      if(a[i] >= b[j]){
        if(a[i] != b[j]) {i--; temp_b.pb(b[j]);}
        continue;
      } 
      mp[a[i]]++;
      s++;
      j--;
    }
    for( ;i < n; i++){
      mp[a[i]]++;
      s++;
    }
    for( ;j < m; j++){
      temp_b.pb(b[j]);
    }
    if(s < temp_b.size()*2) {cout<<"No"<<endl; return;}
    if(s > 0 && temp_b.size() <= 0) {cout<<"No"<<endl; return;}

    bool flag = true;
    // cout<<s<<temp_b.size()<<endl;
    s = s-temp_b.size();
    while(s > 0){
      vi temp;
      for(int i = 0 ; i < temp_b.size() ; i++){
        int a = temp_b[i]/2;
        int b = (temp_b[i]+1)/2;

        if(mp[a] == 0) temp.pb(a);
        else mp[a]--; 
        
        if(mp[b] == 0) temp.pb(b);
        else mp[b]--; 
        s--;
      }
      temp_b = temp;
      if (temp.empty()) break;
    }

    if(temp_b.size() == 0 && s == 0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

  
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
   // #ifndef ONLINE_JUDGE
     //   freopen("input.txt", "r", stdin);

       // freopen("output.txt", "w", stdout);

    //  #endif

    int t = 1;
    cin>>t;
    while (t--)
    {
        solve();
    }
    return 0;
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
// #define endl "\n"
#define int long long int
#define deb(x) cout << #x << "=" << x << endl
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define read(a, n)             \
    for (int i = 0; i < n; ++i) \
        cin >> a[i];
#define print(a, n)               \
    for (int i = 0; i < n; ++i)    \
        if (i == n - 1)           \
        {                         \
            cout << a[i] << "\n"; \
        }                         \
        else                      \
        {                         \
            cout << a[i] << ' ';  \
        }
#define trav(it, x) for (auto it = x.begin(); it != x.end(); it++)
#define f(a, start, end) for (int a = start; a < end; a++)
#define ft(a, end) for (int a = 0; a < end; a++)
#define fi(a, start, end, inc) for (int a = start; a < end; a += inc)
#define si(x) scanf("%lld", &x)
#define sll(x) scanf("%lld", &x)
#define ss(s) scanf("%s", s)
#define pi(x) printf("%d\n", x)
#define pll(x) printf("%lld\n", x)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sortall(x) sort(all(x))
// #define PI 3.14159265

typedef vector<int> vi;
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

const int MOD = (int)(1e9 + 7);

int binexp(int a, int b){ 
   int ans = 1;
   while(b > 0){
        if(b&1){
            ans *= a;
            ans %= MOD;
        }
        a *= a;
        a %= MOD;
        b >>= 1;
   }
   return ans;
}

int modInverse(int A, int M){
    return binexp(A, M - 2);
}


void solve()
{
    int n, m ;
    cin>>n>>m;

    vi a(n);
    vi b(m);

    read(a, n);
    read(b, m);

    if( n <  m ){
      cout<<"No"<<endl;
      return;
    }

    sortall(a);
    sortall(b);
    int j= 0;

    vi temp_b;

    map<int,int> mp;
    int s = 0;
    int i = 0;

    for( ;i < n && j <m ; i++, j++){
      if(a[i] >= b[j]){
        if(a[i] != b[j]) {i--; temp_b.pb(b[j]);}
        continue;
      } 
      mp[a[i]]++;
      s++;
      j--;
    }
    for( ;i < n; i++){
      mp[a[i]]++;
      s++;
    }
    for( ;j < m; j++){
      temp_b.pb(b[j]);
    }
    
    if(s < temp_b.size()*2) {cout<<"No"<<endl; return;}
    if(s > 0 && temp_b.size() <= 0) {cout<<"No"<<endl; return;}

    bool flag = true;
    
    s = s-temp_b.size();
    while(s > 0){
      vi temp;
      for(int i = 0 ; i < temp_b.size() ; i++){
        int a = temp_b[i]/2;
        int b = (temp_b[i]+1)/2;

        if(mp[a] == 0) temp.pb(a);
        else mp[a]--; 
        
        if(mp[b] == 0) temp.pb(b);
        else mp[b]--; 
        s--;
      }
      temp_b = temp;
      if (temp.empty()) break;
    }

    if(temp_b.size() == 0 && s == 0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

  
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
   // #ifndef ONLINE_JUDGE
     //   freopen("input.txt", "r", stdin);

       // freopen("output.txt", "w", stdout);

    //  #endif

    int t = 1;
    cin>>t;
    while (t--)
    {
        solve();
    }
    return 0;
}