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

Previous submission (verdict: Time limit exceeded on test 27):
// author: лелутик :3
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <cassert>
#include <map>
#include <cmath>
#include <iomanip>
#include <random>
#include <functional>
#include <string>
#include <queue>
#include <stack>

using namespace std;
#define int               long long
#define pii               pair<int, int>
#define line              cout << "\n"
#define pb                push_back
#define ppb               pop_back
#define sz(a)             (int) a.size()
#define all(a)            a.begin(), a.end()
#define rall(a)           a.rbegin(), a.rend()
#define fast              ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
typedef long long ll;
typedef long double ld;
typedef string str;
mt19937 rnd(time(0));
const int MOD = 998244353;


void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(m);
    multiset<int> st1, st2;
    int s1 = 0, s2 = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        st1.insert(a[i]);
        s1 += a[i];
    }
    for (int i = 0; i < m; i++) {
        cin >> b[i];
        st2.insert(b[i]);
        s2 += b[i];
    }
    if (s1 != s2) {
        cout << "No"; line;
        return;
    }
    while (sz(st1) && sz(st2)) {
        int x = *(--st2.end());
        if (x < *st1.begin()) {
            cout << "No"; line;
            return;
        }
        st2.erase(--st2.end());
        if (st1.find(x) != st1.end()) {
            st1.erase(st1.find(x));
            continue;
        }
        st2.insert(x / 2);
        st2.insert((x + 1) / 2);
    }
    if (sz(st1) || sz(st2)) {
        cout << "No"; line;
        return;
    }
    cout << "Yes"; line;
}


signed main() {
    fast;


#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif


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


Submission (verdict: Time limit exceeded on test 27):
// author: лелутик :3
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <cassert>
#include <map>
#include <cmath>
#include <iomanip> 
#include <random>
#include <functional>
#include <string>
#include <queue>
#include <stack>

using namespace std;
#define int               long long
#define pii               pair<int, int>
#define line              cout << "\n"
#define pb                push_back
#define ppb               pop_back
#define sz(a)             (int) a.size()
#define all(a)            a.begin(), a.end()
#define rall(a)           a.rbegin(), a.rend()
#define fast              ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
typedef long long ll;
typedef long double ld;
typedef string str;
mt19937 rnd(time(0));
const int MOD = 998244353;


void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(m);
    multiset<int> st1, st2;
    int s1 = 0, s2 = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        st1.insert(a[i]);
        s1 += a[i];
    }
    for (int i = 0; i < m; i++) {
        cin >> b[i];
        st2.insert(b[i]);
        s2 += b[i];
    }
    if (s1 != s2) {
        cout << "No"; line;
        return;
    }
    while (sz(st1) && sz(st2)) {
        int x = *(--st2.end());
        if (x < *st1.begin()) {
            cout << "No"; line;
            return;
        }
        st2.erase(--st2.end());
        if (st1.find(x) != st1.end()) {
            st1.erase(st1.find(x));
            continue;
        }
        st2.insert(x / 2);
        st2.insert((x + 1) / 2);
    }
    if (sz(st1) || sz(st2)) {
        cout << "No"; line;
        return;
    }
    cout << "Yes"; line;
}


signed main() {
    fast;


#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif


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