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

Previous submission (verdict: Time limit exceeded on test 3):
// Be Still, and Know That I Am God.
// Psalms 46:10
#include <bits/stdc++.h>
#include <iostream>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define int long long
#define ld long double
#define fr first
#define sc second
#define pii pair<int, int>
#define tii tuple<int, int, int>
#define pb push_back
#define all(v) v.begin(), v.end()
using namespace std;
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
 
//Euler's
// const int MOD=1e9+7;
const int MOD=998244353;
 
int fastexpo(int a, int b){
    if(b==0) return 1;
    int ret = (fastexpo(a,b/2)%MOD);
    if(b%2){
        return (((ret*ret)%MOD*a%MOD)%MOD);
    }
    else{
        return ((ret*ret)%MOD);
    }
}
 
//sort by second element
bool comp(pair<int,int> &a, pair<int,int> &b){
    return (a.second<b.second);
}
bool sortbyCond(const pair<double, int>& a,
                const pair<double, int>& b)
{
    if (a.first != b.first)
        return (a.first < b.first);
    else
       return (a.second < b.second);
}
 
//Interactive
// char ask(int a, int b, int c, int d){
//     cout<<"? "<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
//     char s; cin>>s;
//     return s;
// }
 
 
 
const int INF=1e18+2;
 
 
// int spf[N];
// void sieve()
// {
//     int MAXN = N;
//     spf[1] = 1;
//     for (int i=2; i<MAXN; i++){
//         spf[i] = i;
//     }
 
//     for (int i=4; i<MAXN; i+=2){
//         spf[i] = 2;
//     }
 
//     for (int i=3; i*i<MAXN; i++)
//     {
//         if (spf[i] == i)
//         {
//             for (int j=i*i; j<MAXN; j+=i){
 
//                 if (spf[j]==j)
//                     spf[j] = i;
//             }
//         }
//     }
// }
// int tree[N*4];
// int treemn[N*4];
// int treemx[N*4];
 
 
// void build(int l, int r, int idx) {
//     if (l == r) {tree[idx] = arr[l]; return;}
//     int mid = (l+r) / 2;
//     build(l, mid, idx*2);
//     build(mid+1, r, idx*2+1);
//     tree[idx] = max(tree[idx*2], tree[idx*2+1]);
// }
 
// int query(int l, int r, int from, int to, int idx) {
//     if (l > to or r < from) return INT_MIN;
//     if (l >= from and r <= to) return tree[idx];
//     int mid = (l+r) / 2;
//     return max(query(l, mid, from, to, idx*2), query(mid+1, r, from, to, idx*2+1));
// }
 
// void buildmin(int l, int r, int idx) {
//     if (l == r) {treemn[idx] = arr[l]; return;}
//     int mid = (l+r) / 2;
//     buildmin(l, mid, idx*2);
//     buildmin(mid+1, r, idx*2+1);
//     treemn[idx] = min(treemn[idx*2], treemn[idx*2+1]);
// }
 
// int querymin(int l, int r, int from, int to, int idx) {
//     if (l > to or r < from) return INT_MAX;
//     if (l >= from and r <= to) return treemn[idx];
//     int mid = (l+r) / 2;
//     return min(querymin(l, mid, from, to, idx*2), querymin(mid+1, r, from, to, idx*2+1));
// }

const int N=1e5+2;


bool sortpsquared(pair<pii,pii>&a,pair<pii,pii>&b){
    return a.first.first>b.first.first;
}

bool sortend(pair<pii,int> &a, pair<pii,int> &b){
    return a.second<b.second;
}

