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

Previous submission (verdict: Wrong answer on test 3):
#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;

//  

// // //   

// // // // ..Optimizations

// // // //  

 // #pragma GCC optimize ("Ofast")

     // #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

    // #pragma GCC target ("sse,sse2,mmx")

    // #pragma GCC optimize ("-ffloat-store")

 // #pragma GCC optimize("O3,unroll-loops")

// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

 // #pragma GCC optimize("Ofast,unroll-loops")

// #pragma GCC target("avx2,tune=native")

// #pragma GCC optimize ("O3")

// #pragma GCC optimize ("unroll-loops")

// #pragma GCC target ("avx2")

// #pragma GCC optimize ("Os")

// #pragma GCC optimize("Ofast")

// #pragma GCC optimize("fast-math")

// #define _FORTIFY_SOURCE 0 

// #pragma GCC optimize("no-stack-protector")  

#define MOD 1000000007

#define MOD1 998244353

#define INF 1e14

 #define nline "\n"

#define pb push_back

 #define ppb pop_back

 #define mp make_pair

 #define ff first

 #define ss second

 #define PI 3.141592653589793238462

 #define set_bits __builtin_popcountll

 #define sz(x) ((int)(x).size())

 #define all(x) (x).begin(), (x).end()

 

 typedef long long ll;

 typedef unsigned long long ull;

 typedef long double lld;

// //template <typename Type, typename ComparatorFn = less<Type>>

// // using oset = tree<Type, null_type, ComparatorFn, rb_tree_tag, tree_order_statistics_node_update>;

// //  

// // template<typename Type, typename ComparatorFn>

// // bool oset_erase(oset<Type, ComparatorFn> &st, Type val) {

	// // if (st.lower_bound(val) == st.upper_bound(val)) return false;

	// // st.erase(st.find_by_order(st.order_of_key(val)));

	// // return true;

// // }

typedef tree<long long, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key

 // methods -> *find_by_order, order_of_key

// comparators -> less, less_equal, greater, greater_equal

#ifndef ONLINE_JUDGE

#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;

#else

#define debug(x)

#endif

 

void _print(ll t) {cerr << t;}

void _print(int t) {cerr << t;}

void _print(string t) {cerr << t;}

void _print(char t) {cerr << t;}

void _print(lld t) {cerr << t;}

void _print(double t) {cerr << t;}

void _print(ull t) {cerr << t;}

  

#define f0r(a, b) for (long long a = 0; a < (b); a++)

#define f1r(a, b, c) for (long long a = (b); a < (c); a++)

#define f0rd(a, b) for (long long a = (b); a >= 0; a--)

#define f1rd(a, b, c) for (long long a = (b); a >= (c); a--)

template <class T, class V> void _print(pair <T, V> p);

template <class T> void _print(vector <T> v);

template <class T> void _print(set <T> v);

template <class T, class V> void _print(map <T, V> v);

template <class T> void _print(multiset <T> v);

template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";}

template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}

template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}

template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}

template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}

#define int long long

#define ll long long

ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;}

ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;}

ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;}

//ll mminv(ll a, ll b) {ll arr[3]; extendgcd(a, b, arr); return mod_add(arr[0], 0, b);} //for non prime b

//ll mminvprime(ll a, ll b) {return expo(a, b - 2, b);}

bool revsort(ll a, ll b) {return a > b;}

//ll mod_div(ll a, ll b, ll m) {a = a % m; b = b % m; return (mod_mul(a, mminvprime(b, m), m) + m) % m;}  //only for prime m

 #define endl "\n" 

//b,k, ointime ,outim,lca, kth parent, bfs, dfs, subtree ,lvl ,euler tour etc

// dp on trees , rerootinmg , precomputation   

//shortes path, bfs,0-1 bfs, dfs, mutisrc bfs, adding edges,

  const int M=1000000007; 

        long long mod(long long x){

            return ((x%M + M)%M);

        }

        long long add(long long a, long long b){

            return mod(mod(a)+mod(b));

        }

        long long mul(long long a, long long b){

            return mod(mod(a)*mod(b));

        }

                

 		bool cmp(pair<int,int>a,pair<int,int>b){

		if(a.ss!=b.ss)return a.ff<b.ff;

		return a.ss<b.ss;

		}

	

	

