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

Solution 1 (runtime: 484 ms):
/*
    Date: 30-01-2025	20:02:54
    © Arghadeep Das
    https://www.linkedin.com/in/arghadeep-das-0b179b212/
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
// Ordered Multiset
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define int long long int
#define endl '\n'
#define MOD(x) ((x) % 1000000007)
#define sign(x) ((x) < 0? -1: ((x) > 0 ? 1) : 0)
#define a first
#define b second
#define SORT(x) (sort(x.begin(), x.end()))

void solve()
{
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];
    }
    vector<int> b(m);
    for (int i = 0; i < m; ++i)
    {
        cin >> b[i];
    }
    // keep splitting
    ordered_multiset<int> sa(a.begin(), a.end());
    ordered_multiset<int> sb(b.begin(), b.end());

    int l = sa.size();
    l--;
    int r = sb.size();
    r--;
    bool flag = true;

    while (l >= 0 && r >= 0)
    {
        if (sb.size() > sa.size())
            break;
        // for (auto &x : sa)
        // {
        //     cout << x << " ";
        // }
        // cout << endl;
        // for (auto &x : sb)
        // {
        //     cout << x << " ";
        // }
        // cout << endl
        //      << endl;

        if (*sa.find_by_order(l) == *sb.find_by_order(r))
        {
            l--;
            r--;
        }
        else
        {
            auto a = sb.find_by_order(r);
            int x = *a / 2;
            int y = (*a + 1) / 2;
            sb.erase(a);
            sb.insert(x);
            sb.insert(y);
            r++;
        }
    }

    flag = (l == -1 && r == -1);

    if (flag)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
}
// g++ -Wl,--stack,167772160 source.cpp -o source.exe && source.exe < input.txt > output.txt 2>&1

// 1 2 10 3 3 2 3 3 2 1 1 1 5 2 1 1 2 2
// 7 9 1 6 5 2 10 5

// 1 1 1 1 1 1 2 2 2 2 2 2 3 3 3 3 5 10
// 1 2 5 5 6 7 9 10

// 1 1 1 1 1 1 2 2 2 2 2 2 3 3 3 3 5 10
// 1 1 1 2 2 2 3 3 3 3 3 3 3 5 10

Solution 2 (runtime: 296 ms):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 200005;
map<ll, int> mp;
int n, m, a[N], b[N];
bool solve(int x)
{
    if(x == 0) return false;
    if(mp[x]) return mp[x] --, true;

    return (solve(x / 2) && solve((x + 1) / 2));
}
int main()
{
    // freopen("1.in", "r", stdin);
    // freopen("1.out", "w", stdout);
    int T;
    scanf("%d", &T);
    while(T --)
    {
        scanf("%d %d", &n, &m);
        ll sum1 = 0, sum2 = 0;
        mp.clear();
        for (int i = 1; i <= n; ++ i) scanf("%d", &a[i]), sum1 += a[i], mp[a[i]] ++;
        for (int i = 1; i <= m; ++ i) scanf("%d", &b[i]), sum2 += b[i];
        if(sum1 != sum2)
        {
            printf("No\n");
        }
        else
        {
            bool pd = true;
            for (int i = 1; i <= m; ++ i) 
            {  
                if(!solve(b[i]))
                {
                    pd = false;
                    break;
                }
            }
            if(pd) printf("Yes\n");
            else printf("No\n");
        }
    }
    return 0;
}