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

Previous submission (verdict: Wrong answer on test 1):
#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;
        }
        if (ms.empty() || *prev(ms.end()) > s) return "No";
        
        long long current = 0;
        int max_elem = 0;
        vector<int> temp;
        while (current < s) {
            if (ms.empty()) return "No";
            auto it = prev(ms.end());
            int x = *it;
            ms.erase(it);
            current += x;
            temp.push_back(x);
            max_elem = max(max_elem, x);
        }
        if (current != s) return "No";
        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;
        }
        
        // 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;
}