void solve(){

	int n;

	cin>>n;

	int m;

	cin>>m;

	vector<int>a,b;

	map<int,int>mp;

	multiset<int>a1,b1;

	for(int i=0;i<n;i++){

		int x;

		cin>>x;

		a.pb(x);

		a1.insert(x);

	}

for(int i=0;i<m;i++){

		int x;

		cin>>x;

		b.pb(x);

		b1.insert(x);

	}

	for(int i=0;i<n;i++){

		if(b1.find(a[i])!=b1.end()){

			b1.erase(b1.find(a[i]));

			a1.erase(a1.find(a[i]));

		}

	}

	int j=n-m;

	for(auto &x:a1){

		mp[x]++;

	}

	if(b1.size()==0 && a1.size()==0){

		cout<<"yes"<<endl;

		return;

	}

	if(b1.size()==0 && a1.size()!=0){

		cout<<"NO"<<endl;

		return;

	}

	debug(a1);

	debug(b1);

	while(a1.size()){

		int h=0;

		multiset<int>b11;

	for(auto &x:b1){

		int g=x;

		g=g>>1;

	

		if(j<=0){

			break;

		}

		int g1=g|1;

		int p1=x/2;

		debug(x);

		int p2=p1+(x%2);

			debug(p1);

			debug(p2);

		if(a1.find(p1)!=a1.end()){

			a1.erase(a1.find(p1));

			h++;

		}else{

			if(p1==1){

				cout<<"No"<<endl;

				return;

			}debug(x);

			b1.insert(p1);

		}

		if(a1.find(p2)!=a1.end()){

			h++;

			a1.erase(a1.find(p2));

			//b1.erase(b1.find(p2));

		}else{

			if(p2==1){

				cout<<"No"<<endl;

				return;

			}debug(x);

			b1.insert(p2);

		}

		j--;

		//b1.erase(b1.find(x));

		}

		if(j<=0)break;

		//b=b11;

		if(b.size()==0 || h==0){

			break;

		}

		auto it=*b.end();

		--it;

		if((it)==1LL)break;

		}

		if(a1.size()){

			cout<<"no"<<endl;

			return;

		}

		// int cnt=mp[g];

		// int z=0;

		// if(2*g==x){

		// if(cnt>0){

			// mp[g]--;

			// cnt--;

			// z++;

		// }

		// if(cnt>0){

			// mp[g]--;

			// cnt--;

			// z++;

		// }

		// }else if()

		// if(z<2){

			// cnt=mp[g1];

		// if(cnt>0){

			// mp[g1]--;

			// cnt--;

			// z++;

		// }

		// if(z<2){

		// if(cnt>0){

			// mp[g1]--;

			// cnt--;

			// z++;

		// }

		// }

		// }

		// debug(x);

		// if(z<2){

			// cout<<"No"<<endl;

			// return;

		// }

	// }

	cout<<"Yes"<<endl;

}

		

signed main(){

	ios::sync_with_stdio(false);

	cin.tie(0);cout.tie(0);

	int t=1;

	cin>>t;

	while(t--){

		

	solve();

}



}

Submission (verdict: Wrong answer on test 3):
#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;

//  

// // //   

// // // // ..Optimizations

// // // //  

 // #pragma GCC optimize ("Ofast")

     // #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

    // #pragma GCC target ("sse,sse2,mmx")

    // #pragma GCC optimize ("-ffloat-store")

 // #pragma GCC optimize("O3,unroll-loops")

// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

 // #pragma GCC optimize("Ofast,unroll-loops")

// #pragma GCC target("avx2,tune=native")

// #pragma GCC optimize ("O3")

// #pragma GCC optimize ("unroll-loops")

// #pragma GCC target ("avx2")

// #pragma GCC optimize ("Os")

// #pragma GCC optimize("Ofast")

// #pragma GCC optimize("fast-math")

// #define _FORTIFY_SOURCE 0 

// #pragma GCC optimize("no-stack-protector")  

#define MOD 1000000007

#define MOD1 998244353

#define INF 1e14

 #define nline "\n"

#define pb push_back

 #define ppb pop_back

 #define mp make_pair

 #define ff first

 #define ss second

 #define PI 3.141592653589793238462

 #define set_bits __builtin_popcountll

 #define sz(x) ((int)(x).size())

 #define all(x) (x).begin(), (x).end()

 

 typedef long long ll;

 typedef unsigned long long ull;

 typedef long double lld;