void solve(){
    // freopen("teamwork.in", "r", stdin);
	// // the following line creates/overwrites the output file
	// freopen("teamwork.out", "w", stdout);
    int n,k; cin>>n>>k;
    multiset<int>arr;
    multiset<int>pleasebro;
    int sum=0;
    int tot=0;
    for(int i=0;i<n;i++){
        int x; cin>>x;
        arr.insert(x);
        sum+=x;
        pleasebro.insert(x);
    }
    multiset<int>ms;
    for(int i=0;i<k;i++){
        int x; cin>>x;
        ms.insert(x);
        tot+=x;
    }
    if(sum!=tot){
        cout<<"No"<<endl;
        return;
    }
    // int temp = n-k;
    // for(auto x:ms){
    //     cout<<x<<" ";
    // }
    // cout<<endl;
    // cout<<mp[9]<<endl;
    for(auto x:pleasebro){
        if(ms.find(x)!=ms.end()){
            ms.erase(ms.find(x));
            arr.erase(arr.find(x));
        }
    }

    // for(auto x:ms){
    //     cout<<x<<" ";
    // }
    // cout<<endl;
    // for(auto x:arr){
    //     cout<<x<<" ";
    // }
    // cout<<endl;
    int cnt=0;
    int store, store1;
    store=arr.size();
    store1=ms.size();
    while(cnt!=store-store1){
        int cur = *ms.rbegin();
        // cout<<cur<<endl;
        if(arr.find(cur)!=arr.end()){
            ms.erase(--ms.end());
            arr.erase(arr.find(cur));
            cnt++;
            // cout<<"yes"<<endl;
        }
        else{
            // temp--;
            // cnt++;
            ms.erase(--ms.end());
            ms.insert((cur+1)/2);
            ms.insert(cur/2);
        }
    }
    // for(int i=0;i<n;i++){
    //     cout<<mp[arr[i]]<<" ";
    // }
    // cout<<endl;
    // if(arr.size()==0 and ms.size()==0){
    //     cout<<"Yes"<<endl;
    // }
    // sort(arr,arr+n);
    vector<int>v;
    for(auto x:arr){
        v.push_back(x);
    }
    // for(auto x:v){
    //     cout<<x<<" ";
    // }
    // cout<<endl;
    // for(auto x:ms){
    //     cout<<x<<" ";
    // }
    // cout<<endl;
    // cout<<v.size()<<" "<<ms.size()<<endl;
    if(v.size()!=ms.size()){
        cout<<"No"<<endl;
        return;
    }
    int ind=0;
    for(auto x:ms){
        if(v[ind]!=x){
            cout<<"No"<<endl;
            return;
        }
        ind++;
    }
    cout<<"Yes"<<endl;
}
 
signed main()
{
    ios_base::sync_with_stdio(false);
    cout.tie(NULL);
    cin.tie(NULL);
    int tc; 
    // sieve();
    tc=1;
    cin>> tc;
    
    while (tc--) solve();
}

Submission (verdict: Wrong answer on test 3):
// Be Still, and Know That I Am God.
// Psalms 46:10
#include <bits/stdc++.h>
#include <iostream>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define int long long
#define ld long double
#define fr first
#define sc second
#define pii pair<int, int>
#define tii tuple<int, int, int>
#define pb push_back
#define all(v) v.begin(), v.end()
using namespace std;
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
 
//Euler's
// const int MOD=1e9+7;
const int MOD=998244353;
 
int fastexpo(int a, int b){
    if(b==0) return 1;
    int ret = (fastexpo(a,b/2)%MOD);
    if(b%2){
        return (((ret*ret)%MOD*a%MOD)%MOD);
    }
    else{
        return ((ret*ret)%MOD);
    }
}
 
//sort by second element
bool comp(pair<int,int> &a, pair<int,int> &b){
    return (a.second<b.second);
}
bool sortbyCond(const pair<double, int>& a,
                const pair<double, int>& b)
{
    if (a.first != b.first)
        return (a.first < b.first);
    else
       return (a.second < b.second);
}
 
//Interactive
// char ask(int a, int b, int c, int d){
//     cout<<"? "<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
//     char s; cin>>s;
//     return s;
// }
 
 
 
const int INF=1e18+2;
 
 
// int spf[N];
// void sieve()
// {
//     int MAXN = N;
//     spf[1] = 1;
//     for (int i=2; i<MAXN; i++){
//         spf[i] = i;
//     }
 
//     for (int i=4; i<MAXN; i+=2){
//         spf[i] = 2;
//     }
 
//     for (int i=3; i*i<MAXN; i++)
//     {
//         if (spf[i] == i)
//         {
//             for (int j=i*i; j<MAXN; j+=i){
 
//                 if (spf[j]==j)
//                     spf[j] = i;
//             }
//         }
//     }
// }
// int tree[N*4];
// int treemn[N*4];
// int treemx[N*4];
 
 
// void build(int l, int r, int idx) {
//     if (l == r) {tree[idx] = arr[l]; return;}
//     int mid = (l+r) / 2;
//     build(l, mid, idx*2);
//     build(mid+1, r, idx*2+1);
//     tree[idx] = max(tree[idx*2], tree[idx*2+1]);
// }
 
// int query(int l, int r, int from, int to, int idx) {
//     if (l > to or r < from) return INT_MIN;
//     if (l >= from and r <= to) return tree[idx];
//     int mid = (l+r) / 2;
//     return max(query(l, mid, from, to, idx*2), query(mid+1, r, from, to, idx*2+1));
// }
 
