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

Solution 1 (runtime: 296 ms):
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define YES cout<<"YES\n";
#define NO cout<<"NO\n";
#define endl "\n"
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
const int N=1e9+7;
const int N1=1e6+3;
signed main(){IOS;
    int t;cin>>t;
    while(t--){
        int n,m;cin>>n>>m;int a[n+1],b[m+1];
        map<int,int>mp;int sum1=0,sum2=0;
        for(int i=1;i<=n;i++){
            cin>>a[i];mp[a[i]]++;sum1+=a[i];
        }
        for(int i=1;i<=m;i++)cin>>b[i],sum2+=b[i];
        if(sum1!=sum2){
            cout<<"No"<<endl;continue;
        }
        sort(b+1,b+m+1);
        auto dfs=[&](auto &dfs,int x)->int{
            if(mp[x]){
               mp[x]--;return 1;
            }
            if(!x)return 0;
            if(x%2==0)return dfs(dfs,x/2)&&dfs(dfs,x/2);
            else return dfs(dfs,x/2)&&dfs(dfs,x/2+1);
        };
        int flag=1;
        for(int i=m;i>=1;i--){
            if(mp[b[i]])mp[b[i]]--;
            else{
                flag=dfs(dfs,b[i]);
                if(!flag)break;
            }
        }
        if(flag)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}
/*******************************************
............................................
............................................
............................................
............................................
.............................1ffLf1.........
............................GGGGGGGC........
....................8CCCftCCCCC1;LLG,.......
..................:CC8CCC.CCCCCCii..........
.................CC88CCCC.CCCCCCC...........
................CC88CCCCC .8.:8CCC..........
................888 CCCCC.88888G;;,.........
,................888CC88.888888888,.........
:::...............CCC888.888888888..........
:::::............Gi1tC8f888888C88,..........
:::::::,........111tttfffffLG8888...........
:::::::::,....ii111ttttttfffttG.............
::::::::::::i111tttffffffffffttt............
::::::::::11tttttfff....fffffftt ...........
..:::::::1Lf1tff,..........fffff1...........
....,:::iiftG::::::.........,LLGtL..........
::::::;:i11t:;;;;;;::,,,,,,,,, f1ii,::,,,,,,
::::::::i11t:::::::::::::::::::f111:::::::::
::::::::111:::::::::::::::::::::t111::::::::
:::::::i1if::::::,,,,,,,,,,,,,,:i111::::::,:
,,,,,::,8G,,,,,,,,,,,,,,,,,,,,,,,tL1:,,,,,,,
,,,,,,:LGL;,,,,,,,,,,,,,,,,,,,,,,,CLf,,,,,,,
,,,,,;LGGG,,,,:,,,,,,,,,,,,,,,,,,,LGCG,,,,,,
*******************************************/

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

const int n_max = 1 * 1e5 + 7;




void solve(){
    int n, m;
    cin >> n >> m;
    priority_queue<int> b_elements;
    multiset<int> a_elements;
    int sum = 0;
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        sum += a;
        a_elements.insert(a);
    }
    for(int i = 0; i < m; i++){
        int a;
        cin >> a;
        sum -= a;
        b_elements.push(a);
    }


    bool ans = true;
    if(sum != 0){
        ans = false;
    }
    int counter = n - m + 5;
    while(ans and !b_elements.empty()){
        auto b = b_elements.top();
        b_elements.pop();
        if(b == 0){
            ans = false;
            break;
        }
        if(a_elements.find(b) == a_elements.end()){
            if(b == 1){
                ans = false;
                break;
            }
            counter--;
            if(counter == 0){
                ans = false;
                break;
            }

            b_elements.push(b/2);
            b_elements.push((b+1)/2);
        }else{
            auto a = a_elements.find(b);
            a_elements.erase(a);
        }
    }
    if(!a_elements.empty()){
        ans = false;
    }

    if(ans){
        cout << "YES\n";
    }else{
        cout << "NO\n";
    }

    
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    cin >> t;
    for(int i = 0; i < t; i++){
        solve();
    }
    return 0;
}