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

Solution 1 (runtime: 374 ms):
#include<bits/stdc++.h>
  using namespace std;
  #define ch cout<<"$"<<endl;
  #define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
  #define MOD 1000000007
  #define MOD1 1000000009
  #define MOD2 998244353
  #define INF 1e18
  #define nline "\n"
  #define set_bits __builtin_popcountll
  #define sz(x) ((int)(x).size())
  #define yes cout<<"YES"
  #define no cout<<"NO"
  #define int long long
  #define all(x) x.begin(),x.end()
  typedef long long ll;
  typedef unsigned long long ull;
  typedef long double lld;
  
  #ifndef ONLINE_JUDGE
  #define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
  #else
  #define debug(x)
  #endif
   
  void _print(int t) {cerr << t;}
  void _print(string t) {cerr << t;}
  void _print(char t) {cerr << t;}
  void _print(lld t) {cerr << t;}
  void _print(double t) {cerr << t;}
  void _print(ull t) {cerr << t;}
 
  template <class T, class V> void _print(pair <T, V> p);
  template <class T> void _print(vector <T> v);
  template <class T> void _print(set <T> v);
  template <class T, class V> void _print(map <T, V> v);
  template <class T> void _print(multiset <T> v);
   
  template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";}
  template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
  template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
  template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
  template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}
  template<> void _print(vector<pair<int, int>> v) { cerr << "[ ";for (auto p : v) { cerr << "{";_print(p.first); cerr << ", "; _print(p.second);cerr << "} ";}cerr << "]";}
 
  //-----------------------------------------------------------------------------------------------------------------------------------------------------
  /*---------------------------------------------------------------------------------------------------------------------------*/
  ll gcd(ll a, ll b) {if (b > a) {return gcd(b, a);} if (b == 0) {return a;} return gcd(b, a % b);}
  ll expo(ll a, ll b, ll mod) {ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;}
  void extendgcd(ll a, ll b, ll*v) {if (b == 0) {v[0] = 1; v[1] = 0; v[2] = a; return ;} extendgcd(b, a % b, v); ll x = v[1]; v[1] = v[0] - v[1] * (a / b); v[0] = x; return;} //pass an arry of size1 3
  ll mminv(ll a, ll b) {ll arr[3]; extendgcd(a, b, arr); return arr[0];} //for non prime b
  ll mminvprime(ll a, ll b) {return expo(a, b - 2, b);}
  bool revsort(ll a, ll b) {return a > b;}
  ll combination(ll n, ll r, ll m, ll *fact, ll *ifact) {ll val1 = fact[n]; ll val2 = ifact[n - r]; ll val3 = ifact[r]; return (((val1 * val2) % m) * val3) % m;}
  void google(int t) {cout << "Case #" << t << ": ";}
  vector<ll> sieve(int n) {int*arr = new int[n + 1](); vector<ll> vect; for (int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for (int j = 2 * i; j <= n; j += i)arr[j] = 1;} return vect;}
  ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;}
  ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;}
  ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;}
  ll mod_div(ll a, ll b, ll m) {a = a % m; b = b % m; return (mod_mul(a, mminvprime(b, m), m) + m) % m;}  //only for prime m
  ll phin(ll n) {ll number = n; if (n % 2 == 0) {number /= 2; while (n % 2 == 0) n /= 2;} for (ll i = 3; i <= sqrt(n); i += 2) {if (n % i == 0) {while (n % i == 0)n /= i; number = (number / i * (i - 1));}} if (n > 1)number = (number / n * (n - 1)) ; return number;} //O(sqrt(N))
  vector<int> decimalToBinary(int n) {  vector<int> binary(32, 0); int index = 31;  while (n > 0) {    int remainder = n % 2;    binary[index] = remainder;    n /= 2;    index--; } reverse(binary.begin(),binary.end()); return binary;}
  ll binpow(long long a, long long b) { if (b == 0)   return 1;  long long res = binpow(a, b / 2);  if (b % 2)return res * res * a; else return res * res;}
  // ll binaryToDecimal(vector<int>& binary) { reverse(all(binary)); int decimal = 0; int power = 1;for (int i = binary.size() - 1; i >= 0; --i) { decimal += binary[i] * power; power *= 2;}return decimal;}
  ll binaryToDecimal(string binary) {long long decimal = 0;long long power = 1;for (long long i = binary.size() - 1; i >= 0; --i) {decimal += (binary[i]-'0') * power; power *= 2;}return decimal;}
  /*--------------------------------------------------------------------------------------------------------------------------------------------------------*/




