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

Previous submission (verdict: Runtime error on test 2):
#include <bits/stdc++.h>

// #define int long long
#define PII pair<int, int>
#define ll long long

using namespace std;

int T, n, m;

void solve()
{
    cin >> n >> m;
    priority_queue<int, vector<int>, greater<int>> qa, qb;
    int sa = 0, sb = 0;
    for(int i = 0, x;i < n;i ++){
        cin >> x;
        sa += x;
        qa.push(x);
    }
    for(int i = 0, x;i < m;i ++){
        cin >> x;
        sb += x;
        qb.push(x);
    }
    if(sa != sb){
        cout << "NO" << endl;
        return;
    }
    while(!qa.empty() && !qb.empty())
    {
        auto a = qa.top(), b = qb.top();
        // cout << a << " " << b << endl;
        qa.pop(), qb.pop();
        if(a < b){
            qa.push(a);
            while(!qa.empty())
            {
                auto t1 = qa.top();
                qa.pop();

                if(t1 == b) break;

                auto t2 = qa.top();
                qa.pop();
                if(t2 - t1 > 1){
                    cout << "NO" << endl;
                    return;
                }
                qa.push(t1 + t2);
            }
        }else if(a > b){
            qb.push(b);
            while(!qb.empty())
            {
                auto t1 = qb.top();
                qb.pop();

                if(t1 == a) break;

                auto t2 = qb.top();
                qb.pop();
                if(t2 - t1 > 1){
                    cout << "NO" << endl;
                    return;
                }
                qb.push(t1 + t2);
            }
        }
    }
    if(qa.empty() && qb.empty()) cout << "YES" << endl;
    else cout << "NO" << endl;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> T;
    while(T --){
        solve();
    }
    return 0;
}

Submission (verdict: Runtime error on test 3):
#include <bits/stdc++.h>

// #define int long long
#define PII pair<int, int>
#define ll long long

using namespace std;

int T, n, m;

void solve()
{
    cin >> n >> m;
    priority_queue<int, vector<int>, greater<int>> qa, qb;
    ll sa = 0, sb = 0;
    for(int i = 0, x;i < n;i ++){
        cin >> x;
        sa += x;
        qa.push(x);
    }
    for(int i = 0, x;i < m;i ++){
        cin >> x;
        sb += x;
        qb.push(x);
    }
    if(sa != sb){
        cout << "NO" << endl;
        return;
    }
    while(!qa.empty() && !qb.empty())
    {
        auto a = qa.top(), b = qb.top();
        // cout << a << " " << b << endl;
        qa.pop(), qb.pop();
        if(a < b){
            qa.push(a);
            while(!qa.empty())
            {
                auto t1 = qa.top();
                qa.pop();

                if(t1 == b) break;

                auto t2 = qa.top();
                qa.pop();
                if(t2 - t1 > 1){
                    cout << "NO" << endl;
                    return;
                }
                qa.push(t1 + t2);
            }
        }else if(a > b){
            qb.push(b);
            while(!qb.empty())
            {
                auto t1 = qb.top();
                qb.pop();

                if(t1 == a) break;

                auto t2 = qb.top();
                qb.pop();
                if(t2 - t1 > 1){
                    cout << "NO" << endl;
                    return;
                }
                qb.push(t1 + t2);
            }
        }
    }
    if(qa.empty() && qb.empty()) cout << "YES" << endl;
    else cout << "NO" << endl;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> T;
    while(T --){
        solve();
    }
    return 0;
}