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

Solution 1 (runtime: 202 ms):
#include <bits/stdc++.h>
using namespace std;

bool canTransform(int n, int m, vector<int>& a, vector<int>& b) {
    // Check if the sum of a is equal to the sum of b
    long long sumA = accumulate(a.begin(), a.end(), 0LL);
    long long sumB = accumulate(b.begin(), b.end(), 0LL);
    if (sumA != sumB) return false;

    // Frequency maps for a and b
    map<int, int> freqA, freqB;
    for (int num : a) freqA[num]++;
    for (int num : b) freqB[num]++;

    // Try to match frequencies
    for (auto& [num, cnt] : freqB) {
        while (cnt > 0) {
            if (freqA[num] >= cnt) {
                freqA[num] -= cnt;
                cnt = 0;
            } else {
                cnt -= freqA[num];
                freqA[num] = 0;
                // Try to merge smaller numbers to form the current number
                if (freqA[num - 1] > 0 && freqA[num] == 0) {
                    int mergeCount = min(cnt, freqA[num - 1]);
                    freqA[num - 1] -= mergeCount;
                    cnt -= mergeCount;
                } else if (freqA[num + 1] > 0 && freqA[num] == 0) {
                    int mergeCount = min(cnt, freqA[num + 1]);
                    freqA[num + 1] -= mergeCount;
                    cnt -= mergeCount;
                } else {
                    return false;
                }
            }
        }
    }

    return true;
}

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];

        if (canTransform(n, m, a, b)) {
            cout << "Yes\n";
        } else {
            cout << "No\n";
        }
    }

    return 0;
}

Solution 2 (runtime: 390 ms):
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;

void solve()
{
    int n, m, x, y, main_counter = 0;
    cin >> n >> m;
    map<int, int> nums;
    vector<int> gather;
    for (int i = 0; i < n; ++i)
    {
        cin >> x;
        ++nums[x];
    }

    for (int i = 0; i < m; ++i)
    {
        cin >> y;
        gather.push_back(y);
    }

    for (auto y : gather)
    {
        int nechet = (y / 2) * 2 + 1, count1 = y % 2;
        int chet = (y / 2) * 2, count2 = y % 2 == 0;

        while (y)
        {
            int x1 = min(nums[nechet], count1);
            int x2 = min(nums[chet], count2);
            count1 -= x1;
            count2 -= x2;
            nums[nechet] -= x1;
            nums[chet] -= x2;
            main_counter += x1 + x2;

            if (count1 == 0 and count2 == 0)
            {
                break;
            }

            int nwc1 = count1;
            int nwc2 = count1;
            switch ((chet / 2) % 2)
            {
            case 1:
                nwc1 += 2 * count2;
                break;
            case 0:
                nwc2 += 2 * count2;
            }
            nechet = nechet / 2;
            chet = nechet + 1;
            if (chet % 2)
                swap(nechet, chet);
            count1 = nwc1;
            count2 = nwc2;
            y /= 2;
            //cout << nechet << " : " << count1 << "   " << chet << " ! " << count2 << endl;
        }
        int x1 = min(nums[1], count1);
        count1 -= x1;
        nums[nechet] -= x1;
        main_counter += x1;

        if (count1 or count2)
        {
            cout << "no" << endl;
            return;
        }
    }
    if (main_counter == n)
        cout << "yes" << endl;
    else
        cout << "no" << endl;
}

int main()
{
    cin.tie(0)->sync_with_stdio(0);
    int t;
    cin >> t;
    while (t--)
        solve();
    return 0;
}