Problem: 2061D - Kevin and Numbers
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 3):

#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() {

  ll n, m;
  cin >> n >> m;
  vector <ll> vn(n);
  vector <ll> vm(m);
  map <ll, ll> mn;
  map <ll, ll> mm;
  fo(i, n) {
  	cin >> vn[i];
  	mn[vn[i]]++;
  }
  fo(i, m) {
  	cin >> vm[i];
  	mm[vm[i]]++;
  }
  for ( auto it : mn) {
  	if (mm[it.first] >= 1 && it.second >= 1) {
  		ll m = min(it.second, mm[it.first]);
  		mm[it.first] -= m;
  		mn[it.first] -= m;  		
  		// if (mm[it.first] == 0) mm.erase(it.first);
  		// if (mn[it.first] == 0) mn.erase(it.first);
  	} 
  }
  // for (auto it : mn) {
  // 	cout << it.first << " " << it.second << endl;
  // }
  // for (auto it : mm) {
  // 	cout << it.first << " " << it.second << endl;
  // }
  set <ll> sn;
  set <ll> sm;
  for (auto it : mn) {
  	if (it.second > 0) sn.insert(it.first);
  }
  for (auto it : mm) {
  	if (it.second > 0) sm.insert(it.first);
  }
  if (sn.size() == 0 && sm.size() == 0) {
  	cout << "YES" << endl;
  	return;
  }
  // else if (sn.size() == sm.size()) {
  // 	cout << "NO" << endl;
  // 	return;
  // }
  else if (*sm.begin() < *sn.begin()) {
  	cout << "NO" << endl;
  	return;
  }
  for (ll it : sn) {
  	if (mm[it] >= 1 && mn[it] >= 1) {
  		ll m = min(mn[it], mm[it]);
  		mm[it] -= m;
  		mn[it] -= m;  
  	}
  	if (mn[it] > 1) {
  		mn[it * 2] += mn[it]/2;
  		sn.insert(it * 2);
  		mn[it] %= 2;
  	}
  	if (mn[it] >= 1 && mn[it+1] >= 1) {
  		
  		ll m = min(mn[it], mn[it+1]);
  		mn[it] -= m;
  		mn[it+1] -= m;
  		mn[it*2 + 1] += m;
  		sn.insert(it*2 + 1);
  	}
  	if (mn[it] != 0) {
  		cout << "NO" << endl;
  		return;
  	}
  }
  
  for (auto i : mm) {
  	if (i.second != mn[i.first]) {
  		cout << "NO" << endl;
  		return;
  	}
  }
  cout << "YES" << 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
}


Submission (verdict: Wrong answer on test 3):

#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(*i);
        b.erase(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
}