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

Previous submission (verdict: Runtime error on test 2):
#include <bits/stdc++.h>
using namespace std;

#define int long long
    signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL); 

int t;
cin>>t;
while(t--){
    int n,m;
    cin>>n>>m;
   
    map<int,int> mp1,mp2;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        mp1[x]++;
    }
    for(int i=0;i<m;i++){
        int x;
        cin>>x;
        mp2[x]++;
       
    }
   
    bool ans=true;
    auto it=mp2.end();
    
    int count=n-m;
    while(count){
        it=mp2.end();
        it--;
        if(mp2.empty()){
            break;
        }
        int val=it->first;
        if(val==1||mp2.empty()){
            break;
        }
        if(mp1.find(val)==mp1.end()){
            count--;
            int fr=it->second;
            mp2.erase(it);
            if(val%2){
                
              mp2[val/2]+=fr;
              mp2[(val+1)/2]+=fr;
            }
            else{
                mp2[val/2]+=2*fr;
            }
        }
        else{
            if(mp1[val]==mp2[val]){
                mp1.erase(val);
                mp2.erase(val);
            }
            else if(mp1[val]>mp2[val]){
                mp1[val]-=mp2[val];
                mp2.erase(val);
            }
            else{
                mp2[val]-=mp1[val];
                mp1.erase(val);
            }
        }
        // cout<<mp1.size()<<" "<<mp2.size()<<endl;
      
    }
      if(mp1==mp2){
            cout<<"Yes"<<endl;
        }
        else{
            cout<<"No"<<endl;
        }
   

}
}

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

#define int long long
    signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL); 

int t;
cin>>t;
while(t--){
    int n,m;
    cin>>n>>m;
   
    map<int,int> mp1,mp2;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        mp1[x]++;
    }
    for(int i=0;i<m;i++){
        int x;
        cin>>x;
        mp2[x]++;
       
    }
   
    bool ans=true;
    auto it=mp2.end();
    
    int count=n-m;
    while(count){
        it=mp2.end();
        if(mp2.empty()){
            break;
        }
        it--;
        
        int val=it->first;
        if(val==1||mp2.empty()){
            break;
        }
        if(mp1.find(val)==mp1.end()){
            count--;
            
            int fr=mp2[val];
            
            if(val%2){
                
              mp2[val/2]+=fr;
              mp2[(val+1)/2]+=fr;
            }
            else{
                
                fr=fr+fr;
                
                val/=2;
            //    cout<<val<<endl;
            //     cout<<fr<<endl;
                mp2[val]+=fr;
            }
            mp2.erase(it);
        }
        else{
            if(mp1[val]==mp2[val]){
                mp1.erase(val);
                mp2.erase(val);
            }
            else if(mp1[val]>mp2[val]){
                mp1[val]-=mp2[val];
                mp2.erase(val);
            }
            else{
                mp2[val]-=mp1[val];
                mp1.erase(val);
            }
        }
        
      
    }
    //  cout<<mp1.size()<<" "<<mp2.size()<<endl;
      if(mp1==mp2){
            cout<<"Yes"<<endl;
        }
        else{
            cout<<"No"<<endl;
        }
   

}
}