Problem: 2061D - Kevin and Numbers
Language: c++17 

Solution 1 (runtime: 186 ms):
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
 
typedef long long ll;
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
 
    int t;
    cin >> t;
    while(t--){
        int n, m;
        cin >> n >> m;
        vector<ll> a(n), b(m);
        ll sumA = 0, sumB = 0;
 
        for (int i = 0; i < n; i++){
            cin >> a[i];
            sumA += a[i];
        }
        for (int j = 0; j < m; j++){
            cin >> b[j];
            sumB += b[j];
        }
 
        // Check the invariant.
        if(sumA != sumB){
            cout << "No\n";
            continue;
        }
 
        // Sort target pieces in non-increasing order.
        sort(a.begin(), a.end(), greater<ll>());
 
        // Use a max-heap to simulate splitting the numbers from b.
        priority_queue<ll> pq;
        for (ll x : b)
            pq.push(x);
 
        bool possible = true;
        int i = 0;  // index for target pieces in a
 
        // For each target piece in a (largest first) try to match using available pieces.
        while(i < n && !pq.empty()){
            ll cur = pq.top();
            pq.pop();
 
            // If the current available piece exactly matches the target, we have a match.
            if(cur == a[i]){
                i++;  // move to the next target piece
            } 
            // If the current piece is larger, split it.
            else if(cur > a[i]){
                // Cannot split further if the piece is 1.
                if(cur == 1){
                    possible = false;
                    break;
                }
                ll left = cur / 2;
                ll right = cur - left;  // ensures left + right = cur and |left - right| <= 1.
                pq.push(left);
                pq.push(right);
            }
            else{
                // If the piece is smaller than the target, it's impossible.
                possible = false;
                break;
            }
        }
 
        // If not all target pieces were matched, the answer is "No".
        cout << (possible && i == n ? "Yes" : "No") << "\n";
    }
    return 0;
}


Solution 2 (runtime: 484 ms):
#include<bits/stdc++.h>
using namespace std;
#define int long long 
using ll = long long;
using pii = pair<int,int>;
#define _rep(i,a,b) for(int i = (a);i <= (b);i ++)
#define _for(i,a,b) for(int i = (a);i < (b) ;i ++)
#define pb push_back
void solve(){
	int n , m; cin >> n >> m;
	multiset<int> s1;
	multiset<int> s2;
	for(int i = 0;i < n;  ++ i){
		int x; cin >> x; s1.insert(x);
	} for(int i = 0;i < m;  ++ i){
		int x; cin >> x; s2.insert(x);
	}
	while(s1.size() && s2.size()){
		auto t1 = *s1.begin();
		auto t2 = *s2.begin();
		if(t1 == t2){
			s1.erase(s1.begin());
			s2.erase(s2.begin()); 
		}else if(t1 > t2){
			cout << "No" << endl;
			return; 
		}else{
			auto x  = s1.find(t2);
			s2.erase(s2.begin());
			if(x != s1.end()){
				s1.erase(x);
				continue;
			}
			
			s2.insert((t2 + 1) / 2);
			s2.insert((t2) / 2); 
		}
	}
	if(s1.size() == 0 && s2.size() == 0){
		cout << "Yes" << endl;
	}else cout << "No" << endl;
	return;
}
signed main(){
	std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
	int _;cin >> _;
	while(_--){
		solve();
	}
	return 0;
}
/*   /\_/\
*   (= ._.)
*   / >  \>
*/