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());

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

        priority_queue<ll> pq;
        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;
        }
    }
      if(!a.empty()){
         cout << "No\n";
            return;
    }
    cout << "Yes\n";
}

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

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();
    }
}