Problem: 2061D - Kevin and Numbers
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define B7AIRY                    \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define YES return void(cout << "YES\n")
#define NO return void(cout << "NO\n")
#define RN1 return void(cout << "-1\n")
#define ld long double
#define ll long long
#define PI acos(-1) a
#define endl "\n"
#define int ll
const ll N = 1e6 + 10, mod = 1e9 + 7;
const int dx[] = { 1, -1, 0, 0, 1, -1, 1, -1 };
const int dy[] = { 0, 0, 1, -1, 1, 1, -1, -1 };
class DSU {
private:
    vector<int> Parent;
    vector<int> GroupSize;
    vector<int> Max;
    int Components;
public:
    DSU(int n) {
        Parent = vector<int>(n + 1);
        iota(Parent.begin(), Parent.end(), 0);
        Parent.push_back(0);
        Components = n;
        GroupSize = vector<int>(n + 1, 1);
    }
    int FindParent(int node) {
        if (Parent[node] == node) return node;
        return Parent[node] = FindParent(Parent[node]);
    }
    int GetGroupSize(int node) {
        return GroupSize[FindParent(node)];
    }
    void Merge(int u, int v) {
        u = FindParent(u);
        v = FindParent(v);
        if (u == v) return;
        if (GroupSize[u] < GroupSize[v]) swap(u, v);
        Parent[v] = u;
        GroupSize[u] += GroupSize[v];
        Components--;
    }

    int GetGroupCount() {
        return Components;
    }
    bool IsSameGroup(int u, int v) {
        return FindParent(u) == FindParent(v);
    }
};
void solution() {
    int n, m; cin >> n >> m;
    multiset<int>mst1, mst2;
    for (int i = 0; i < n; i++) {
        int x; cin >> x;
        mst1.insert(x);
    }
    for (int i = 0; i < m; i++) {
        int x; cin >> x;
        mst2.insert(x);
    }
    vector<int>tt;
    for (auto i : mst2) {
        auto it = (mst1.find(i));
        if (it != mst1.end())tt.push_back(*it), mst1.erase(it);
    }
    for (auto t : tt)mst2.erase(mst2.find(t));
    m += 10;
    while (mst1.size() && mst2.size() && m--) {

        while (mst1.size() && mst2.size() && *mst1.begin() == *mst2.begin()) {
            mst1.erase(mst1.begin());
            mst2.erase(mst2.begin());
        }
        if (!mst2.size())YES;
        int mx = *mst2.rbegin();
        //  cout << mx << endl;
        if (mst1.find(mx / 2) != mst1.end()) {
            mst1.erase(mst1.find(mx / 2));
        }
        else mst2.insert((mx) / 2);
        if (mst1.find((mx + 1) / 2) != mst1.end()) {
            mst1.erase(mst1.find((mx + 1) / 2));
        }
        else mst2.insert((mx + 1) / 2);
        mst2.erase(mst2.find(mx));
    }
    if (mst1 == mst2)YES;
    else NO;
}
signed main()
{
    B7AIRY
#ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int t = 1;
    cin >> t;
    for (int i = 1; i <= t; i++)
    {

        // cout< "Case #" << i << ": ";
        solution();
    }
}

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

bool canTransform(int n, int m, vector<int>& a, vector<int>& b) {
    if (m > n) return false; // Cannot reduce sequence length
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    
    // Frequency map for a
    map<int, int> freq;
    for (int num : a) freq[num]++;
    
    for (int num : b) {
        bool found = false;
        // Try to find a combination of numbers in a that can sum to num
        for (auto it = freq.begin(); it != freq.end(); ++it) {
            int x = it->first;
            if (freq[x] == 0) continue;
            // Check if x can be combined with x or x+1 to form num
            if (x == num && freq[x] >= 1) {
                freq[x]--;
                found = true;
                break;
            }
            if (x + 1 == num && freq[x] >= 1 && freq[x + 1] >= 1) {
                freq[x]--;
                freq[x + 1]--;
                found = true;
                break;
            }
        }
        if (!found) 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;
}