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

  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
}


Submission (verdict: Wrong answer on test 1):

#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
}