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

Previous submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int INF = 1e18;
const int MOD = 1e9 + 7;

void solve() {
    int n,m;
    cin>>n>>m;

    vector<int>a(n),b(m);
    for(int i=0;i<n;i++) cin>>a[i];
    for(int j=0;j<m;j++) cin>>b[j];

    priority_queue<int> q1,q2;
    
    for(auto i:a) q1.push(i);
    for(auto i:b) q2.push(i);

    while(!q2.empty()){
        int curr=q2.top();
        q2.pop();

        if(q1.top()==curr){
            q1.pop();
            continue;
        }

        else if(q1.top()>curr){
            cout<<"NO"<<endl;
            return;
        }
        else if(q1.size()<q2.size()){
            cout<<"NO"<<endl;
            return;
        }
        q2.push(curr/2);
        q2.push((curr+1)/2);
    }
    if(q1.size()) cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
}

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

    int t = 1;
    cin >> t;
    while (t--) solve();

    return 0;
}


Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;

// Function to check if sequence a can be transformed into sequence b
string canTransform(vector<int>& a, vector<int>& b) {
    long long sum_a = 0, sum_b = 0;
    
    // Calculate the sum of elements in a and b
    for (int x : a) sum_a += x;
    for (int x : b) sum_b += x;
    
    // If sums are not equal, transformation is impossible
    if (sum_a != sum_b) {
        return "No";
    }
    
    // Count frequencies of elements in a and b
    map<int, int> count_a, count_b;
    for (int x : a) count_a[x]++;
    for (int x : b) count_b[x]++;
    
    // Try to reduce count_a to count_b
    while (!count_a.empty()) {
        // Find the smallest element in count_a
        int min_a = count_a.begin()->first;
        
        bool found = false;
        for (auto& [target, cnt] : count_b) {
            if (abs(min_a - target) <= 1) {
                if (count_a[min_a] > 0) {
                    count_a[min_a]--;
                    if (count_a[min_a] == 0) {
                        count_a.erase(min_a);
                    }
                    
                    if (target == min_a) {
                        count_b[target]--;
                        if (count_b[target] == 0) {
                            count_b.erase(target);
                        }
                        found = true;
                        break;
                    } else {
                        // Combine min_a with another element to form target
                        int needed = target - min_a;
                        if (count_a.count(needed) && count_a[needed] > 0) {
                            count_a[needed]--;
                            if (count_a[needed] == 0) {
                                count_a.erase(needed);
                            }
                            
                            count_b[target]--;
                            if (count_b[target] == 0) {
                                count_b.erase(target);
                            }
                            found = true;
                            break;
                        }
                    }
                }
            }
        }
        
        if (!found) {
            return "No";
        }
    }
    
    if (!count_b.empty()) {
        return "No";
    }
    
    return "Yes";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int t;
    cin >> t;
    while (t--) {
        int n, m;
        cin >> n >> m;
        
        vector<int> a(n), b(m);
        for (int i = 0; i < n; ++i) cin >> a[i];
        for (int i = 0; i < m; ++i) cin >> b[i];
        
        cout << canTransform(a, b) << '\n';
    }
    
    return 0;
}