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

Solution 1 (runtime: 671 ms):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 998244353

void solve() {
    int n, m;
    cin >> n >> m;
    
    priority_queue<int> a, b;
    
    // Input sets (pushing elements into max-heaps)
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        a.push(x);
    }
    
    for (int i = 0; i < m; i++) {
        int y;
        cin >> y;
        b.push(y);
    }
    int itr=n-m+1;
    // Process the heaps
    while (itr && !a.empty() && !b.empty()) {
        int top_a = a.top();
        int top_b = b.top();
        
        if (top_a == top_b) {
            // Remove both elements as they match
            a.pop();
            b.pop();
        } else if (top_a < top_b) {
            // Split the largest element from b
            b.pop();
            if (top_b > 1) {
                itr--;
                b.push(top_b / 2);
                b.push((top_b + 1) / 2);
            } else {
                cout << "NO\n";
                return;
            }
        } else {
            // If top_a > top_b, output NO
            cout << "NO\n";
            return;
        }
    }

    // If either heap is non-empty, print NO
    if (!a.empty() || !b.empty()) {
        cout << "NO\n";
        return;
    }

    cout << "YES\n";
}

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


Solution 2 (runtime: 327 ms):
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
double eps = 1e-12;
#define ln "\n"
#define printVector(a) for(int i=0; i<a.size(); i++){cout<<a[i]<<" ";}cout<<ln;
#define print_array(a,n) for(int i=0; i<n; i++){cout<<a[i]<<" ";}cout<<ln;
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define pb push_back
#define take_vector(a) for(auto &x:a)cin>>x;
#define take_array(a,n) for(int i=0;i<n;i++){cin>>a[i];}
#define take_matrix(a,m,n) for(int i=0; i<m; i++){for(int j=0; j<n; j++){cin>>a[i][j];}}
#define print_matrix(a,m,n) for(int i=0; i<m; i++){for(int j=0; j<n; j++){cout<<a[i][j]<<" ";}cout<<ln;}
#define fi first
#define se second
#define INF 2e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/gcd(a,b))*b
#define count(a,x) count(a.begin(), a.end(),x)  
#define sum(a) accumulate(a.begin(), a.end(),0)
#define max_ele(a) *max_element(a.begin(), a.end())
#define min_ele(a) *min_element(a.begin(), a.end())

map<int,int> mp;

bool isPossible(int num){
 
    if( mp[num] ){

        mp[num]--;
        
        return 1;
    }

    if( num == 1 ) return false;

    return isPossible( num / 2 ) and isPossible( (num + 1)/2 );

}

int32_t main()
{
  fast_cin();

  int t;
  cin >> t;

  while (t--)
  {

    int n,m;
    cin>>n>>m;

    mp.clear();
    
    vector<int> a(n,0);
    for( int i = 0; i < n;  i++ ){ cin>>a[i]; mp[a[i]]++; }

    vector<int> b(m,0);
    for( int i = 0; i < m ; i++ ){ cin>>b[i]; }

    if( sum(a) != sum(b) ){ cout<<"NO"<<endl; continue; }

    sort(b.begin(),b.end());

    bool flag = 1;

    for( auto it : b ){
        if( !isPossible(it) ){
            flag = 0;
            break;
        }
    }

    if( flag == 1 ) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    

  }
  return 0;
}