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

Previous submission (verdict: Time limit exceeded on test 3):
#include <bits/stdc++.h>
using namespace std;

#define INF (int)1e9
#define PI 3.1415926535897932384626433832795
#define mod 1000000007
#define yes cout << "YES" << endl 
#define no cout << "NO" << endl 
#define pb push_back
#define l_b lower_bound
#define u_b upper_bound
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef map<int, int> mii;
typedef unordered_map<int, int> umap_ii;
typedef unordered_map<string, int> umap_si;

void solve() {
    ll n, m;
    cin >> n >> m;
    vl a(n), b(m);
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < m; i++) cin >> b[i];

    sort(rall(a));
    sort(rall(b));

    if (a[0]>b[0]) {
        no;
        return;
    }
    if (n==m) {
        for (int i=0; i<m; i++) {
            if (a[i]!=b[i]) {
                no;
                return;
            }
        }
        yes;
        return;
    }

    multiset<ll> st1(all(a)), st2(all(b));
    while (st2.size()>0) {
        
        auto it = prev(st2.end());
        ll x = *it;
        st2.erase(it);

        auto it2 = st1.find(x);
        if (it2 != st1.end()) {
            
            st1.erase(it2);
        } 
        else {
            if (x==1) { 
                no;
                return;
            }
            ll a = x/2;
            ll b = (x/2)+(x%2); 
            st2.insert(a);
            st2.insert(b);
        }

        if (st1.empty()) {
            yes;
            return;
        }
    }

    no;
}

int main() {
    _fastio;
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;

#define INF (int)1e9
#define PI 3.1415926535897932384626433832795
#define mod 1000000007
#define yes cout << "YES" << endl 
#define no cout << "NO" << endl 
#define pb push_back
#define l_b lower_bound
#define u_b upper_bound
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef map<int, int> mii;
typedef unordered_map<int, int> umap_ii;
typedef unordered_map<string, int> umap_si;

void solve() {
    ll n, m;
    cin >> n >> m;
    vl a(n), b(m);
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < m; i++) cin >> b[i];

    sort(rall(a));
    sort(rall(b));

    if (a[0]>b[0]) {
        no;
        return;
    }
    if (n==m) {
        for (int i=0; i<m; i++) {
            if (a[i]!=b[i]) {
                no;
                return;
            }
        }
        yes;
        return;
    }

    multiset<ll> st1, st2;
    for(auto x: a) {
        st1.insert(x);
    }
    for(auto x: b) {
        st2.insert(x);
    }
    while (1) {
            
        if(st1.empty() && st2.empty()) {
            yes;
            return;
        }
        if(st1.empty() || st2.empty()) {
            no;
            return;
        }
        auto it = st2.begin();
        ll x = *it;
        st2.erase(it);

        auto it2 = st1.find(x);
        if (it2 != st1.end()) {
            
            st1.erase(it2);
        } 
        else {
            if (x==1) { 
                no;
                return;
            }
            ll a = x/2;
            ll b = (x/2)+(x%2); 
            st2.insert(a);
            st2.insert(b);
        }
    }

    no;
}

int main() {
    _fastio;
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
}