// //template <typename Type, typename ComparatorFn = less<Type>>

// // using oset = tree<Type, null_type, ComparatorFn, rb_tree_tag, tree_order_statistics_node_update>;

// //  

// // template<typename Type, typename ComparatorFn>

// // bool oset_erase(oset<Type, ComparatorFn> &st, Type val) {

	// // if (st.lower_bound(val) == st.upper_bound(val)) return false;

	// // st.erase(st.find_by_order(st.order_of_key(val)));

	// // return true;

// // }

typedef tree<long long, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key

 // methods -> *find_by_order, order_of_key

// comparators -> less, less_equal, greater, greater_equal

#ifndef ONLINE_JUDGE

#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;

#else

#define debug(x)

#endif

 

void _print(ll t) {cerr << t;}

void _print(int t) {cerr << t;}

void _print(string t) {cerr << t;}

void _print(char t) {cerr << t;}

void _print(lld t) {cerr << t;}

void _print(double t) {cerr << t;}

void _print(ull t) {cerr << t;}

  

#define f0r(a, b) for (long long a = 0; a < (b); a++)

#define f1r(a, b, c) for (long long a = (b); a < (c); a++)

#define f0rd(a, b) for (long long a = (b); a >= 0; a--)

#define f1rd(a, b, c) for (long long a = (b); a >= (c); a--)

template <class T, class V> void _print(pair <T, V> p);

template <class T> void _print(vector <T> v);

template <class T> void _print(set <T> v);

template <class T, class V> void _print(map <T, V> v);

template <class T> void _print(multiset <T> v);

template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";}

template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}

template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}

template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}

template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}

#define int long long

#define ll long long

ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;}

ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;}

ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;}

//ll mminv(ll a, ll b) {ll arr[3]; extendgcd(a, b, arr); return mod_add(arr[0], 0, b);} //for non prime b

//ll mminvprime(ll a, ll b) {return expo(a, b - 2, b);}

bool revsort(ll a, ll b) {return a > b;}

//ll mod_div(ll a, ll b, ll m) {a = a % m; b = b % m; return (mod_mul(a, mminvprime(b, m), m) + m) % m;}  //only for prime m

 #define endl "\n" 

//b,k, ointime ,outim,lca, kth parent, bfs, dfs, subtree ,lvl ,euler tour etc

// dp on trees , rerootinmg , precomputation   

//shortes path, bfs,0-1 bfs, dfs, mutisrc bfs, adding edges,

  const int M=1000000007; 

        long long mod(long long x){

            return ((x%M + M)%M);

        }

        long long add(long long a, long long b){

            return mod(mod(a)+mod(b));

        }

        long long mul(long long a, long long b){

            return mod(mod(a)*mod(b));

        }

                

 		bool cmp(pair<int,int>a,pair<int,int>b){

		if(a.ss!=b.ss)return a.ff<b.ff;

		return a.ss<b.ss;

		}

	

	

void solve(){

	int n;

	cin>>n;

	int m;

	cin>>m;

	vector<int>a,b;

	map<int,int>mp;

	multiset<int>a1,b1;

	for(int i=0;i<n;i++){

		int x;

		cin>>x;

		a.pb(x);

		a1.insert(x);

	}

for(int i=0;i<m;i++){

		int x;

		cin>>x;

		b.pb(x);

		b1.insert(x);

	}

	for(int i=0;i<n;i++){

		if(b1.find(a[i])!=b1.end()){

			b1.erase(b1.find(a[i]));

			a1.erase(a1.find(a[i]));

		}

	}

	while(a1.size() && b1.size()){

		if(b1.size()>a1.size() || *a.begin()>*b.begin()){

			break;

		}else if(a1.find(*b1.begin())!=a1.end()){

			a1.erase(a1.find(*b1.begin()));

			b1.erase(b1.begin());

		}else{

			int z=*b1.begin();

			b1.erase(b1.begin());

			b1.insert(z/2);

			b1.insert((z+1)/2);

		}

	}

	if(a1.size()==0){

		cout<<"yes"<<endl;

		return;

	}

	cout<<"No"<<endl;

}

		

signed main(){

	ios::sync_with_stdio(false);

	cin.tie(0);cout.tie(0);

	int t=1;

	cin>>t;

	while(t--){

		

	solve();

}



}