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

Solution 1 (runtime: 203 ms):
#include "bits/stdc++.h" 
using namespace std; 
#define dbg(x) cout << #x << '=' << x << endl;
#define int long long
#define inc(v) sort(v.begin() , v.end()) 
#define dec(v) sort(v.rbegin() , v.rend()) 
typedef vector<int> vi; 
typedef pair<int, int> pi; 
#define pb push_back 
#define get(a) for(int i = 0; i<a.size(); i++) cin >> a[i]; 
#define print(a) for(int i = 0; i<a.size(); i++) cout << a[i] << ' '; cout << "\n"; 
#define yes() cout << "YES\n"; 
#define no() cout << "NO\n"; 

void solve()
{
    int n , m ;
    cin >> n >> m ;

    vi a(n) , b(m) ;
    get(a) ; get(b) ;

    int sum = 0 ;
    priority_queue<int> x , y ;
    for(int i=0 ; i<n ; i++){
        x.push(a[i]) ;
        sum += a[i] ;
    }
    for(int i=0 ; i<m ; i++){
        y.push(b[i]) ;
        sum -= b[i] ;
    }
    if(sum){
        cout << "No\n" ;
        return ;
    }
    while(y.size() < x.size()){
        // dbg(x.size()) ;
        if(y.empty() || x.empty()){
            break ;
        }
        int b_top = y.top() ;
        if(x.top() < y.top()){
            y.pop() ;
            y.push(b_top/2) ;
            y.push((b_top+1)/2) ;
        }else if(x.top() == y.top()){
            x.pop() ;
            y.pop() ;
        }else{
            cout << "No\n" ;
            return ;
        }
    }
    
    while(!y.empty()){
        if(x.empty()){
            cout << "No\n";
            return ;
        }
        if(y.top()!=x.top()){
            cout << "No\n";
            return ;
        }
        y.pop() ; x.pop() ;
    }

    if(!x.empty()){
        cout << "No\n";
        return ;
    }

    cout << "Yes\n" ;
    return ;

}

int32_t main() 
{ 
    ios::sync_with_stdio(0); 
    cin.tie(0);
    cout.tie(0); 
    int T; 
    cin >> T; 
    while (T--) { 
        solve();
    } 
    return 0; 
} 

Solution 2 (runtime: 405 ms):
#include <cmath>
#include <algorithm>
#include <iostream>
#include <map>
#include <functional>
#include <queue>
#include <set>
#include <bitset>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define ll long long
#define int long long
#define pqi priority_queue<long long>
#define pi pair<long long, long long>
#define mi map<long long, long long>
#define vi vector<long long>
#define vvi vector<vector<long long>>

using namespace std;

int gcd(int a, int b){
    //a>b
    if(b==0) return a;
    return gcd(b,a%b);
}
istream &operator>>(istream &is, vector<int> &vec)
{
//    vec.clear();
    int num;
    while (is >> num)
    {
        vec.push_back(num);
        char ch = is.peek();
        if (ch == '\n')
        {
            is.ignore();
            break;
        }
    }
    return is;
}

void print(vector <int> v){
    for(auto it:v) cout << it <<' ';
    cout <<endl;
}
vector<int> prefixSum(vector<int> v ){
    vector<int> ans ;
    int sum=0;
    for (int i =0; i < v.size();i++){
        sum+=v[i];
        ans.push_back(sum);
    }
    return ans;
}
void print(const vector<std::vector<int>> arr) {
    for (const std::vector<int>& row : arr) {
        for (int num : row) {

            std::cout << num << " ";
        }
        std::cout << std::endl;
    }
}

const int mod = 1e9+7;
const int N= 3e5 ;
int64_t fact[N];
int64_t pw(int64_t a, int64_t b) {
    int64_t r = 1;
    while(b > 0) {
        if(b & 1) r = (r * a) % mod;
        b /= 2;
        a = (a * a) % mod;
    }
    return r;
}
int64_t C(int64_t n, int64_t k) {
    if(n < k) return 0LL;
    return (fact[n] * pw((fact[n - k] * fact[k]) % mod, mod - 2)) % mod;
}
int modInverse(int a, int m) {
    int result = 1;
    int exp = m - 2;
    while (exp > 0) {
        if (exp % 2 == 1) {
            result = (result * a) % m;
        }
        a = (a * a) % m;
        exp /= 2;
    }
    return result;
}

long long modExp(long long a, long long b, long long m) {
    long long result = 1;
    a = a % m;  // In case a is larger than m

    while (b > 0) {
        // If b is odd, multiply a with result
        if (b % 2 == 1) {
            result = (result * a) % m;
        }

        // Now b must be even, square a
        a = (a * a) % m;
        
        // Divide b by 2
        b = b / 2;
    }

    return result;
}

