Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 3):
///////////////// REMARKS ////////////////////////////////////////////
 

//tut ref thg intuition was sim

///////////////// PPD FUNC //////////////////////////////////////////
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx2")
// const long long MOD = 1000000007;
const int N = 2e5 + 2;
const int MAX1 = 100000;
const int MAX3 = 2000000 + 100;
const int MAX2 = 1005, OO = 0x3f3f3f3f;
const int MOD = 1000000007;

#define M_PI 3.14159265358979323846

#define pb push_back
#define yes cout << "Yes\n"
#define no cout << "No\n"
typedef long long ll;

/////////////////////////DEFINED STRUCTS/////////////////////////////
typedef tree
<
    int,
    null_type,
    less<int>,
    rb_tree_tag,
    tree_order_statistics_node_update
> ordered_multiset;

///////////////////////////DEFINED DATA//////////////////////////////

vector<int> fenwickTree(N + 2, 0);

vector<int> fact(MAX1), invFact(MAX1);
int dx[] = {-1, 0, 0, 1};
int dy[] = {0, 1, -1, 0};

////////////////////////////HELPERS//////////////////////////////////
int modPow(int x, int y, int p) {
    int res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}


int mod_inverse(int a, int m) {
    return modPow(a, m - 2, m);
}


int nCr_mod(int n, int r) {
    if (r > n) return 0;
    if (r > n - r) r = n - r;
    int numerator = 1, denominator = 1;
    for (int i = 0; i < r; i++) {
        numerator = (numerator * (n - i)) % MOD;
        denominator = (denominator * (i + 1)) % MOD;
    }
    return (numerator * mod_inverse(denominator, MOD)) % MOD;
}

void precomputeFactorials(int maxN) {
    fact[0] = 1;
    for (int i = 1; i <= maxN; i++) {
        fact[i] = fact[i - 1] * i % MOD;
    }
    invFact[maxN] = modPow(fact[maxN], MOD - 2, MOD);
    for (int i = maxN - 1; i >= 0; i--) {
        invFact[i] = invFact[i + 1] * (i + 1) % MOD;
    }
}

int binomialCoefficient(int n, int k) {
    if (k > n) return 0;
    return fact[n] * invFact[k] % MOD * invFact[n - k] % MOD;
}

int lucas(int n, int k, int p) {
    if (k == 0) return 1;
    int ni = n % p, ki = k % p;
    if (ki > ni) return 0;

    return lucas(n / p, k / p, p) * binomialCoefficient(ni, ki) % p;
}

bool isPrime(int n) {
    if (n <= 1) return false;
    if (n <= 3) return true;
    if (n % 2 == 0 || n % 3 == 0) return false;

    for (int i = 5; i * i <= n; i += 6) {
        if (n % i == 0 || n % (i + 2) == 0) return false;
    }
    return true;
}

int logBase3(int x) {
    return (int)(log(x) / log(3));
}

int maxDivisor(int n) {
    for (int i = 2; i * i <= n; ++i) {
        if (n % i == 0) {
            return n / i;
        }
    }
    return 1;
}

int sumOfDigits(int val) {
    int sum = 0, digit = 0;
    while (val) {
        digit = val % 10;
        sum += digit;
        val /= 10;
    }
    return sum;
}

void updateFenwickTree(int idx, int updateValue, int n) {
    while (idx <= n) {
        fenwickTree[idx] += updateValue;
        idx += idx & -idx;
    }
}

int queryFenwickTree(int idx, int modValue) {
    int res = 0;
    while (idx > 0) {
        res *= fenwickTree[idx] % modValue;
        idx -= idx & -idx;
    }
    return res;
}

void resetFenwickTree(int size) {
    for (int i = 0; i <= size; ++i) {
        fenwickTree[i] = 0;
    }
}

