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;

string solve() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(m);
    for (int &x : a) cin >> x;
    for (int &x : b) cin >> x;
    
    long long sum_a = accumulate(a.begin(), a.end(), 0LL);
    long long sum_b = accumulate(b.begin(), b.end(), 0LL);
    if (sum_a != sum_b) return "No";
    
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    
    multiset<int> ms(a.begin(), a.end());
    
    for (int i = m-1; i >= 0; --i) {
        int s = b[i];
        if (ms.empty()) return "No";
        auto it = ms.find(s);
        if (it != ms.end()) {
            ms.erase(it);
            continue;
        }
        
        // s is not present, need to form it by merging
        if (ms.empty()) return "No";
        auto max_it = prev(ms.end());
        int x = *max_it;
        if (x > s) return "No";
        ms.erase(max_it);
        
        long long sum_needed = s - x;
        int current_sum = x;
        int max_elem = x;
        
        while (sum_needed > 0) {
            if (ms.empty()) return "No";
            auto y_it = ms.upper_bound(sum_needed);
            if (y_it == ms.begin()) {
                return "No";
            }
            --y_it;
            int y = *y_it;
            if (y > sum_needed) {
                return "No";
            }
            sum_needed -= y;
            current_sum += y;
            if (y > max_elem) {
                max_elem = y;
            }
            ms.erase(y_it);
        }
        
        // Check the max condition
        if (max_elem > (s - max_elem) + 1) {
            return "No";
        }
    }
    
    return "Yes";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int t;
    cin >> t;
    while (t--) {
        cout << solve() << '\n';
    }
    
    return 0;
}

Submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>
using namespace std;

string solve() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(m);
    for (int &x : a) cin >> x;
    for (int &x : b) cin >> x;
    
    long long sum_a = accumulate(a.begin(), a.end(), 0LL);
    long long sum_b = accumulate(b.begin(), b.end(), 0LL);
    if (sum_a != sum_b) return "No";
    
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    
    multiset<int> ms(a.begin(), a.end());
    
    for (int i = m - 1; i >= 0; --i) {
        int s = b[i];
        if (ms.empty()) return "No";
        auto it = ms.find(s);
        if (it != ms.end()) {
            ms.erase(it);
            continue;
        }
        
        // Need to form s by merging
        long long sum_needed = s;
        int max_allowed = (s + 1) / 2; // max allowed in the group
        vector<int> group;
        bool possible = true;
        
        while (sum_needed > 0) {
            int current_limit = min(sum_needed, (long long)max_allowed);
            auto y_it = ms.upper_bound(current_limit);
            if (y_it == ms.begin()) {
                possible = false;
                break;
            }
            --y_it;
            int y = *y_it;
            if (y > max_allowed) {
                possible = false;
                break;
            }
            group.push_back(y);
            sum_needed -= y;
            ms.erase(y_it);
        }
        
        if (!possible || sum_needed != 0) {
            return "No";
        }
        
        int group_max = *max_element(group.begin(), group.end());
        if (group_max > max_allowed) {
            return "No";
        }
    }
    
    return "Yes";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int t;
    cin >> t;
    while (t--) {
        cout << solve() << '\n';
    }
    
    return 0;
}