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

Solution 1 (runtime: 311 ms):
#include <bits/stdc++.h>
#include <algorithm>
#include <limits>
#include <cstring>

using namespace std;

#define Code ios_base::sync_with_stdio(false);
#define By cin.tie(NULL);
#define Het cout.tie(NULL);

#define ll long long
#define int ll
#define ld long double
#define ull unsigned long long
const ld pi = 3.141592653589793238;
const ll INF = LONG_LONG_MAX;
const ll MIN = LONG_LONG_MIN;
const ll mod = 1e9 + 7;

typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef unordered_map<ll, ll> umll;
typedef map<ll, ll> mll;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define vv(T) vector<vector<T>>
#define maxhp(T) priority_queue<T>
#define minhp(T) priority_queue<T, vector<T>, greater<T>>
#define mem(n, i) memset(n, i, sizeof n)
#define p(A, B) pair<A, B>

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return (a / gcd(a, b) * b); }
ll moduloMultiplication(ll a, ll b, ll mod)
{
    ll res = 0;
    a %= mod;
    while (b)
    {
        if (b & 1)
            res = (res + a) % mod;
        b >>= 1;
    }
    return res;
}
ll powermod(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    if (x == 0)
        return 0;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}

bool sorta(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); }
bool sortd(const pair<int, int> &a, const pair<int, int> &b) { return (a.second > b.second); }

bool isPrime(ll n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;
    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;
    return true;
}
bool isPowerOfTwo(int n)
{
    if (n == 0)
        return false;
    return (ceil(log2(n)) == floor(log2(n)));
}
bool isPerfectSquare(ll x)
{
    if (x >= 0)
    {
        ll sr = sqrt(x);
        return (sr * sr == x);
    }
    return false;
}

#define ff first
#define ss second
#define mp make_pair
#define pb push_back

#define ps(x, y) fixed << setprecision(y) << x;

#define vi vector<int>
#define vs vector<string>
#define vvi vector<vector<int>>
#define vvs vector<vector<string>>
#define vpi vector<pair<int, int>>
// Returns the Bitwise OR of all
// llegers between L and R
ll MSBPosition(ll N)
{
    ll msb_p = -1;
    while (N)
    {
        N = N >> 1;
        msb_p++;
    }
    return msb_p;
}
ll findBitwiseOR(ll L, ll R)
{
    ll res = 0;

    // Find the MSB position in L
    ll msb_p1 = MSBPosition(L);

    // Find the MSB position in R
    ll msb_p2 = MSBPosition(R);

    while (msb_p1 == msb_p2)
    {
        ll res_val = (1 << msb_p1);

        // Add this value until msb_p1 and
        // msb_p2 are same;
        res += res_val;

        L -= res_val;
        R -= res_val;

        // Calculate msb_p1 and msb_p2
        msb_p1 = MSBPosition(L);
        msb_p2 = MSBPosition(R);
    }
    // Find the max of msb_p1 and msb_p2
    msb_p1 = max(msb_p1, msb_p2);

    // Set all the bits from msb_p1 upto
    // 0th bit in the result
    for (ll i = msb_p1; i >= 0; i--)
    {
        ll res_val = (1 << i);
        res += res_val;
    }
    return res;
}

#define i1(A, a) \
    A a;         \
    cin >> a;
#define i2(A, a, b) \
    A a, b;         \
    cin >> a >> b;
#define i3(A, a, b, c) \
    A a, b, c;         \
    cin >> a >> b >> c;
#define i4(A, a, b, c, d) \
    A a, b, c, d;         \
    cin >> a >> b >> c >> d;
#define i5(A, a, b, c, d, e) \
    A a, b, c, d, e;         \
    cin >> a >> b >> c >> d >> e;
#define i6(A, a, b, c, d, e, f) \
    A a, b, c, d, e, f;         \
    cin >> a >> b >> c >> d >> e >> f;

#define fl(i, n) for (ll i = 0; i < n; i++)
#define bl(i, n) for (ll i = n; i >= 0; i--)
#define Fl(i, k, n) for (ll i = k; i < n; i++)
#define Bl(i, k, n) for (ll i = n; i >= k; i--)
#define py cout << "YES" << "\n";
#define pm cout << "-1" << endl;
#define pn cout << "NO" << "\n";
#define it(v) v.begin(), v.end()
#define itr(v) v.rbegin(), v.rend()
#define rit(v) v.end(), v.begin()

#define o(x) cout << (x) << " ";
#define o2(x, y) cout << (x) << " " << (y) << " ";
#define o3(x, y, z) cout << (x) << " " << (y) << " " << (z) << " ";

#define oe(x) cout << (x) << endl;
#define oe2(x, y) cout << (x) << " " << (y) << endl;
#define oe3(x, y, z) cout << (x) << " " << (y) << " " << (z) << endl;

#define inv(v, n)               \
    vi v(n);                    \
    for (int i = 0; i < n; i++) \
        cin >> v[i];

// code starts here

void solve()
{
    i2(int, n, m);
    inv(arr, n);
    inv(arr2, m);
    int sum1 = accumulate(it(arr), 0ll);
    int sum2 = accumulate(it(arr2), 0ll);
    if (sum1 != sum2)
    {
        pn;
        return;
    }
    multiset<int>  ms (it(arr));
    priority_queue<int> pq;
    for(int i=0;i<m;i++){
        pq.push(arr2[i]);
    }
    while(!pq.empty() && pq.size()<=ms.size()){
        int large = pq.top();
        pq.pop();
        if(ms.size()>0 && (*ms.rbegin())==large){
            ms.erase((--ms.end()));
        }else{
        int a = (large+1)/2;
        int b = large/2;
        pq.push(a);
        pq.push(b);
        }
        // else if((*ms.rbegin())>large){
        //     pn;
        //     return;
        // }
    }
    if(ms.size()==0){
        py;
        return;
    }
    pn;
}

signed main()
{
    Code By Het;
    ll tt = 1;
    cin >> tt;
    while (tt--)
    {
        solve();
    }
}

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

using namespace std;



const int maxn = 2e5 + 1000;

const int inf = 0x7fffffff;



int n, m, a, b, s1, s2;

map<int, int> mp1, mp2;



inline void solve() {

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

  mp1.clear();

  mp2.clear();

  s1 = s2 = 0;

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

    scanf("%d", &a);

    mp1[a]++;

    s1++;

  }

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

    scanf("%d", &b);

    mp2[b]++;

    s2++;

  }



  while (!mp2.empty() && !mp1.empty() && s2 <= s1) {

    int l1 = mp1.rbegin()->first;

    int l2 = mp2.rbegin()->first;



    if (l1 == l2) {

      if (--mp1[l1] == 0) {

        mp1.erase(l1);

      }

      if (--mp2[l2] == 0) {

        mp2.erase(l2);

      }

      s1--;

      s2--;

    } else if (l1 > l2) {

      break;

    } else {

      int x = l2 / 2, y = l2 - x;

      mp2[x]++;

      mp2[y]++;

      if (--mp2[l2] == 0) {

        mp2.erase(l2);

      }

      s2++;

    }

  }



  if (mp2.empty() && mp1.empty()) {

    puts("YES");

  } else {

    puts("NO");

  }



  return;

}



int main() {

  int cas;

  scanf("%d", &cas);

  for (int _cas = 1; _cas <= cas; _cas++) {

    solve();

  }

  return 0;

}