vector<int> generatePrimes(int maxLimit) {
    vector<bool> isPrime(maxLimit + 1, true);
    vector<int> primes;

    isPrime[0] = isPrime[1] = false;
    for (int i = 2; i <= maxLimit; ++i) {
        if (isPrime[i]) {
            primes.push_back(i);
            if ((int)i * i <= maxLimit) {
                for (int j = i * i; j <= maxLimit; j += i) {
                    isPrime[j] = false;
                }
            }
        }
    }
    return primes;
}

int power(int a, int b, int mod) {
    int res = 1;
    a = a % mod;
    while(b > 0){
        if(b & 1){
            res = (res * a) % mod;
        }
        a = (a * a) % mod;
        b >>= 1;
    }
    return res;
}

int inverse(int a, int mod){
    return power(a, mod - 2, mod);
}

///////////////////// JMD solve()///////////////////////////////////////////

int n, m;
vector<int> A, B;
vector<bool> used;

bool dfs(long long sum, int last, int reqVal) {
    if(sum == reqVal)
        return true;
    if(sum > reqVal)
        return false;
    for (int i = last + 1; i < n; i++) {
        if (!used[i]) {
            if(sum == 0) {
                used[i] = true;
                if(dfs(A[i], i, reqVal))
                    return true;
                used[i] = false;
            } else {
                if(A[i] <= sum + 1) {
                    if(sum + A[i] > reqVal)
                        continue;
                    used[i] = true;
                    if(dfs(sum + A[i], i, reqVal))
                        return true;
                    used[i] = false;
                }
            }
        }
    }
    return false;
}

void solve() {
    cin >> n >> m;
    A.resize(n);
    B.resize(m);
    used.assign(n, false);
    long long sumA = 0, sumB = 0;
    for (int i = 0; i < n; i++){
        cin >> A[i];
        sumA += A[i];
    }
    for (int j = 0; j < m; j++){
        cin >> B[j];
        sumB += B[j];
    }
    if(sumA != sumB) {
        cout << "No\n";
        return;
    }
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    for (int j = 0; j < m; j++){
        if (!dfs(0, -1, B[j])) {
            cout << "No\n";
            return;
        }
    }
    cout << "Yes\n";
}


/////////////////////////////////main()/////////////////////////////////////
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int maxLimit = 2e6;
    int testCase = 1;
      // precomputeFactorials(2e5);
         cin >> testCase;
    while (testCase--) solve();
    return 0;
}

Submission (verdict: Accepted):
///////////////// REMARKS ////////////////////////////////////////////
 

// soln ref :: Ambug_Pls_Debug

///////////////// PPD FUNC //////////////////////////////////////////
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx2")
// const long long MOD = 1000000007;
const int N = 2e5 + 2;
const int MAX1 = 100000;
const int MAX3 = 2000000 + 100;
const int MAX2 = 1005, OO = 0x3f3f3f3f;
const int MOD = 1000000007;

#define M_PI 3.14159265358979323846

#define pb push_back
#define yes cout << "Yes\n"
#define no cout << "No\n"
typedef long long ll;

/////////////////////////DEFINED STRUCTS/////////////////////////////
typedef tree
<
    int,
    null_type,
    less<int>,
    rb_tree_tag,
    tree_order_statistics_node_update
> ordered_multiset;

///////////////////////////DEFINED DATA//////////////////////////////

vector<int> fenwickTree(N + 2, 0);

vector<int> fact(MAX1), invFact(MAX1);
int dx[] = {-1, 0, 0, 1};
int dy[] = {0, 1, -1, 0};

////////////////////////////HELPERS//////////////////////////////////
int modPow(int x, int y, int p) {
    int res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}


int mod_inverse(int a, int m) {
    return modPow(a, m - 2, m);
}


int nCr_mod(int n, int r) {
    if (r > n) return 0;
    if (r > n - r) r = n - r;
    int numerator = 1, denominator = 1;
    for (int i = 0; i < r; i++) {
        numerator = (numerator * (n - i)) % MOD;
        denominator = (denominator * (i + 1)) % MOD;
    }
    return (numerator * mod_inverse(denominator, MOD)) % MOD;
}

