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

Previous submission (verdict: Memory limit exceeded on test 6):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pii;

typedef vector <ll> vi;
typedef vector <vector <ll>> vvi;

const ll mxn = 1e6 + 5;
const ll mod = 1e9 + 7;

void fast(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
}


void solve(){

    ll n,m;
    cin>>n>>m;
    ll a[n];
    ll b[m];
    ll sum1=0;
    ll sum2=0;

    map<ll,ll> mp;
    for(ll i=0;i<n;i++){
        cin>>a[i];
        sum1+=a[i];
        mp[a[i]]++;
    }
    priority_queue<ll> p;
    for(ll i=0;i<m;i++){
        cin>>b[i];
        sum2+=b[i];
        p.push(b[i]);
    }
    if(sum1!=sum2){
        cout<<"No"<<endl;
        return;
    }
    while(!p.empty()||!mp.empty()){

        


        ll x=p.top();
        if(x==1){
            int zz=p.size();
            if(zz>mp[1]||zz<mp[1]){
                break;
            }
        }
        //cout<<x<<endl;
        p.pop();
        if(mp.count(x)!=0){
            mp[x]--;
            if(mp[x]==0) mp.erase(x);
           
            continue;
        }
        if(x==1){
            break;
        }
        // p.pop();
        //cout<<x<<endl;
        if(x%2==0){
            p.push(x/2);
            //cout<<"even pushing "<<endl;
            p.push(x/2);
        }
        else{
            ll kk=x/2+1;
            p.push(x/2);
            p.push(kk);
            //cout<<"odd pushing"<<endl;
        }
    }
    if(p.size()>0){
        cout<<"No"<<endl;
    }
    else cout<<"Yes"<<endl;

    // if(z==kk){
    //     cout<<"Yes"<<endl;
    // }
    // else cout<<"No"<<endl;
    

    





}
int main(){

    fast();
    ll t;
    cin >> t;

    while(t--){
        solve();
    }

    return 0;
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pii;

typedef vector <ll> vi;
typedef vector <vector <ll>> vvi;

const ll mxn = 1e6 + 5;
const ll mod = 1e9 + 7;

void fast(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
}


void solve(){

    ll n,m;
    cin>>n>>m;
    ll a[n];
    ll b[m];
    ll sum1=0;
    ll sum2=0;

    map<ll,ll> mp;
    for(ll i=0;i<n;i++){
        cin>>a[i];
        sum1+=a[i];
        mp[a[i]]++;
    }
    priority_queue<ll> p;
    for(ll i=0;i<m;i++){
        cin>>b[i];
        sum2+=b[i];
        p.push(b[i]);
    }
    if(sum1!=sum2){
        cout<<"No"<<endl;
        return;
    }
    int cnt=0;
    while(!p.empty()||!mp.empty()){

        if(cnt>n) break;
        ll x=p.top();
        //cout<<x<<endl;
        p.pop();
        if(mp.count(x)!=0){
            mp[x]--;
            if(mp[x]==0) mp.erase(x);
           
            continue;
        }
        if(x==1){
            break;
        }
        // p.pop();
        //cout<<x<<endl;
        if(x%2==0){
            p.push(x/2);
            //cout<<"even pushing "<<endl;
            p.push(x/2);
            cnt+=1;
        }
        else{
            ll kk=x/2+1;
            p.push(x/2);
            p.push(kk);
            cnt+=1;
            //cout<<"odd pushig"<<endl;
        }
    }
    if(p.size()>0){
        cout<<"No"<<endl;
    }
    else cout<<"Yes"<<endl;

    // if(z==kk){
    //     cout<<"Yes"<<endl;
    // }
    // else cout<<"No"<<endl;
    

    





}
int main(){

    fast();
    ll t;
    cin >> t;

    while(t--){
        solve();
    }

    return 0;
}