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

Previous submission (verdict: Memory limit exceeded on test 27):
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define lll _int128_t
#define vi vector<int>
#define vvi vector<vector<int>>
#define pb push_back
#define nl '\n'
template< typename typC> istream &operator>>(istream &cin,vector<typC> &a) {for (auto &x:a)cin>>x; return cin;}
template< typename typC> ostream &operator<<(ostream &cout,vector<typC> &a) {for (auto it:a)cout<<it<<" "; return cout;}
#define loop1(n) for(int i=0;i<n;i++)
#define loop2(a,b,i) for(int i=a;i<b;i++)
#define fast 	ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
void solve() {
    int n, m;
    cin >> n >> m;
    
    multiset<ll> a;
    vector<ll> b(m);

    ll sumA = 0;
    for (int i = 0; i < n; i++) {
        ll x;
        cin >> x;
        a.insert(x);
        sumA += x;
    }

    for (int i = 0; i < m; i++) {
        cin >> b[i];
    }

    sort(b.rbegin(), b.rend());

    priority_queue<ll> pq;
    for (ll bi : b) {
        if (bi > sumA) { 
            cout << "No\n"; 
            return;
        }

        pq.push(bi);
        bool possible = true;

        while (!pq.empty() && !a.empty()) {
            ll num = pq.top();
            pq.pop();

            auto it = a.find(num);
            if (it != a.end()) {
                a.erase(it); 
                sumA -= num;
                continue;
            }

            if (num == 1 || num < *a.begin()) { 
                possible = false;
                break;
            }
            ll left = num / 2;
            ll right = num - left;

            pq.push(left);
            pq.push(right);
        }

        if (!possible) {
            cout << "No\n";
            return;
        }
        pq = priority_queue <ll>();
    }
      if(!a.empty()){
         cout << "No\n";
            return;
    }
    cout << "Yes\n";
}

int main(){
    fast;
    int t=1;
    cin>>t;
    while (t--){
        solve();
    }
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define lll _int128_t
#define vi vector<int>
#define vvi vector<vector<int>>
#define pb push_back
#define nl '\n'
template< typename typC> istream &operator>>(istream &cin,vector<typC> &a) {for (auto &x:a)cin>>x; return cin;}
template< typename typC> ostream &operator<<(ostream &cout,vector<typC> &a) {for (auto it:a)cout<<it<<" "; return cout;}
#define loop1(n) for(int i=0;i<n;i++)
#define loop2(a,b,i) for(int i=a;i<b;i++)
#define fast 	ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
void solve() {
    int n, m;
    cin >> n >> m;
    vector<ll> a(n), b(m);
    cin >> a >> b;
    priority_queue<ll> maxA, maxB;
    for(int i=0;i<n;i++){
        maxA.push(a[i]);
    }
     for(int i=0;i<m;i++){
        maxB.push(b[i]);
    }
    int rem = n - m;  
    while (rem >= 0) {
        while (!maxA.empty() && !maxB.empty() && maxA.top() == maxB.top()) {
            maxA.pop();
            maxB.pop();
        }
        if (maxA.empty() && maxB.empty()) {
            cout << "Yes\n";
            return;
        }
        if (maxA.empty() || maxB.empty()) {
            cout << "No\n";
            return;
        }
        int num = maxB.top();
        maxB.pop();
        maxB.push(num / 2);
        maxB.push(num - num/2);
        rem--;
    }
    cout << "No\n";
}
int main() {
    fast;
    int t = 1;
    cin >> t;
    while (t--) {
        solve();
    }
}