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

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




#define int long long
#define pb push_back
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define sz(v) ((int)v.size())
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define per(i, a, b) for (int i = b - 1; i >= a; --i)
#define YES cout << "YES\n"
#define NO cout << "NO\n"

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;


const int MOD = 998244353;
const int INF = 1e18;


int modAdd(int a, int b, int m = MOD) { return (a % m + b % m) % m; }
int modSub(int a, int b, int m = MOD) { return ((a % m - b % m) + m) % m; }
int modMul(int a, int b, int m = MOD) { return (a % m * b % m) % m; }
int modPow(int a, int b, int m = MOD) {
    int res = 1;
    while (b > 0) {
        if (b & 1) res = (res * a) % m;
        a = (a * a) % m;
        b >>= 1;
    }
    return res;
}
int modInv(int a, int m = MOD) { return modPow(a, m - 2, m); }
int modDiv(int a, int b, int m = MOD) { return modMul(a, modInv(b, m), m); }


int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int lcm(int a, int b) { return (a / gcd(a, b)) * b; }


template <typename T>
vector<T> prefixSum(const vector<T> &arr) {
    int n = arr.size();
    vector<T> pref(n + 1, 0);
    rep(i, 1,  n+1) {
        pref[i] = pref[i - 1] + arr[i - 1];
    }
    return pref;
}



class graph {
    public:
    int n;
    vector<vi> edges;
    graph(int nodes) : n(nodes), edges(nodes + 1) {}

    void add_edge(int u, int v, bool directed = false) {
        // edges[u].push_back(make_pair(w, v));
        edges[u].push_back(v);
        if (!directed) {
            edges[v].push_back(u);
        }
    }

    void dfs_helper(int u, vi &visited) {
        visited[u] = 1;
        for (int v : edges[u]) {
            if (!visited[v]) {
                dfs_helper(v, visited);
            }
        }
    }

    int dfs_helper_map(int u, int depth, map<int, int> &m, vi &visited) {
        visited[u] = 1;
        m[depth] = m[depth] + 1;
        int ans = 0;
        for (auto e : edges[u]) {
            // int v = e.se
            // int w = e.fi
            int v = e;
            if (!visited[v]) {
                map<int, int> temp_m;
                ans = ans + dfs_helper_map(v, depth+1, temp_m, visited);
                map<int, int> &small = (sz(temp_m) > sz(m))? m : temp_m;
                map<int, int> &large = (sz(temp_m) > sz(m))? temp_m : m;
                for(auto entry: small) {
                    large[entry.fi] = large[entry.fi] + entry.se;
                } 
                m = large;
            }
        }

        for(auto entry: m) {
            ans += entry.fi * entry.se;
        } 

        return ans;
    }

    void dfs(int root) {
        vi visited(n + 1, 0);
        dfs_helper(root, visited);
    }
};






void solve() {
    int n, m;
    cin >> n >> m;
    vi a(n), b(m);
    multiset<int> a_counts;
    priority_queue<int> b_queue;
    rep(i, 0, n) {
        cin >> a[i];
        a_counts.insert(a[i]);
    }
    rep(i, 0, m) {
        cin >> b[i];
        b_queue.push(b[i]);
    }

    while((!b_queue.empty()) && (!a_counts.empty()) && ((sz(a_counts)) >= (sz(b_queue)))) {
        int next_b = b_queue.top();
        if (*(a_counts.begin()) > next_b) {
            break;
        }
        else {
            auto to_erase = a_counts.upper_bound(next_b);
            to_erase--;
            // if (to_erase != a_counts.end())
            if (*(to_erase) == next_b) {
                // cout << next_b << " ";
                // cout << *to_erase << endl;
                a_counts.erase(to_erase);
                // cout << "here" << endl;
                b_queue.pop();
            }
            else {
                b_queue.pop();
                b_queue.push(next_b / 2);
                b_queue.push((next_b + 1) / 2);
            }
        }
    }

    if (b_queue.empty() && a_counts.empty()) {
        YES;
    }
    else {
        NO;
    }



  
}


signed main() {
    int t;
    t = 1;
    cin >> t; 
    while (t--) {
        solve();
    }
    return 0;
}


Solution 2 (runtime: 187 ms):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
bool comp (int a ,int b) {
  return a> b;
}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int tc; cin>>tc;
    for(int _=0; _<tc; _++){
      int n,m; cin>>n>>m;
      ll sum_a=0, sum_b=0;
      vector<int> arr(n), brr(m);
      for(auto &it: arr){cin>>it; sum_a+=it;}
      for(auto &it: brr){cin>>it; sum_b+= it;}
      if(sum_a!= sum_b){cout<<"No"<<endl; continue;}
      map<int,int> c;
      sort(arr.begin(), arr.end());
      priority_queue<int> max_heap;
      for(auto it: brr) max_heap.push(it);
      bool flag= true;
      int i=n-1;
      int oper=n-m;
      while(oper>0){
        if(max_heap.top()== arr[i]){
          max_heap.pop();
          i-=1;
        }
        else if(max_heap.top()< arr[i]){
          flag= false;
          break;
        }
        else{
          int a=max_heap.top();
          max_heap.pop();
          max_heap.push(a/2);
          if(a%2==0) max_heap.push(a/2);
          else max_heap.push(a/2+1);
          oper-=1;
        }
      }
      while(i>-1){
        if(max_heap.top()==arr[i]){
          max_heap.pop();
          i--;
        }
        else{
          flag= false;
          break;
        }
      }

      if(flag) cout<<"Yes";
      else cout<<"No";
      cout<<endl;

} 
}