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

Solution 1 (runtime: 796 ms):
#include<bits/stdc++.h>
#define ll long long
using namespace std;

bool findEl(multiset <ll> &ms, ll val){
    if (val == 1){
        auto pt = ms.find(val);
        if (pt == ms.end()){
            return false;
        }
        else{
            ms.erase(pt);
            return true;
        }
    } 
    auto pt = ms.find(val);
    if (pt == ms.end()){
        //could not find val
        return findEl(ms,val/2)&&findEl(ms,val/2 + (val&1));
    }else{
        ms.erase(pt);
        return true;
    }

}


int main() {

    int t;
    cin>>t;
    while(t--){
        int n,m;
        cin>>n>>m;
        
        multiset <ll> m1,m2;

        for (int i = 0; i<n; i++){
            ll x;cin>>x;
            m1.insert(x);
        }
        for (int i = 0; i<m; i++){
            ll x;
            cin>>x;
            auto pt = m1.find(x);
            if (pt != m1.end()){
                m1.erase(pt);
            }else{
                m2.insert(x);
            }
        }

        bool bad = false;

        for (auto it = m2.begin(); it!= m2.end();){
            if (findEl(m1,*it)){
                auto x = it;
                it = m2.erase(x);
            }else{
                bad = true;
                break;
            }
        } 

        if (m1.size() == 0 && m2.size() == 0 && !bad){
            cout<<"yes"<<endl;
        }else{
            cout<<"no"<<endl;
        }
    }

    return 0;
}

Solution 2 (runtime: 984 ms):
#include <bits/stdc++.h>
using namespace std;

void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) {cerr << ' ' << H;dbg_out(T...);}
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)

#define ll long long
#define int ll
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef pair<int, int> pii;
typedef vector<int> vi;

// #include "debugging.h"

#define mod 1000000007

bool findTarget(vector<int>&a, map<int,int>&feq, int ptr, int curr, int sum, int target){
    // dbg(sum, target, a, ptr);
    if (sum == target) return true;
    if (sum > target || ptr >= a.size() || (curr >0 && a[ptr]-curr > 1)) return false;

    if (feq[a[ptr]]>0){
    feq[a[ptr]]--;
    if (findTarget(a, feq, ptr, curr+a[ptr], sum+a[ptr], target)) return true;
    if (findTarget(a, feq, ptr+1, sum+a[ptr], sum+a[ptr], target)) return true;
    feq[a[ptr]]++;
    }

    if (findTarget(a, feq, ptr+1, curr, sum, target)) return true;
    

    return false;
}

void solve()
{
    int n,m;
    cin >> n >> m ;
    vi a(n),b(m);
    rep(i,0,n) cin >> a[i];
    rep(i,0,m) cin >> b[i];

    map<int,int> feq;
    rep(i,0,n) feq[a[i]]++;

    sort(all(a));
    sort(all(b));

    vi set_a = {a[0]};
    rep(i,1,n) {
        if (a[i] != set_a[set_a.size()-1]) set_a.push_back(a[i]);
    }

    // dbg(set_a);
    // dbg(b);

    int ptr = 0;
    rep(i,0,m){
        while(ptr < set_a.size() && feq[set_a[ptr]] == 0) ptr++;
        if (ptr >= n) {cout << "No\n"; return;}
        if (feq.find(b[i]) != feq.end() && feq[b[i]] > 0) {feq[b[i]]--; continue;}
        if (b[i] == set_a[ptr]) {
            if (feq[set_a[ptr]] == 0) {cout << "No\n"; return;}
            feq[set_a[ptr]]--;
            // ptr++;
        } else if (b[i] < set_a[ptr]) {cout << "No\n"; return;}
        else {
            // feq[set_a[ptr]]--;
            // dbg(set_a[ptr]);
            if (!findTarget(set_a, feq, ptr, 0, 0, b[i])){
                cout << "No\n"; return;
            }
            // ptr++;
        }
    } 

    rep(i,0,set_a.size()) if (feq[set_a[i]] != 0) {cout << "No\n"; return;}
    cout << "Yes\n";
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll test=1;
    cin>>test;

    while(test--)
    {
        solve();
    }
    return 0;
}