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

Previous submission (verdict: Time limit exceeded on test 5):
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

bool can_transform(int n, int m, vector<ll> &a, vector<ll> &b) {
    ll sum_a = 0, sum_b = 0;
    for(auto &x : a) sum_a += x;
    for(auto &x : b) sum_b += x;
    if(sum_a != sum_b) return false;
    // Sort a in descending order
    sort(a.begin(), a.end(), greater<ll>());
    // Sort b in descending order
    sort(b.begin(), b.end(), greater<ll>());
    // Initialize priority queue with b's elements
    priority_queue<ll> pq;
    for(auto &x : b) pq.push(x);
    // Pointer for a's elements
    int a_ptr = 0;
    while(!pq.empty()) {
        ll y = pq.top(); pq.pop();
        if(a_ptr < n && a[a_ptr] == y) {
            a_ptr++;
        }
        else {
            if(y < 2) {
                return false;
            }
            // Split y into two parts
            ll x, y_x;
            if(y % 2 == 0) {
                x = y / 2;
                y_x = y / 2;
            }
            else {
                x = y / 2;
                y_x = y - x;
            }
            if(abs(x - y_x) > 1) {
                return false;
            }
            pq.push(x);
            pq.push(y_x);
        }
    }
    if(a_ptr == n) return true;
    else return false;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while(t--){
        int n, m;
        cin >> n >> m;
        vector<ll> a(n);
        for(auto &x : a) cin >> x;
        vector<ll> b(m);
        for(auto &x : b) cin >> x;
        bool res = can_transform(n, m, a, b);
        if(res) cout << "Yes\n";
        else cout << "No\n";
    }
}


Submission (verdict: Time limit exceeded on test 5):
#include <bits/stdc++.h>
using namespace std;

// Function to determine if transformation is possible
bool can_transform(int n, int m, vector<int> &a, vector<int> &b) {
    long long sum_a = 0, sum_b = 0;
    for(auto &x : a) sum_a += x;
    for(auto &x : b) sum_b += x;
    
    // Check if the sums are equal
    if(sum_a != sum_b) return false;
    
    // Sort 'a' and 'b' in descending order
    sort(a.begin(), a.end(), greater<int>());
    sort(b.begin(), b.end(), greater<int>());
    
    // Initialize a max heap (priority queue) with elements of 'b'
    priority_queue<int> pq;
    for(auto &x : b) pq.push(x);
    
    // Pointer for elements in 'a'
    int a_ptr = 0;
    
    // Process the priority queue
    while(!pq.empty()) {
        int y = pq.top(); 
        pq.pop();
        
        // If the current element in 'a' matches 'y', assign it
        if(a_ptr < n && a[a_ptr] == y) {
            a_ptr++;
            continue;
        }
        
        // If 'y' is less than 2, it cannot be split further
        if(y < 2) {
            return false;
        }
        
        // Split 'y' into two parts x and y_x such that |x - y_x| <= 1
        int x = y / 2;
        int y_x = y - x;
        
        // Validate the split condition
        if(abs(x - y_x) > 1) {
            return false;
        }
        
        // Push the split parts back into the priority queue
        pq.push(x);
        pq.push(y_x);
    }
    
    // After processing, all elements in 'a' should have been assigned
    return a_ptr == n;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int t;
    cin >> t;
    
    while(t--){
        int n, m;
        cin >> n >> m;
        
        vector<int> a(n);
        for(auto &x : a) cin >> x;
        
        vector<int> b(m);
        for(auto &x : b) cin >> x;
        
        bool res = can_transform(n, m, a, b);
        cout << (res ? "Yes" : "No") << "\n";
    }
}