Problem: 2061D - Kevin and Numbers
Language: c++17 

Solution 1 (runtime: 765 ms):
#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--)
	{
	    int n,m;
	    cin>>n>>m;
	    vector<int> a,b;
	    int y;
	    for(int i=0;i<n;i++)
	    {
	        cin>>y;
	        a.push_back(y);
	    }
	    for(int i=0;i<m;i++)
	    {
	        cin>>y;
	        b.push_back(y);
	    }
	    if(m>n)
	    {
	        cout<<"NO"<<endl;
	    }
	    else
	    {

	        map<int,int> m1;
	        for(int i=0;i<n;i++)
	        {
	            m1[a[i]]++;
	        }
	        int x,count=m,j=0;
	        while(count<=n && j<b.size())
	        {
	            x=b[j];
                //cout<<x<<" ";
	            if(m1[x]>0)
	            {
	                m1[x]--;
	                //cout<<"Present ";
	                j++;
	            }
	            else
	            {
	                //cout<<"lop2 ";
	                if(x%2==0 && x>0)
	                {
	                    b[j]=(x/2);
	                    b.push_back((x/2));
	                    count++;
	                }
	                else if(x>1)
	                {
	                    //cout<<"Yes ";
	                    b[j]=(x/2);
	                    b.push_back(((x+1)/2));
	                    count++;
	                }
	                else
	                {
	                    break;
	                }
	            }
	        }
	        if(j==b.size() && count==n)
	        {
	            cout<<"YES"<<endl;
	        }
	        else
	        {
	            cout<<"NO"<<endl;
	        }
	    }
	}

}


Solution 2 (runtime: 749 ms):
#include <iostream>
#include <map>
#include <cstdio>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <vector>
#include <cmath>
#include <set>
#include <stack>

using namespace std;

const int N=2e5+10, mod=1e9+7,M=7*1e6;
#define pb push_back
#define fi first
#define se second
typedef long long LL;
typedef pair<LL,LL> PLL;
typedef pair<int,int> PII;



int n,m,a[N],b[N];
LL sa,sb;

bool sol(){
    if(sa!=sb || n<m)return 0;
    //sort(a,a+n);
    sort(b,b+m);
    map<int,int>mp;
    for(int i=0;i<n;i++)mp[a[i]]++;
    for(int i=0;i<m;i++){
        int tcnt=0,tcur=0,jcnt=0,jcur=0;
        if(b[i]%2==0){
            tcnt=1;
            tcur=b[i];
        }
        else{
            jcnt=1;
            jcur=b[i];
        }
        bool flag=0;
        
        while(1){
            //cout<<tcnt<<" "<<tcur<<" "<<jcnt<<" "<<jcur<<endl;
            
            //抵消ou
            if(tcnt){
                if(mp[tcur]>=tcnt){
                mp[tcur]-=tcnt;
                tcnt=0;
                }
                else{
                    tcnt-=mp[tcur];
                    mp[tcur]=0;
                }
            }
            
            
            //抵消ji
            if(jcnt){
                if(mp[jcur]>=jcnt){
                    mp[jcur]-=jcnt;
                    jcnt=0;
                }
                else{
                    jcnt-=mp[jcur];
                    mp[jcur]=0;
                }
            }
            
            
            //如果剩下1就失败
            if(jcur==1&&jcnt){
                flag=0;
                break;
            }
            
            if(jcnt+tcnt==0){
                flag=1;
                break;
            }
            
            //变化
            int xx=tcur/2,yy=jcur/2,zz=jcur/2+1;
            int tmpji=0,tmpou=0;
            
            
            
            //cnt
            if(tcnt){
                if(xx%2==0){
                    tmpou+=tcnt*2;
                }
                else {
                    tmpji+=tcnt*2;
                }
            }
            if(jcnt){
                tmpou+=jcnt;
                tmpji+=jcnt;
            }
            
            //cur
            if(tcnt){
                if(xx%2==0)tcur=xx;
                else jcur=xx;
            }
            if(jcnt){
                if(yy%2==0){
                    tcur=yy;
                    jcur=yy+1;
                }
                else{
                    tcur=yy+1;
                    jcur=yy;
                }
            }
            
            tcnt=tmpou;
            jcnt=tmpji;
            
        }
        if(!flag)return 0;
        
    }
    return 1;
}

int main(){
    int t;
    cin>>t;
    while(t--){
        sa=0;
        sb=0;
        cin>>n>>m;
        for(int i=0;i<n;i++)cin>>a[i];
        for(int i=0;i<m;i++)cin>>b[i];
        for(int i=0;i<n;i++)sa+=a[i];
        for(int i=0;i<m;i++)sb+=b[i];
        if(sol())cout<<"yes\n";
        else cout<<"no\n";
    }
    
    return 0;
}


//10 8 3 2 9
//10 2 9 4 9
//10 2 4 9 10
//2 4 9 10 11