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


Submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<long long, null_type,less<>, rb_tree_tag,tree_order_statistics_node_update>// set
typedef tree<long long,null_type,less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update>ordered_multiset;
#define orderedset tree<pair<long long,char>,null_type,less<pair<long long,char>>,rb_tree_tag,tree_order_statistics_node_update>
#define OMAR_JR ios::sync_with_stdio(false),cin.tie(0), cout.tie(0);
#define all(v) (v).begin(), (v).end()
#define endl '\n'
#define ll long long
#define double long double
#define cin(vec) for(auto& i : vec) cin >> i
#define cout(vec) for(auto& i : vec) cout << i << " ";
#define pi 3.141592653
#define dpp(arr,t)memset(arr,t,sizeof(arr))
#define numofone(n) __builtin_popcount(n)
#define numofonell(n) __builtin_popcountll(n)
//order_of_key (k) : Number of items strictly smaller than k .
//find_by_order(k) : K-th element in a set (counting from zero).
//size - order_of_key (k) - mp[k] : Number of items strictly grater than k
//string alphabet = "abcdefghijklmnopqrstuvwxyz";
void myErase(ordered_multiset &t, ll v){
    ll rank = t.order_of_key(v);
    ordered_multiset::iterator it = t.find_by_order(rank);
    t.erase(it);
}//oredered_muliset erase
const ll mod = 1e9 + 7;
//priority_queue<ll,vector<ll>,greater<ll>>q;
ll add(ll a, ll b) {
    return ((a % mod + b % mod) % mod + mod) % mod;
}ll mul(ll a, ll b){
    return 1ll * a * b % mod;
}ll di[] = { 1, 0, -1, 0, 1, -1, 1, -1 };
ll dj[] = { 0, 1, 0, -1, 1, -1, -1, 1 };
ll mins(ll a, ll b) {
    return ((a % mod) - (b % mod) + mod) % mod;
}ll powlog(ll base , ll power){
    if(power == 0ll)return 1ll;
    ll x = powlog(base , power / 2ll) ;
    x = mul(x , x) ;
    if(power & 1ll)x = mul(x , base) ;
    return x ;
}ll modinv(ll x){
    return powlog(x , mod-2ll) ;
}ll Div(ll x , ll y){
    return mul(x ,modinv(y)) ;
}void File() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}ll gcd(ll x, ll y) { return ((!y) ? x : gcd(y, x % y));}
ll lcm(ll x, ll y) { return ((x / gcd(x, y)) * y); }
ll setbit1(ll n, ll x) {
    return n | (1ll << x);
}ll cheak(ll num,ll idx) {
    num >>= idx;
    return num & 1ll;
}ll setbit0(ll num,ll idx) {
    return (~(1ll << idx) & num);
}ll fp(ll n, ll p){
    if (!p)return 1ll;
    ll temp = fp(n, p >> 1ll);
    temp = mul(temp, temp);
    if (p & 1ll)temp = mul(temp, n);
    return temp;
}//A % m = B % m
//A % m - B % m = 0
//(A - B) % m = 0;
// (100 / 5) % mod ==  100 * inverse(5) % mod
// inverse(5) = 5^-1 ----- 5^-1 = 5^mod-2
bool rec(ll val,multiset<ll>&s){
    if(!s.size())return 0;
    if(s.count(val)){
        s.erase(s.find(val));
        return 1;
    }if(val == 1)return 0;
    return rec(val/2,s) and rec(val/2+(val&1),s);
}
void lol() {
    ll x,y;cin >> x >> y;
    vector<ll>v1(x),v2(y);
    cin(v1);cin(v2);
    multiset<ll>s;
    for(int i = 0 ; i < y ; i++){
        s.insert(v2[i]);
    }sort(all(v1)),sort(all(v2));
    for(int i = 0 ; i < x ; i++){
        if(!rec(v1[i],s))return cout << "NO" << endl,void();
    }cout << "YES" << endl;
}
signed main(){
    OMAR_JR
    int t = 1;
    cin >> t;
    while(t--) {
        lol();
    }
}