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

Previous submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

using namespace std;

using namespace __gnu_pbds;

template <typename T>

using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define int long long

#define pb push_back

#define pf push_front

#define eb emplace_back

#define ins insert

#define F first

#define S second

#define MAXN 100005

#define LOG (int)log2(MAXN)+1



const int INF = LLONG_MAX-10;

const int MOD = 1e9;

const double EPS = 1e-8;



//WA?



void solve() {

    int n, m;

    cin >> n >> m;



    multiset<int> ms_a, ms_b;

    vector<int> b_vals(m);

    for (int i = 0, x; i < n; ++i) {

        cin >> x;

        ms_a.ins(x);

    }

    for (int i = 0; i < m; ++i) {

        cin >> b_vals[i];

        ms_b.ins(b_vals[i]);

    }



    for (int x : b_vals) {

        auto it = ms_a.find(x);

        if (it != ms_a.end()) {

            ms_a.erase(it);

            ms_b.erase(ms_b.find(x));

        }

    }



    vector<int> a_rem(ms_a.begin(), ms_a.end());

    vector<int> b_rem(ms_b.begin(), ms_b.end());



    if ((a_rem.empty() && !b_rem.empty()) || (!a_rem.empty() && b_rem.empty())) {

        cout << "No\n";

        return;

    }



    int idx = 0;

    for (int target : b_rem) {

        int sum = a_rem[idx++];

        while (idx < (int)a_rem.size() && sum < target && llabs(sum - a_rem[idx]) <= 1) {

            sum += a_rem[idx++];

        }

        if (sum != target) {

            cout << "No\n";

            return;

        }

    }



    cout << "Yes\n";

}





signed main() {

    ios_base::sync_with_stdio(0);  cin.tie(0);  cout.tie(0);

    int t = 1;

    cin >> t;

    while(t--) solve();

    return 0;

}



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

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

using namespace std;

using namespace __gnu_pbds;

template <typename T>

using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define int long long

#define pb push_back

#define pf push_front

#define eb emplace_back

#define ins insert

#define F first

#define S second

#define MAXN 100005

#define LOG (int)log2(MAXN)+1



const int INF = LLONG_MAX-10;

const int MOD = 1e9;

const double EPS = 1e-8;



void solve() {

	int n, m;

	cin >> n >> m;

	multiset<int> a, b;

	for(int i = 0; i < n; i++){

		int x;

		cin >> x;

		a.ins(x);

	}

	for(int i = 0; i < m; i++){

		int x;

		cin >> x;

		b.ins(x);

	}

	int t = n-m, c = 0;

	while(c<t && !a.empty() && !b.empty()){

		auto it1 = prev(b.end()), it2 = prev(a.end());

		b.erase(it1);

		if(*it1==*it2){

			a.erase(it2);

		} else{

			int x = *it1;

			b.ins( x/2 );

			b.ins( (x+1)/2 );

			c++;

		}

	}	

//	for(auto el: a) cout << el << ' '; cout << '\n';

//	for(auto el: b) cout << el << ' '; cout << '\n';

	if(a==b) cout << "Yes\n";

	else cout << "No\n";

}





signed main() {

    ios_base::sync_with_stdio(0);  cin.tie(0);  cout.tie(0);

    int t = 1;

    cin >> t;

    while(t--) solve();

    return 0;

}