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

Previous submission (verdict: Wrong answer 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;

bool isPossible(multiset<ll>& st, ll target) {
    if (st.find(target) != st.end()) {
        st.erase(st.find(target)); 
        return true;
    }

    if (target==1 || st.empty()) return false; 
    ll part1 = target/2;
    ll part2 = target-part1;

    if (st.count(part1)>0) {
        
        st.erase(st.find(part1));
        if (isPossible(st, part2)) {
            return true;
        }
        st.insert(part1);
    }

    if (st.count(part2)>0) {
       
        st.erase(st.find(part2));
        if (isPossible(st, part1)) {
            return true;
        }
        st.insert(part2);
    }

    return false;
}

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(all(a));
    sort(all(b));
    if(a[n-1]>b[m-1]) {
        no; 
        return;
    }
    if (n==m) {
        for (int i=0; i<m; i++) {
            if (a[i]!=b[i]) {
                no;
                return;
            }
        }
        yes;
        return;
    }

    multiset<ll> st;
    for (auto x : a) {
        st.insert(x);
    }

    for (int i = 0; i < m; i++) {
        ll x = b[i];
        if (st.find(x)!=st.end()) {
            st.erase(st.find(x)); 
        } 
        else if (!isPossible(st, x)) {
            no;
            return;
        }
    }
    if(!st.empty()) {
        no;
        return;
    }
    yes;
}

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

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();
    }
}