Problem: 2061D - Kevin and Numbers
Language: C++23 (GCC 14-64, msys2)

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

#define int long long
#define aa(z) int z; cin >> z
#define vi vector<int>
#define f(i, n) for (int i = 0; i < n; i++)
#define pb push_back
#define in(arr, n) for (int i = 0; i < n; i++) cin >> arr[i]
#define out(arr, n) for (int i = 0; i < n; i++) cout << arr[i] << " "; cout << endl
#define srt(v) sort(v.begin(), v.end())
#define srtr(v) sort(v.begin(), v.end(), greater<int>())
#define err cout << fixed << setprecision(10)
#define lb(arr, d) lower_bound(arr, arr + n, d) - arr
const int mod = 998244353;

void mohammaad_rafi() {
    aa(n);
    aa(m);
    vi a(n), b(m);
    in(a, n);
    in(b, m);

    map<int, int> mp;
    srt(a);
    srt(b);

    // Populate the map with elements of `a`
    for (int x : a) {
        mp[x]++;
    }
int i=0;
    while (i<m) {
if(mp[b[i]]>=1){
    mp[b[i]]--;
    if(mp[b[i]]==0){
        mp.erase(b[i]);
    }
    i++;
}


else if(b[i]%2==0&&mp[b[i]/2]>=2){
    mp[b[i]/2]-=2;
    if(mp[b[i]/2]==0){
        mp.erase(b[i]/2);
    }
    i++;
}
else if(b[i]%2!=0&&mp[b[i]/2]>=1&&mp[b[i]/2+1]>=1){
    mp[b[i]/2]-=1;
    mp[b[i]/2+1]-=1;
     if(mp[b[i]/2]==0){
        mp.erase(b[i]/2);
    }
    
     if(mp[b[i]/2+1]==0){
        mp.erase(b[i]/2+1);
    }
    i++;
}
else{

auto it=mp.begin();
while(it->first<b[i]){
int key=it->first;
if(mp[key+1]>1){
    mp[key]--;
    mp[key+1]--;
    mp[key+key+1]++;
}

if(mp[key]==0){
    mp.erase(key);
}
if(mp[key+1]==0){
    mp.erase(key);
}


it=mp.begin();
}

 it=mp.begin();
 if(mp.size()==0||it->first!=b[i]){
    cout<<"No"<<endl; return;
 }
}



    
    }
    if(mp.size()!=0){
        cout<<"No"<<endl;
        return;
    }

    cout << "Yes" << endl;
}

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

    aa(t); // Number of test cases
    while (t--) {
        mohammaad_rafi();
    }
    return 0;
}


Submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define aa(z) int z; cin >> z
#define vi vector<int>
#define f(i, n) for (int i = 0; i < n; i++)
#define pb push_back
#define in(arr, n) for (int i = 0; i < n; i++) cin >> arr[i]
#define out(arr, n) for (int i = 0; i < n; i++) cout << arr[i] << " "; cout << endl
#define srt(v) sort(v.begin(), v.end())
#define srtr(v) sort(v.begin(), v.end(), greater<int>())
#define err cout << fixed << setprecision(10)
#define lb(arr, d) lower_bound(arr, arr + n, d) - arr
const int mod = 998244353;

void mohammaad_rafi() {
    aa(n);
    aa(m);
    vi a(n), b(m);
    in(a, n);
    in(b, m);

    map<int, int> mp;
    srt(a);
    srt(b);

    // Populate the map with elements of `a`
    for (int x : a) {
        mp[x]++;
    }

    int i = 0;
    while (i < m) {
        if (mp.find(b[i]) != mp.end() && mp[b[i]] >= 1) {
            // Exact match found
            mp[b[i]]--;
            if (mp[b[i]] == 0) {
                mp.erase(b[i]);
            }
            i++;
        } else if (mp.find(b[i] / 2) != mp.end() && b[i] % 2 == 0 && mp[b[i] / 2] >= 2) {
            // Combine two smaller elements to form `b[i]` (even case)
            mp[b[i] / 2] -= 2;
            if (mp[b[i] / 2] == 0) {
                mp.erase(b[i] / 2);
            }
            i++;
        } else if (mp.find(b[i] / 2) != mp.end() && mp.find(b[i] / 2 + 1) != mp.end() &&
                   b[i] % 2 != 0 && mp[b[i] / 2] >= 1 && mp[b[i] / 2 + 1] >= 1) {
            // Combine two smaller elements to form `b[i]` (odd case)
            mp[b[i] / 2]--;
            mp[b[i] / 2 + 1]--;
            if (mp[b[i] / 2] == 0) {
                mp.erase(b[i] / 2);
            }
            if (mp[b[i] / 2 + 1] == 0) {
                mp.erase(b[i] / 2 + 1);
            }
            i++;
        } else {
            // Try to create `b[i]` by combining smaller elements
            auto it = mp.begin();
            while (!mp.empty() && it->first < b[i]) {
                int key = it->first;
                if (mp.find(key ) != mp.end() && mp[key ] >= 2) {
                    // Combine `key` and `key + 1` to form `key + key + 1`
                    mp[key]--;
                    mp[key ]--;
                     mp[key + key]++;
                    if (mp[key] == 0) {
                        mp.erase(key);
                    }
                    // if (mp[key ] == 0) {
                    //     mp.erase(key 1);
                    // }

                    // Add the combined element
                    
                }

               else if (mp.find(key + 1) != mp.end() && mp[key + 1] >= 1) {
                    // Combine `key` and `key + 1` to form `key + key + 1`
                    mp[key]--;
                    mp[key + 1]--;
                    if (mp[key] == 0) {
                        mp.erase(key);
                    }
                    if (mp[key + 1] == 0) {
                        mp.erase(key + 1);
                    }

                    // Add the combined element
                    mp[key + key + 1]++;
                } else {
                    // No valid combination can be made
                    break;
                }

                // Update iterator after potential erasures
                it = mp.begin();
            }

            // After trying, check if `b[i]` can be satisfied
            it = mp.begin();
            if (mp.empty() || it->first != b[i]) {
                cout << "NO" << endl;
                return;
            }
        }
    }
    if(mp.size()!=0){
        cout<<"No"<<endl;return;
    }

    cout << "YES" << endl;
}

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

    aa(t); // Number of test cases
    while (t--) {
        mohammaad_rafi();
    }
    return 0;
}