// void buildmin(int l, int r, int idx) {
//     if (l == r) {treemn[idx] = arr[l]; return;}
//     int mid = (l+r) / 2;
//     buildmin(l, mid, idx*2);
//     buildmin(mid+1, r, idx*2+1);
//     treemn[idx] = min(treemn[idx*2], treemn[idx*2+1]);
// }
 
// int querymin(int l, int r, int from, int to, int idx) {
//     if (l > to or r < from) return INT_MAX;
//     if (l >= from and r <= to) return treemn[idx];
//     int mid = (l+r) / 2;
//     return min(querymin(l, mid, from, to, idx*2), querymin(mid+1, r, from, to, idx*2+1));
// }

const int N=1e5+2;


bool sortpsquared(pair<pii,pii>&a,pair<pii,pii>&b){
    return a.first.first>b.first.first;
}

bool sortend(pair<pii,int> &a, pair<pii,int> &b){
    return a.second<b.second;
}

void solve(){
    // freopen("teamwork.in", "r", stdin);
	// // the following line creates/overwrites the output file
	// freopen("teamwork.out", "w", stdout);
    int n,k; cin>>n>>k;
    multiset<int>arr;
    multiset<int>pleasebro;
    int sum=0;
    int tot=0;
    for(int i=0;i<n;i++){
        int x; cin>>x;
        arr.insert(x);
        sum+=x;
        pleasebro.insert(x);
    }
    multiset<int>ms;
    for(int i=0;i<k;i++){
        int x; cin>>x;
        ms.insert(x);
        tot+=x;
    }
    if(sum!=tot){
        cout<<"No"<<endl;
        return;
    }
    // int temp = n-k;
    // for(auto x:ms){
    //     cout<<x<<" ";
    // }
    // cout<<endl;
    // cout<<mp[9]<<endl;
    for(auto x:pleasebro){
        if(ms.find(x)!=ms.end()){
            ms.erase(ms.find(x));
            arr.erase(arr.find(x));
        }
    }

    // for(auto x:ms){
    //     cout<<x<<" ";
    // }
    // cout<<endl;
    // for(auto x:arr){
    //     cout<<x<<" ";
    // }
    // cout<<endl;
    int cnt=0;
    int store, store1;
    store=arr.size();
    store1=ms.size();

    // i think the issue here was the fact that we didn't consider
    // the fact that this while loop might not stop
    // because previously you will just keep splitting the number
    // until you found a match
    // but what if there are no match
    while(cnt!=store-store1 && ms.size() < arr.size()){
        int cur = *ms.rbegin();
        // cout<<cur<<endl;

        // *arr.rbegin() > cur -> "No"
        // *arr.rbegin() == cur
        if(*arr.rbegin()==cur){
            ms.erase(--ms.end());
            arr.erase(--arr.end());
            cnt++;
            // cout<<"yes"<<endl;
        }
        // this else will also receive *arr.rebgin() > cur
        // gota add another else if for this case
        else if(*arr.rbegin()>cur){
            cout<<"No"<<endl;
            return;
        }
        else{
            // temp--;
            // cnt++;
            ms.erase(--ms.end());
            ms.insert((cur+1)/2);
            ms.insert(cur/2);
        }
    }
    // for(int i=0;i<n;i++){
    //     cout<<mp[arr[i]]<<" ";
    // }
    // cout<<endl;
    // if(arr.size()==0 and ms.size()==0){
    //     cout<<"Yes"<<endl;
    // }
    // sort(arr,arr+n);
    vector<int>v;
    for(auto x:arr){
        v.push_back(x);
    }
    // for(auto x:v){
    //     cout<<x<<" ";
    // }
    // cout<<endl;
    // for(auto x:ms){
    //     cout<<x<<" ";
    // }
    // cout<<endl;
    // cout<<v.size()<<" "<<ms.size()<<endl;
    if(v.size()!=ms.size()){
        cout<<"No"<<endl;
        return;
    }
    int ind=0;
    for(auto x:ms){
        if(v[ind]!=x){
            cout<<"No"<<endl;
            return;
        }
        ind++;
    }
    cout<<"Yes"<<endl;
}
 
signed main()
{
    ios_base::sync_with_stdio(false);
    cout.tie(NULL);
    cin.tie(NULL);
    int tc; 
    // sieve();
    tc=1;
    cin>> tc;
    
    while (tc--) solve();
}