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

Solution 1 (runtime: 328 ms):
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

#include <iostream>
#include <iomanip>
#include <sstream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <vector>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <map>
#include <numeric>  
#include <queue>
#include <stack>
#include <limits.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define SORT(v) sort(v.begin(), v.end())
#define RSORT(v) sort(v.rbegin(), v.rend())
#define ASORT(a, n) sort(a, a + n)
// nonstrict lower bound of x in a
#define LB(a, x) lower_bound(a.begin(), a.end(), x)
#define UB(a, x) upper_bound(a.begin(), a.end(), x)
// returns a pair of iterators representing [first, last)]
#define ER(a, x) equal_range(a.begin(), a.end(), x)

const int MOD = 1000000007;
const char nl = '\n';

template <typename Container>
void print(const Container& c) {
    for (const auto& elem : c) {
        cout << elem << " ";
    }
    cout << nl;
}

void solve() {
    int n, m; cin >> n >> m;
    multiset<ll> a;
    multiset<ll> b;
    ll x;
    FOR(i, 0, n) {
        cin >> x; a.insert(x);
    }
    FOR(i, 0, m) {
        cin >> x; 
        if (a.count(x)) a.erase(a.find(x));
        else b.insert(x);
    }
    // remove all overlaps with a and b
    // take the maximum of b repeatedly 
    while (a.size() > b.size() && b.size() > 0) {

        x = *prev(b.end());
        if (x < *prev(a.end())) {
            // impossible to recoover
            break;
        }
        b.erase(b.find(x));
        ll y = x/2;
        ll z = (x+1)/2;
        if (a.count(y)) a.erase(a.find(y));    
        else b.insert(y);
        if (a.count(z)) a.erase(a.find(z));    
        else b.insert(z);
    }


    if (a.size() == 0) cout << "YES" << nl;
    else cout << "NO" << nl;

    // we will resign when size(a) > size(b)
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
 
    int t; cin >> t;
    FOR(i, 0, t) {
        solve();
    }
}


Solution 2 (runtime: 405 ms):

#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long

#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626

vector< ll> primes, is_prime, spf;

void sieve( ll n);
ll expo(ll a, ll b); // gives a^b 
bool isPrime(ll num) ;


const  ll mod = 1'000'000'007;
const  ll N = 3e5, M = N;
//=======================


void solve() {

  int n, m;
  cin >> n >> m;
  multiset <int, greater<int>> a;
  multiset <int, greater<int>> b;
  
  fo(i, n) {
  	int temp;
  	cin >> temp;
    a.insert(temp);
  }
  fo(i, m) {
  	int temp;
    cin >> temp;
    b.insert(temp);
  }
  while (!b.empty() && !a.empty()) {
    auto i = b.begin();
    if (*i < *a.begin() || b.size() > 2*a.size()) {
        break;
    }
    //cout << *i << endl;
    if (a.find(*i) != a.end()) {
        a.erase(a.lower_bound(*i));
        b.erase(b.lower_bound(*i));
        continue;
    }
    int b1, b2;
    if (*i % 2 == 0) {
        b1 = (*i)/2;
        b2 = (*i)/2;
    }
    else {
        b1 = (*i)/2;
        b2 = (*i)/2 + 1;
    }
    //cout << b1 << " " << b2 << endl;
    if (a.find(b1) != a.end()) {
        a.erase(a.lower_bound(b1));
    }
    else {
        b.insert(b1);
    }
    if (a.find(b2) != a.end()) {
        a.erase(a.lower_bound(b2));
    }
    else {

        b.insert(b2);
    }
    b.erase(b.lower_bound(*i));
    // for (int i : a) cout << "a"  << " " << i << " ";
    // cout << endl;
    // for (int i : b) cout << "b"  << " " << i << " ";
    // cout << endl;
  }
  if (a.empty() && b.empty()) cout << "YES" << endl;
  else cout << "NO" << endl;
 
  

}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());

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

    return 0;
}






void sieve( ll n) {
    primes.clear();
    is_prime.assign(n + 1, 1);
    spf.assign(n + 1, 0);
    is_prime[0] = is_prime[1] = false;
    for (ll i = 2; i <= n; i++) {
        if (is_prime[i]) {
            primes.push_back(i);
            spf[i] = i;
            for (ll j = i * i; j <= n; j += i) {
                is_prime[j] = false;
                spf[j] = i;
            }
         }
     }
}

long long expo(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

bool isPrime(ll num) {
    if (num <= 1) return false; // 1 or smaller are not prime
    if (num == 2) return true;  // 2 is the only even prime number
    if (num % 2 == 0) return false; // Other even numbers are not prime

    ll limit = static_cast<ll>(sqrt(num)); // We only need to check up to the square root
    for (ll i = 3; i <= limit; i += 2) { // Check odd numbers only
        if (num % i == 0) {
            return false; // Found a divisor, so not prime
        }
    }
    return true; // No divisors found, it is prime
}