Problem: 2061D - Kevin and Numbers
Language: C++17 (GCC 7-32)


Submission (verdict: Memory limit exceeded on test 1):
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<long long> vll;
typedef vector<double> vd;
typedef vector<pair<ll,ll>> vpll;
typedef vector<vector<ll>> vvll;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
#define fo(i,n) for(ll i=0;i<n;i++)
#define foa(i,k,n) for(ll i=k;i<=n;i++)
#define fob(i,k,n) for(ll i=k;i>=n;i--)
#define sortuniq(v){sort(v.begin(), v.end());v.erase(unique(v.begin(),v.end()),v.end());}
#define inp(a) fo(i,a.size()){cin>>a[i];}
#define uniq(v){v.erase(unique(v.begin(), v.end()), v.end());}
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define print(a){for(ll i=0;i<a.size();++i){cout<<a[i]<<" ";}cout<<endl;}
#define printst(st){for(auto it=st.begin();it!=st.end();++it){cout<<*it<<" ";}cout<<endl;}
#define printpair(p){for(ll i=0;i<p.size();++i){cout<<p[i].first<<":"<<p[i].second<<" ";}cout<<endl;}
#define printmap(mp){for(auto ix=mp.begin();ix!=mp.end();++ix){cout<<ix->first<<":"<<ix->second<<" ";}cout<<endl;}
#define dbg(var) cout << #var << ": " << var << endl;
#pragma GCC optimize("O2")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using ordered_set = tree<T, null_type , less<T> , rb_tree_tag , tree_order_statistics_node_update>;
const ll mod1 = ll(1e9 + 7);
const ll mod2 = 998244353LL;
const ll inf = ll(INT64_MAX);
const ll NMAX = (ll)2e5 + 100;
const int dx[4]{1, 0, -1, 0}, dy[4]{0, 1, 0, -1};
const int d8x[8]{1, 0, -1, 0, 1, 1, -1, -1},d8y[8]{0, 1, 0, -1, 1, -1, 1, -1};
#define pb push_back
#define eb emplace_back
#define sz(x) int(x.size())
#define all(x) begin(x), end(x)
#define sor(x) sort(all(x))
#define F first
#define S second

bool isPrime(ll n) {
    for(ll i = 2; i*i <= n; i++)
        if (n % i == 0) return false;
    if(n==1){return false;}
    return true;
}
const ll MOD = mod1;////
ll norm(ll x) { return ((x%MOD) + MOD) % MOD; }
template <class T>
T power(T a, ll b, T res = 1) {
for (; b; b /= 2, (a *= a) %= MOD)
if (b & 1) (res *= a) %= MOD;
return res;
}
struct Mint {
ll x;
Mint(ll _x = 0) : x(norm(_x)) {}
Mint operator-() const { return Mint(norm(MOD - x)); }
Mint inv() const { return power(*this, MOD - 2); }
Mint &operator*=(const Mint &rhs) { return x = x * rhs.x % MOD, *this; }
Mint &operator+=(const Mint &rhs) { return x = norm(x + rhs.x), *this; }
Mint &operator-=(const Mint &rhs) { return x = norm(x - rhs.x), *this; }
Mint &operator/=(const Mint &rhs) { return *this *= rhs.inv(); }
Mint &operator%=(const auto &_) { return *this; }
friend Mint operator*(Mint lhs, const Mint &rhs) { return lhs *= rhs; }
friend Mint operator+(Mint lhs, const Mint &rhs) { return lhs += rhs; }
friend Mint operator-(Mint lhs, const Mint &rhs) { return lhs -= rhs; }
friend Mint operator/(Mint lhs, const Mint &rhs) { return lhs /= rhs; }
friend Mint operator%(Mint lhs, const auto &_) { return lhs; }
friend istream &operator>>(istream &input, Mint &z) { return input >> z.x, input; }
};
ostream& operator<<(ostream& out, const Mint& x)
{
return out << x.x;
}
//ll fact[NMAX];ll invfact[NMAX];
ll fast_power(ll n, ll p, ll m){
    ll result=1;
    while(p>0){
        if(p&1){result=(result*n)%m;}
        n=(n*n)%m;
        p>>=1;
    }
    return result;
}

ll inverse(ll a, ll mod) {
if (a == 1) return 1;
return fast_power(a, mod-2, mod);
}
/*ll ncr(ll a, ll b, ll mod) {
if(a < 0 || b < 0) return 0;
if (a < b) return 0;
ll cur = fact[a];
cur *= invfact[b];
cur %= mod;
cur *= invfact[a - b];
cur %= mod;
return cur;
}
void factcomp() {
fact[0] = 1;
invfact[0] = 1;
for(ll i = 1; i < NMAX; i++) {
fact[i] = fact[i-1] * i;
fact[i] %= MOD;
}
invfact[NMAX-1] = inverse(fact[NMAX-1], MOD);
for(int i = NMAX-2; i > -1; i--) {
invfact[i] = invfact[i+1] * (i+1);
invfact[i] %= MOD;
}
}*/
string slice1(const string& s,ll a,ll b) {
    if (a<0||b>s.size()||a>b) {return "";}
    return s.substr(a,b-a);
}

