Problem: 2061D - Kevin and Numbers
Language: C++23 (GCC 14-64, msys2)

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

void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(m);
    long long sum_a = 0, sum_b = 0;
    for (int &x : a) {
        cin >> x;
        sum_a += x;
    }
    for (int &x : b) {
        cin >> x;
        sum_b += x;
    }
    if (sum_a != sum_b) {
        cout << "No\n";
        return;
    }
    
    sort(a.begin(), a.end(), greater<int>());
    sort(b.begin(), b.end(), greater<int>());
    
    unordered_map<int, int> freq;
    for (int x : a) {
        freq[x]++;
    }
    
    set<int, greater<int>> available;
    for (auto &[k, v] : freq) {
        if (v > 0) {
            available.insert(k);
        }
    }
    
    priority_queue<int> pq;
    for (int x : b) {
        pq.push(x);
    }
    
    bool possible = true;
    int remaining = n;
    
    while (!pq.empty()) {
        int s = pq.top();
        pq.pop();
        
        auto it = freq.find(s);
        if (it != freq.end() && it->second > 0) {
            it->second--;
            remaining--;
            if (it->second == 0) {
                available.erase(s);
                freq.erase(it);
            }
            continue;
        }
        
        if (available.empty()) {
            possible = false;
            break;
        }
        int current_max = *available.begin();
        if (s < current_max) {
            possible = false;
            break;
        }
        
        if (s == 1) {
            possible = false;
            break;
        }
        int x = (s + 1) / 2;
        int y = s / 2;
        
        pq.push(x);
        pq.push(y);
        
        if (pq.size() > remaining) {
            possible = false;
            break;
        }
    }
    
    if (possible && remaining == 0) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

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

void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(m);
    long long sum_a = 0, sum_b = 0;
    for (int &x : a) {
        cin >> x;
        sum_a += x;
    }
    for (int &x : b) {
        cin >> x;
        sum_b += x;
    }
    if (sum_a != sum_b) {
        cout << "No\n";
        return;
    }
    
    sort(a.begin(), a.end(), greater<int>());
    sort(b.begin(), b.end(), greater<int>());
    
    unordered_map<int, int> freq;
    for (int x : a) {
        freq[x]++;
    }
    
    priority_queue<int> a_pq;
    for (auto &p : freq) {
        a_pq.push(p.first);
    }
    
    auto get_current_max = [&]() {
        while (!a_pq.empty()) {
            int top = a_pq.top();
            auto it = freq.find(top);
            if (it != freq.end() && it->second > 0) {
                return top;
            } else {
                a_pq.pop();
            }
        }
        return -1;
    };
    
    priority_queue<int> pq;
    for (int x : b) {
        pq.push(x);
    }
    
    bool possible = true;
    int remaining = n;
    
    while (!pq.empty()) {
        int s = pq.top();
        pq.pop();
        
        int current_max = get_current_max();
        if (current_max == -1) {
            possible = false;
            break;
        }
        
        if (s < current_max) {
            possible = false;
            break;
        }
        
        auto it = freq.find(s);
        if (it != freq.end() && it->second > 0) {
            it->second--;
            remaining--;
            if (it->second == 0) {
                freq.erase(it);
            }
            continue;
        }
        
        if (s == 1) {
            possible = false;
            break;
        }
        
        int x = (s + 1) / 2;
        int y = s / 2;
        pq.push(x);
        pq.push(y);
        
        if (pq.size() > remaining) {
            possible = false;
            break;
        }
    }
    
    if (possible && remaining == 0) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}