void solve() {
    int n;
    cin >> n;
    int m;cin>>m; 
    vector<int>a(n);for(auto &it : a)cin>>it; 
    vector<int>b(m);for(auto &it : b)cin>>it; 
    vector<int>stk;     
    multiset<int>ss(a.begin(),a.end()); 
    for(int i =0;i<m;i++){
        if(ss.find(b[i]) != ss.end()){
            ss.erase(ss.find(b[i]));
        }
        else stk.push_back(b[i]); 
    }
    while(stk.size() > 0){

        int last = stk.back();
        stk.pop_back(); 
        int one,two;  
        if(last % 2 ==0){
            one = last / 2; 
            two = one;
        }
        else {one = last/2;two = one + 1;}
        if(ss.find(one) != ss.end()){
            ss.erase(ss.find(one));
        }
        else {
            if(one == 1){
                no;return;
            }
            else stk.push_back(one);
        }
        if(ss.find(two) != ss.end()){
            ss.erase(ss.find(two));
        }
        else {
            if(two == 1){
                no;return;
            }
            else stk.push_back(two);
        }

    }
    if(ss.size() == 0)yes;
    else no;
}

 
int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); 
 
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
    #endif
 
    int t = 1;
    cin >> t;
    // cout<<t<<endl;
    while (t--) {
        solve();
        
        cout << "\n";
    }
 
    return 0;
}

Solution 2 (runtime: 327 ms):
/*// Ih Badhon Chowdhury //*/

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;

// using namespace __gnu_pbds;
// template<typename T> using orderset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
// template<typename T> using ordermultiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
//(*X).find_by_order(index) /// return value (0 index)
//(X).order_of_key(value) /// return lower_bound(value)

/*
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); /// mt19937_64 (long long)
auto my_rand(long long l,long long r)
{
  return uniform_int_distribution<long long>(l,r)(rng);
}
#ifndef ONLINE_JUDGE
#include "debug.h"
#else
#define dbg(...) 42
#endif
*/

#define ll long long int
#define ld long double
#define sp " "
#define lcm(a, b) (a * b) / __gcd(a, b)
#define cinv(v)     \
  for (auto &i : v) \
    cin >> i;
#define vi vector<int>
#define vii vector<ll>
#define coutv(v)       \
  for (auto it : v)    \
    cout << it << ' '; \
  cout << endl;
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define case "Case " << test++ << ": "
#define all(v) v.begin(), v.end()
#define Faster                      \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);                    \
  cout.tie(NULL);
#define nl '\n'
#define PI acos(-1)

const int N = 1000001;
const int mod = 1000000007;
const ll INF = LLONG_MAX;

///.........Bit_Manipulation...........///
#define MSB(mask) 63 - __builtin_clzll(mask) /// 0 -> -1
#define LSB(mask) __builtin_ctzll(mask)      /// 0 -> 64
#define ONE(mask) __builtin_popcountll(mask)
#define CHECK(mask, bit) (mask & (1LL << bit))
#define ON(mask, bit) (mask(1LL << bit))
#define OFF(mask, bit) (mask & ~(1LL << bit))
#define CHANGE(mask, bit) (mask ^ (1LL << bit))
#define LOG2(x) (__builtin_clz(x) ^ 31)
#define LSB1(mask) (__builtin_ffs(mask) - 1)
#define STRING_TO_INT(mask) (std::bitset<64>(mask).to_ullong())

///................Graph's Move.................
/// const int dx[] = {+1,-1,+0,+0}; ///Rock's Move
/// const int dy[] = {+0,+0,+1,-1}; ///Rock's Move
/// const int dx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's Move
/// const int dy[] = {-1,+1,+0,+0,+1,+1,-1,-1}; ///king's Move
/// const int dx[] = {-2,-2,-1,-1,+1,+1,+2,+2}; ///knight's Move
/// const int dy[] = {-1,+1,-2,+2,-2,+2,-1,+1}; ///knight's Move
///*.....................-_-........................*///

inline ll IPOW(ll n, ll k)
{
  ll ans = 1;
  while (k)
  {
    if (k & 1)
      ans = ans * n % mod;
    n = n * n % mod;
    k >>= 1;
  }
  return ans;
}
inline ll POW(ll n, ll k)
{
  ll ans = 1;
  while (k)
  {
    if (k & 1)
      ans = ans * n;
    n = n * n;
    k >>= 1;
  }
  return ans;
}
//////

// Driver Code
int main()
{
  Faster;
  ll tc = 1, test = 1;
  cin >> tc;
  while (tc--)
  {
    ll n, m;
    cin >> n >> m;

    multiset<ll> ms;

    for (int i = 0; i < n; i++)
    {
      ll x;
      cin >> x;
      ms.insert(x);
    }

    priority_queue<ll> pq;

    for (int i = 0; i < m; i++)
    {
      ll x;
      cin >> x;
      pq.push(x);
    }

    bool ok = 1;

    while (!pq.empty())
    {
      if (pq.size() > ms.size())
      {
        ok = 0;
        break;
      }
      ll u = pq.top();
      pq.pop();

      if (ms.find(u) != ms.end())
      {
        ms.erase(ms.find(u));
      }
      else
      {
        ll x = u / 2;
        ll y = (u + 1) / 2;
        pq.push(x);
        pq.push(y);
      }
    }

    if (!ok or pq.size() or ms.size())
      no;
    else
      yes;
  }
}