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

Solution 1 (runtime: 389 ms):
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <stack>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <array>
#include <climits>
#include <algorithm>
#include <functional>
using namespace std;
#define ll long long
#define floop(i, a, b) for (int i = (a); i < (b); i++)
#define vi vector<int>
#define vvi vector<vector<int>>
#define vpii vector<pair<int, int>>
#define pii pair<int, int>
#define all(x) (x).begin(), (x).end()
const ll inf = 1e16;
const int mod = 1e9 + 7;
const int N = 1e6;
ll i = 0, j = 0;
ll n, m;

bool solve(priority_queue<ll> &bb, map<ll, ll> &a)
{
     for (int i = 0; i < (2 * n - m); i++)
     {
          if (bb.empty())
          {
               return false;
          }
          ll num = bb.top();
          bb.pop();

          if (a[num] == 0)
          {
               bb.push(num / 2);
               bb.push((num + 1) / 2);
          }
          else
          {
               a[num]--;
          }
     }
     if (bb.empty())
          return true;
     return false;
}
void ExoticLur3e37()
{
     ll p;
     cin >> n >> m;
     map<ll, ll> a;
     for (i = 0; i < n; i++)
     {
          cin >> p;
          a[p]++;
     }
     vector<ll> b(m);
     // vector<ll> vis(m, 0);
     priority_queue<ll> bb;
     for (i = 0; i < m; i++){
          cin >> b[i];
          bb.push(b[i]);
     }

     // for (int i = 0; i < m; i++)
     // {
     //      int num = b[i];
     //      if (a[num] > 0)
     //      {
     //           a[num]--;
     //           if (a[num] == 0)
     //                a.erase(num);
     //           vis[i] = 1;
     //      }
     // }

     // for (int i = 0; i < m; i++)
     // {
     //      if (!vis[i])
     //           bb.push(b[i]);
     // }

     bool res = solve(bb, a);
     
     res?cout<<"YES":cout<<"NO";
}
int main()
{
     ios_base::sync_with_stdio(0);
     cin.tie(0);
     cout.tie(0);
     ll t;
     cin >> t;
     // t = 1;
     while (t--)
     {
          ExoticLur3e37();
          cout << "\n";
     }
}

Solution 2 (runtime: 327 ms):
#include<bits/stdc++.h>

#define ll long long int

#define pb push_back



using namespace std;



const int MAXN = 2e5 + 10;



int main(){

		

	ll t;

	scanf("%lld", &t);



	while(t--){

		ll n, m, x;

		scanf("%lld %lld", &n, &m);



		multiset<ll> a;

		vector<ll> b;

		ll suma_a = 0;

		ll suma_b = 0;



		for(ll i = 0; i < n; i++){

			scanf("%lld", &x);

			suma_a += x;

			a.insert(x);

		}



		for(ll i = 0; i < m; i++){

			scanf("%lld", &x);

			suma_b += x;

			b.pb(x);

		}



		if(suma_a != suma_b){

			printf("No\n");

		}

		else{

			ll k = 0;

			while(b.size() > 0 && k <= n + 2){

				k++; 

				if(a.find(b[b.size() - 1]) != a.end()){

					a.erase(a.find(b[b.size() - 1]));

					b.pop_back();

				}

				else{

					ll x1 = b[b.size() - 1]/2;

					ll x2 = b[b.size() - 1]/2;

					if(b[b.size() - 1] % 2 == 1){

						x2++;

					}

					b.pop_back();

					if(a.find(x1) != a.end()){

						a.erase(a.find(x1));

					}

					else{

						b.push_back(x1);

					}

					if(a.find(x2) != a.end()){

						a.erase(a.find(x2));

					}

					else{

						b.push_back(x2);

					}

				}

			}

			if(b.size() == 0){

				printf("Yes\n");

			}

			else{

				printf("No\n");

			}

		}

	}	

	

	return 0;

}