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

Solution 1 (runtime: 217 ms):
// Problem: D. Kevin and Numbers

// Contest: Codeforces - IAEPC Preliminary Contest (Codeforces Round 999, Div. 1 + Div. 2)

// URL: https://codeforces.com/problemset/problem/2061/D

// Memory Limit: 256 MB

// Time Limit: 2000 ms

// 

// Powered by CP Editor (https://cpeditor.org)



#include <bits/stdc++.h>

#define FOR(i, j, k) for(int i = (j);i <= (k);i ++)

#define ROF(i, j, k) for(int i = (j);i >= (k);i --)

#define For(i, j, k) for(int i = (j);i < (k);i ++)

#define Rof(i, j, k) for(int i = (j);i > (k);i --)

#define pb emplace_back

#define ull unsigned long long

#define ll long long

#define int long long

#define pii pair<int,int>

#define tu tuple<int,int,int>//get<0,1,2>(x)

#define db double

#define fi first

#define se second

#define sp(x) fixed << setprecision(x)

#define all(x) x.begin(), x.end()

#define unq_all(x) x.erase(unique(all(x)), x.end())

#define ss(x,y) setw(x) << setfill(y)

#define M(x) x %= mod, x += mod, x %= mod

#define YES cout << "YES\n"

#define NO cout << "NO\n"

#define Yes cout << "Yes\n"

#define No cout << "No\n"

#define ANS cout << ans << '\n'

const int mod = 1e9 + 7;

const int INF = 1e18;

using namespace std;

int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

int gcd(int a, int b){

    return b ? gcd(b, a % b) : a;

}

ll qmi(int a,int b,int mo)//快速幂,a的b次方取模mo

{

    ll res =1%mo;

    while(b){if(b&1)res=res*a%mo;a=(ll)a*a%mo;b>>=1;}return res;

}

inline int read()//快读只读数字有字符不用

{

    char c=getchar();int x=0,f=1;

    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}

    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}

    return x*f;

}

void slove()

{

    int n,m;

    cin>>n>>m;

    priority_queue<int> a,b;

    for(int i=1;i<=n;i++)

    {

    	int u;

    	cin>>u;

    	a.push(u);

    }

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

    {

    	int u;cin>>u;

    	b.push(u);

    }

    while(a.size()&&b.size())

    {

    	if(a.size()<b.size())

    	{

    		cout<<"NO"<<endl;

    		return;

    	}

    	if(a.top()>b.top())

    	{

    		cout<<"NO"<<endl;return;

    	}

    	if(a.top()==b.top())

    	{

    		a.pop(),b.pop();continue;

    	}

    	int k=b.top();

    	b.pop();

    	b.push(k>>1);

    	b.push((k+1)>>1);

    }

    if(a.size()==b.size())

    cout<<"YES"<<endl;

    else cout<<"NO"<<endl;

}

signed main()

{

    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

    int t=1;cin>>t;

    while(t--)

    {

        slove();

    }

    return 0;

}

Solution 2 (runtime: 327 ms):
/**

 * code by bitandas

 */

#include <bits/stdc++.h>

#define int long long

#define ll long long

#define uint unsigned long long

#define umap unordered_map

#define uset unordered_set

#define heap priority_queue

#define all(x) (x).begin(), (x).end()

#define sz(x) (long long)(x).size()

#define INF (long long)1e9

#ifdef LOCAL

#include "debug.hpp"

#else

#define debug(...)

#endif



using namespace std;

typedef vector<int> vint;

typedef vector<vint> vvint;

typedef vector<bool> vbool;

typedef vector<string> vstr;

typedef pair<int, int> pii;



template <typename T> inline void read(vector<T> &a, int i, int n) {

    while (i < n)

        cin >> a[i++];

}



void fast_io() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    cout.tie(nullptr);

}



int32_t main() {

    fast_io();

    int tt = 1;

    cin >> tt; // For multiple test cases

    while (tt--) {

        // Main solve function

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

        vint a(n), b(m);

        read(a, 0, n);

        read(b, 0, m);



        multiset<int> d(all(a));



        auto ff = [&](auto&& self, int x) -> bool {

            if (d.find(x) != d.end()) {

                d.erase(d.find(x));

                return 1;

            }

            if (x == 1) return 0;

            return self(self, x / 2) && self(self, (x + 1) / 2);

        };



        bool f = 1;

        for (auto i: b) {

            if (!ff(ff, i)) {

                f = 0;

                break;

            }

        }

        cout << (f && !d.size() ? "Yes" : "No") << endl;

    }

    return 0;

}