bool comp2(const std::pair<ll,ll>& a,const std::pair<ll,ll>& b) {
    return a.second<b.second;
}

void sort2nd(vector<std::pair<ll,ll>>& v) {
    sort(v.begin(),v.end(),comp2);
}

vll factorize(ll n) {
    vll factorization;
    while (n % 2 == 0) {
        factorization.push_back(2);
        n /= 2;
    }
    for (long long d = 3; d * d <= n; d += 2) {
        while (n % d == 0) {
            factorization.push_back(d);
            n /= d;
        }
    }
    if (n > 1)
        factorization.push_back(n);
    return factorization;
}

ll round(ll a, ll b) {
    ll q = a / b, r = a % b;
    if (2 * r >= b) {
        return q + (a > 0 ? 1 : -1);
    }
    return q;
}
vll sieve(ll n) {
    vector<bool> is_prime(n + 1, true);
    is_prime[0] = is_prime[1] = false;
    for (ll i = 2; i <= n; i++) {
        if (is_prime[i] && (ll)i * i <= n) {
            for (ll j = i * i; j <= n; j += i)
                is_prime[j] = false;
        }
    }
    vll primes;
    for (ll i = 2; i <= n; i++) {
        if (is_prime[i]) primes.push_back(i);
    }
    return primes;
}

ll ee(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {x = 1;y = 0;return a;}ll x1, y1;
    ll gcd = ee(b, a % b, x1, y1);x = y1;
    y = x1 - (a / b) * y1;
    return gcd;
}

ll modinv(ll a, ll m) {
    ll x, y;ll g = ee(a, m, x, y);
    if (g != 1) {return -1;}
    return (x % m + m) % m;
}

ll sqrtfn(ll x) {
    ll l = 0, r = 2e9;
    while(l<r){
        ll mid=(l+r+1)/2;
        if(mid*mid<=x){l=mid;}
        else{r=mid-1;}
    }
    return l;
}

int checkpow(ll mid, ll n, ll x) {
    ll result = 1;
    for (ll i = 1; i <= n; ++i) {
        if (result > x / mid) return 1;
        result *= mid;
    }
    if (result == x) return 0;
    return -1;
}
 
ll fnrx(ll n, ll x) {
    ll low = 1, high = x, ans = 1;
    while (low <= high) {
        ll mid = (low + high) / 2;
        int cmp = checkpow(mid, n, x);
        if (cmp == 0) return mid; 
        if (cmp < 0) {
            ans = mid;           
            low = mid + 1;
        } else {
            high = mid - 1;
        }
    }
    return ans;
}

ll cnrx(ll n, ll x) {
    ll low = 1, high = x, ans = x;
    while (low <= high) {
        ll mid = (low + high) / 2;
        int cmp = checkpow(mid, n, x);
        if (cmp == 0) return mid;
        if (cmp < 0) {          
            low = mid + 1;
        } else {
            ans = mid;        
            high = mid - 1;
        }
    }
    return ans;
}

ll gcd(ll a, ll b) {
    if(b==0)return a;
    return gcd(b,a%b);
}

ll powkn(ll n, ll k) {
    ll count = 0;
    while (n % k == 0) {count++;n /= k;}
    return count;
}

ll cntbits(ll n) {
    ll bits=0;
    while(n>0){bits++;n>>=1;}
    if(bits==0)bits=1;return bits;
}

ll hp2(ll n) {
    if ((n&(n-1))==0) return n;
    ll p=1;
    while(p<=n){p<<=1;}
    return p>>1;
}

vll grpsz(const string& s) {
vll res = {0};
for (char c : s) {
if (res.size() % 2 == (c == '1')) res.back()++;
else res.push_back(1);
}
return res;
}

vll grpsz2(const string& s) {
vll res;
ll count = 1;
for(ll i = 1; i < sz(s); i++) {
if (s[i] == s[i - 1]) {
count++;
} else {
res.push_back(count);
count = 1;
}
}
res.push_back(count);
return res;
}
ll hpk(ll k,ll n) {
    ll p=1;
    while(p*k<=n){p*=k;}
    return p;
}

ll lcm(ll a, ll b) {
    return (a/gcd(a,b))*b;
}

void rotatek(vector<ll>& a,ll k) {
    ll n=a.size();
    k=k%n;
    if(k<0) k+=n;
    reverse(a.begin(),a.end());
    reverse(a.begin(),a.begin()+k);
    reverse(a.begin()+k,a.end());
}

void solve() {
    ll n,m;cin>>n>>m;
    vll a(n),b(m);
    inp(a);inp(b);
    priority_queue<ll> qa(all(a));
    priority_queue<ll> qb(all(b));
    while(!qa.empty() && !qb.empty()){
        ll v1 = qa.top();
        ll v2 = qb.top();
        if(v1==v2){
            qa.pop();
            qb.pop();
        }
        else if(v1>v2){
            no;return;
        }
        else{
            qb.pop();
            qb.push((v2)/2);
            qb.push((v2+1)/2);
        }
    }
    yes;
}

signed main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(0); cin.tie(0);
    //.
    ll tc;cin>>tc;while(tc--){solve();}
    //solve();
    return 0;
}