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

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

using namespace std;
typedef vector<int> vi;
typedef map<int, int> mi;
typedef set<int, greater<int>> si;
int n, m;
int newn, newm;
mi amap, bmap;
vi a, b;
si sa, sb;

void solve() {
  cin >> n >> m;
  a.assign(n, 0); b.assign(m, 0);
  amap.clear(), bmap.clear();
  sa.clear(), sb.clear();
  for (int i = 0; i < n; ++i) { cin >> a[i]; ++amap[a[i]]; sa.insert(a[i]); }
  for (int i = 0; i < m; ++i) { cin >> b[i]; ++bmap[b[i]]; sb.insert(b[i]); }

  sort(b.begin(), b.end(), greater<int>());
  int count = n - m;
  for (int i = 0; i < count; ++i) {
    //cout << i << ", " << b[j] << ":" << bmap[b[j]] << " " << amap[b[j]] << endl;
    if (sb.empty()) break;
    int bval = *sb.begin();
    if (bval == 1) break;
    if (bmap[bval] != amap[bval]) {
      ++bmap[floor(bval/2.0f)];
      ++bmap[ceil(bval/2.0f)];
      --bmap[bval];
      if (bmap[bval] == 0) sb.erase(sb.begin());
      sb.insert(ceil(bval/2.0f));
      sb.insert(floor(bval/2.0f));
      //for (auto s : sb) { cout << s << " " ; }
      //cout << endl;
    } else { sb.erase(sb.begin()); --i; }
  }

  int ans = 1;
  for (const auto &[key, val] : bmap) {
    //cout << key << " " << val << endl;
    if (val != amap[key]) { ans = 0; break; }
  }
  for (const auto &[key, val] : amap) {
    //cout << key << " " << val << endl;
    if (val != bmap[key]) { ans = 0; break; }
  }

  cout << (ans ? "YES" : "NO") << endl;
}

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


Solution 2 (runtime: 311 ms):
#pragma GCC optimize("Ofast")

#pragma GCC optimize("unroll-loops")



#include <iostream>

#include <string>

#include <vector>

#include <algorithm>

#include <sstream>

#include <queue>

#include <deque>

#include <bitset>

#include <iterator>

#include <list>

#include <stack>

#include <utility>

#include <map>

#include <set>

#include <numeric>

#include <cmath>

#include <cstring>



using namespace std;



typedef long long ll;

typedef vector<int> vi;

typedef vector<ll> vll;

typedef pair<int, int> pii;

typedef pair<ll, ll> pll;

typedef multiset<int> msi;



#define loop(i, l, n) for (decltype(n) i = l; i < n; i++)

#define rloop(i, l, n) for (decltype(n) i = l; i >= n; i--)

#define pb push_back

#define YES cout << "YES\n"

#define NO cout << "NO\n"

#define all(v) v.begin(), v.end()

int maxm;

int f(int x, multiset<int>& ms, int maxi) {

    

    if (maxi < 0 || x<maxm) return -1;

    if(ms.find(x) != ms.end())

    {

        ms.erase(ms.find(x));

        return 1;

    }

    int a, b;

    if (x % 2 == 0) {

        a = b = x / 2;

    } else {

        a = x / 2;

        b = x / 2 + 1;

    }



    int flag = 0;



    // Try to use a

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

        ms.erase(ms.find(a));

        flag++;

    } else {

        if (f(a, ms, maxi - 1) != -1) flag++;

    }



    // Try to use b

    if (ms.find(b) != ms.end()) {

        ms.erase(ms.find(b));

        flag++;

    } else {

        if (f(b, ms, maxi - 1) != -1) flag++;

    }



    return (flag == 2) ? 1 : -1;

}



void solve() {

    int n, m;

    cin >> n >> m;

     maxm = INT_MAX;

    ll sum1 = 0;

    ll sum2= 0;

    multiset<int> ms;

    loop(i, 0, n) {

        int x;

        cin >> x;

        maxm = min(x , maxm);

        sum1+= x;

        ms.insert(x);

    }



    vi v2(m);

    loop(i, 0, m) 

    {cin >> v2[i];

     sum2+= v2[i];

    }

    if(sum1 != sum2)

    {

        NO;

        return;

    }



    // sort(all(v2));

    int maxi = n-m;;



    for (int i = m - 1; i >= 0; i--) {

        if (f(v2[i], ms, maxi) == -1) {

            NO;

            return;

        }

    }



    YES;

}



int main() {

    ios::sync_with_stdio(false);

    cin.tie(NULL);



    int t;

    cin >> t;

    while (t--) {

        solve();

    }



    return 0;

}