void precomputeFactorials(int maxN) {
    fact[0] = 1;
    for (int i = 1; i <= maxN; i++) {
        fact[i] = fact[i - 1] * i % MOD;
    }
    invFact[maxN] = modPow(fact[maxN], MOD - 2, MOD);
    for (int i = maxN - 1; i >= 0; i--) {
        invFact[i] = invFact[i + 1] * (i + 1) % MOD;
    }
}

int binomialCoefficient(int n, int k) {
    if (k > n) return 0;
    return fact[n] * invFact[k] % MOD * invFact[n - k] % MOD;
}

int lucas(int n, int k, int p) {
    if (k == 0) return 1;
    int ni = n % p, ki = k % p;
    if (ki > ni) return 0;

    return lucas(n / p, k / p, p) * binomialCoefficient(ni, ki) % p;
}

bool isPrime(int n) {
    if (n <= 1) return false;
    if (n <= 3) return true;
    if (n % 2 == 0 || n % 3 == 0) return false;

    for (int i = 5; i * i <= n; i += 6) {
        if (n % i == 0 || n % (i + 2) == 0) return false;
    }
    return true;
}

int logBase3(int x) {
    return (int)(log(x) / log(3));
}

int maxDivisor(int n) {
    for (int i = 2; i * i <= n; ++i) {
        if (n % i == 0) {
            return n / i;
        }
    }
    return 1;
}

int sumOfDigits(int val) {
    int sum = 0, digit = 0;
    while (val) {
        digit = val % 10;
        sum += digit;
        val /= 10;
    }
    return sum;
}

void updateFenwickTree(int idx, int updateValue, int n) {
    while (idx <= n) {
        fenwickTree[idx] += updateValue;
        idx += idx & -idx;
    }
}

int queryFenwickTree(int idx, int modValue) {
    int res = 0;
    while (idx > 0) {
        res *= fenwickTree[idx] % modValue;
        idx -= idx & -idx;
    }
    return res;
}

void resetFenwickTree(int size) {
    for (int i = 0; i <= size; ++i) {
        fenwickTree[i] = 0;
    }
}

vector<int> generatePrimes(int maxLimit) {
    vector<bool> isPrime(maxLimit + 1, true);
    vector<int> primes;

    isPrime[0] = isPrime[1] = false;
    for (int i = 2; i <= maxLimit; ++i) {
        if (isPrime[i]) {
            primes.push_back(i);
            if ((int)i * i <= maxLimit) {
                for (int j = i * i; j <= maxLimit; j += i) {
                    isPrime[j] = false;
                }
            }
        }
    }
    return primes;
}

int power(int a, int b, int mod) {
    int res = 1;
    a = a % mod;
    while(b > 0){
        if(b & 1){
            res = (res * a) % mod;
        }
        a = (a * a) % mod;
        b >>= 1;
    }
    return res;
}

int inverse(int a, int mod){
    return power(a, mod - 2, mod);
}

///////////////////// JMD solve()///////////////////////////////////////////


void Solve()
{
    int n,m;
    cin>>n>>m;
    vector<int>a(n),b(m);
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<m;i++) cin>>b[i];
    map<int,int>mp;
    priority_queue<int>pq;
    for(int i=0;i<n;i++) mp[a[i]]++;
    for(int i=0;i<m;i++) pq.push(b[i]);
    for(int i=0;i<2*n-m;i++)
    {
        if(pq.empty())
        {
            cout<<"NO"<<endl;
            return;
        }
        int x=pq.top();
        pq.pop();
        if(mp[x]==0)
        {
            int val=x/2;
            int val1=x-val;
            pq.push(val);
            pq.push(val1);
        }
        else mp[x]--;
    }
    cout<<(pq.empty()?"YES":"NO")<<endl;
}

/////////////////////////////////main()/////////////////////////////////////
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int maxLimit = 2e6;
    int testCase = 1;
      // precomputeFactorials(2e5);
         cin >> testCase;
    while (testCase--) Solve();
    return 0;
}