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

Previous submission (verdict: Runtime error on test 3):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define ve vector
#define fi first
#define se second
#define pb push_back
#define pll pair<int,int>
#define AC cout << "\n---------------------\n";
#define vi vector<int>
#define vii vector<vi>
//srand((unsigned int)time(NULL));        rand();
const double eps = 1e-6;
const double pi = acos(-1.0);
const int N = 1e5 + 10;
const int mod = 998244353;
const int inf = 1e18;
void solve() {
    int n, m;
    cin >> n >> m;
    vi a1(n + 1);
    vi a2(m + 1);
    int sum1 = 0, sum2 = 0;
    for (int i = 1; i <= n; i++)cin >> a1[i], sum1 += a1[i];
    for (int i = 1; i <= m; i++)cin >> a2[i], sum2 += a2[i];
    vi vis2(m + 1);
    vi vis1(n + 1);
    if (sum1 != sum2){
        cout << "NO\n";
        return ;
    }
    sort(a1.begin(), a1.end());
    sort(a2.begin(), a2.end());
    int p1 = 1;
    for (int i = 1; i <= m; i++){
        while (a1[p1] < a2[i] && p1 + 1 <= n)p1++;
        if (a1[p1] == a2[i]){
            p1++;
            vis1[p1] = 1;
            vis2[i] = 1;
        }
    }
    multiset<int> s1, s2;
    for (int i = 1; i <= n; i++){
        if (vis1[i] == 0)s1.insert(a1[i]);
    }
    for (int i = 1; i <= m; i++){
        if (vis2[i] == 0)s2.insert(a2[i]);
    }
    while (s2.size()){
        while(s1.size() && *s1.begin() == *s2.begin()){
            s1.erase(s1.begin());
            s2.erase(s2.begin());
        }
        if (s2.size() == 0)break;
        if (*s1.begin() > *s2.begin()){
            break;
        }
        int x = *s1.begin();
        s1.erase(s1.begin());
        int y = *s1.begin();
        s1.erase(s1.begin());
        if (abs(x - y) > 1){
            break;
        }
        s1.insert(x + y);
    }
    cout << (s2.size() == 0 ? "YES\n" : "NO\n");
}
/*

*/
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);// getline()前请使用cin.ignore();  或者关闭ios 启动getchar()
    int t1 = 1;
    cin >> t1;
    while (t1--){
        solve();
    }
    return 0;
}

Submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define ve vector
#define fi first
#define se second
#define pb push_back
#define pll pair<int,int>
#define AC cout << "\n---------------------\n";
#define vi vector<int>
#define vii vector<vi>
//srand((unsigned int)time(NULL));        rand();
const double eps = 1e-6;
const double pi = acos(-1.0);
const int N = 1e5 + 10;
const int mod = 998244353;
const int inf = 1e18;
void solve() {
    int n, m;
    cin >> n >> m;
    vi a1(n + 1);
    vi a2(m + 1);
    int sum1 = 0, sum2 = 0;
    for (int i = 1; i <= n; i++)cin >> a1[i], sum1 += a1[i];
    for (int i = 1; i <= m; i++)cin >> a2[i], sum2 += a2[i];
    vi vis2(m + 1);
    vi vis1(n + 1);
    if (sum1 != sum2){
        cout << "NO\n";
        return ;
    }
    sort(a1.begin(), a1.end());
    sort(a2.begin(), a2.end());
    int p1 = 1;
    for (int i = 1; i <= m; i++){
        while (p1 + 1 <= n && a1[p1] < a2[i])p1++;
        if (p1 <= n && a1[p1] == a2[i]){
            vis1[p1] = 1;
            vis2[i] = 1;
            p1++;
        }
    }
    multiset<int> s1, s2;
    for (int i = 1; i <= n; i++){
        if (vis1[i] == 0)s1.insert(a1[i]);
    }
    for (int i = 1; i <= m; i++){
        if (vis2[i] == 0)s2.insert(a2[i]);
    }
    while (s2.size()){
        while(s1.size() && *s1.begin() == *s2.begin()){
            s1.erase(s1.begin());
            s2.erase(s2.begin());
        }
        if (s2.size() == 0)break;
        if (*s1.begin() > *s2.begin()){
            break;
        }
        int x = *s1.begin();
        s1.erase(s1.begin());
        int y = *s1.begin();
        s1.erase(s1.begin());
        if (abs(x - y) > 1){
            break;
        }
        s1.insert(x + y);
    }
    cout << (s2.size() == 0 ? "YES\n" : "NO\n");
}
/*

*/
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);// getline()前请使用cin.ignore();  或者关闭ios 启动getchar()
    int t1 = 1;
    cin >> t1;
    while (t1--){
        solve();
    }
    return 0;
}