long long modMultiply(long long a, long long b, long long m) {
    return ((a % m) * (b % m)) % m;
}

vector<int> findDivisors(int n) {
    std::vector<int> divisors;

    // Loop from 1 to sqrt(n) to find divisors
    for (int i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            divisors.push_back(i);  // Add divisor i
            if (i != n / i) {
                divisors.push_back(n / i);  // Add the complementary divisor n/i, if it's not the same
            }
        }
    }
    sort(divisors.begin(), divisors.end());
    return divisors;
}

class UnionFind {
public:
    UnionFind(int n) {
        parent.resize(n + 1);
        size.resize(n + 1, 1);
        hasCycle.resize(n + 1, false);  
        for (int i = 1; i <= n; ++i) {
            parent[i] = i; 
        }
    }

    int find(int u) {
        if (parent[u] != u) {
            parent[u] = find(parent[u]);  
        }
        return parent[u];
    }

    void unionSets(int u, int v) {
        int rootU = find(u);
        int rootV = find(v);
        if (rootU != rootV) {
            // Union by size: attach the smaller tree under the root of the larger tree
            if (size[rootU] < size[rootV]) {
                swap(rootU, rootV);
            }
            parent[rootV] = rootU;
            size[rootU] += size[rootV];
            // If either of the components was cyclic, mark the new component as cyclic
            hasCycle[rootU] = hasCycle[rootU] || hasCycle[rootV];
        } else {
            // If they are already in the same component, a cycle is formed
            hasCycle[rootU] = true;
        }
    }

    bool isCyclic(int u) {
        return hasCycle[find(u)];
    }

private:
    vector<int> parent;
    vector<int> size;
    vector<bool> hasCycle;
};

set<int> sieveOfEratosthenes(int n) {
    vector<bool> is_prime(n + 1, true);
    is_prime[0] = is_prime[1] = false;
    set<int> primes;
    
    for (int i = 2; i <= n; i++) {
        if (is_prime[i]) {
            primes.insert(i);
            for (int j = i * i; j <= n; j += i) {
                is_prime[j] = false;
            }
        }
    }
    
    return primes;
}
void print(const map<int, int> &mp) {
    for (const auto &[key, value] : mp) {
        cout << key << ": " << value << "\n";
    }
}
int sum(vi & a){
    int s = 0;
    for(int i : a) s+=i;
    return s;
}
void print(const multiset<int> &ms) {
    for (int x : ms) {
        cout << x << " ";
    }
    cout << "\n";
}


void solve(){
    int  n,m;
    vi a,b;
    cin >> n >> m >> a >> b;

    if(sum(a) != sum(b)){
        cout <<"No\n";
        return;
    }    

    multiset <int> sa (a.begin(), a.end()),sb(b.begin(),b.end());
    for (auto it = sa.begin(); it != sa.end();) {
        auto found = sb.find(*it);
        if (found != sb.end()) {
            sb.erase(found);  // Remove one occurrence from sb
            it = sa.erase(it); // Remove one occurrence from sa
        } else {
            ++it;
        }
    }
    // print(sa);
    // print(sb);

    // mi ma,mb;
    // for(int i : a)ma[i]++;
    // for(int i : b) mb[i]++;

    

    // for(auto & [num, f] : mb){
    //     int t = min(f,ma[num]);
    //     ma[num] -= t;
    //     f -= t;
    // }
    
    // // print(ma);
    // // cout <<endl;
    // // print(mb);

    
    
    while(sa.size() != sb.size()){
        int l = * sb.rbegin();
        sb.erase( prev(sb.end()));
        
        if(sa.find(l/2) == sa.end()){ 
            sb.insert( l/2);
        }else{
            sa.erase(sa.find(l/2));
        }

        if(sa.find((l+1)/2) == sa.end()){ 
            sb.insert( (l+1)/2);
        }else{
            sa.erase(sa.find((l+1)/2));
        }

        // print(sa);
        // print(sb);
    }
    
    if( sa == sb )cout <<"Yes"<<endl;
    else cout <<"No\n";
}

int32_t main()
{

    ios_base ::sync_with_stdio(false);
    cin.tie(NULL);

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int T = 1;

//    fact[0] = 1;
//    for(int64_t i = 1; i < N; ++i) fact[i] = (fact[i - 1] * i) % mod;

   cin >> T;

    while (T--)
    {
        solve();
    }

    return 0;
}