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

Solution 1 (runtime: 484 ms):

/*
██╗  ██╗███████╗████████╗██████╗  ██████╗ ███████╗
██║ ██╔╝██╔════╝╚══██╔══╝██╔══██╗██╔═══██╗██╔════╝
█████╔╝ █████╗     ██║   ██████╔╝██║   ██║███████╗
██╔═██╗ ██╔══╝     ██║   ██╔══██╗██║   ██║╚════██║
██║  ██╗███████╗   ██║   ██║  ██║╚██████╔╝███████║
╚═╝  ╚═╝╚══════╝   ╚═╝   ╚═╝  ╚═╝ ╚═════╝ ╚══════╝

*/


#include<bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
using namespace chrono;

//debugging stuff
#ifndef ONLINE_JUDGE
#include <C:\Users\HP\OneDrive\Desktop\CP\debug.h>

#else
#define debug(x...)
#endif


#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int> , rb_tree_tag, tree_order_statistics_node_update> o_set;
/*
    s.find_by_order(k): It returns to an iterator to the kth element (counting from zero) in the set s
	s.order_of_key(k) : It returns to the number of items that are strictly smaller than our item k
*/
//multiordered_set , helper_fun : https://github.com/vekariyasagar54/CP/blob/main/GenFun.md
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> mo_set;

#define fastio()        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD             1000000007
#define inf             1e18
#define pb              push_back
#define ppb             pop_back
#define mp              make_pair
#define ff              first
#define ss              second
#define PI              3.141592653589793238462
#define sz(x)           ((int)(x).size())
#define all(x)          (x).begin(), (x).end()
#define forf(n , ch)    for(long long ch = 0 ; ch < (n) ; ch++)
#define forr(n , ch)    for(long long ch = (n) ; ch >= 0 ; ch--)
#define for0(n,i)       for(long long i = 0; i < (int)(n); ++i)
#define for1(n,i)       for(long long i = 1; i <= (int)(n); ++i)
#define forc(i,l,r)     for(long long i = (int)(l); i <= (int)(r); ++i)
#define min3(a,b,c)     min(c, min(a, b))
#define min4(a,b,c,d)   min(d, min(c, min(a, b)))
#define inp(n,arr)      for(int __i = 0; __i < n ; __i++) cin >> arr[__i]
#define dbg(arr)        for(auto &i : arr) cout<<i<<" "
#define yes             cout<<"YES\n"
#define no              cout<<"NO\n"
#define rtn             return
#define lb 				lower_bound
#define ub 				upper_bound
#define nwl             cout<<"\n"


//data-type
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
using str = string;

//int container
typedef vector<int>     vi;
typedef vector<vi>      vvi;
typedef pair<int, int>   pii;
typedef vector<pii>     vii;


//ll container
typedef vector<ll>      vl;
typedef vector<vl>      vvl;
typedef pair<ll, ll>     pll;
typedef vector<pll>     vll;

//bool container
typedef vector<bool>    vb;
typedef vector<vb>      vvb;

//string container
typedef vector<str>     vs;

//Min Max heaps
typedef priority_queue<pair<ll, ll> , vector<pair<ll, ll>>, greater<pair<ll, ll>>>  pqpll;
typedef priority_queue<ll , vector<ll>, greater<ll>>  pqll;

typedef priority_queue<pair<ll, ll>>  mxpqpll;
typedef priority_queue<ll>  mxpqll;

/*---------------------------------------------------------------------------------------------------------------------------*/
ll gcd(ll a, ll b) {if (b > a) {return gcd(b, a);} if (b == 0) {return a;} return gcd(b, a % b);}
ll expo(ll a, ll b, ll mod) {ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;}
void extendgcd(ll a, ll b, ll*v) {if (b == 0) {v[0] = 1; v[1] = 0; v[2] = a; return ;} extendgcd(b, a % b, v); ll x = v[1]; v[1] = v[0] - v[1] * (a / b); v[0] = x; return;} //pass an arry of size1 3
ll mminv(ll a, ll b) {ll arr[3]; extendgcd(a, b, arr); return arr[0];} //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 combination(ll n, ll r, ll m, ll *fact, ll *ifact) {ll val1 = fact[n]; ll val2 = ifact[n - r]; ll val3 = ifact[r]; return (((val1 * val2) % m) * val3) % m;}
vector<ll> sieve(int n) {int*arr = new int[n + 1](); vector<ll> vect; for (int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for (int j = 2 * i; j <= n; j += i)arr[j] = 1;} return vect;}
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 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
ll cdiv(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); } // divide a by b rounded up
ll fdiv(ll a, ll b) { return a / b - ((a ^ b) < 0 && a % b); } // divide a by b rounded down
ll phin(ll n) {ll number = n; if (n % 2 == 0) {number /= 2; while (n % 2 == 0) n /= 2;} for (ll i = 3; i <= sqrt(n); i += 2) {if (n % i == 0) {while (n % i == 0)n /= i; number = (number / i * (i - 1));}} if (n > 1)number = (number / n * (n - 1)) ; return number;} //O(sqrt(N))
/*--------------------------------------------------------------------------------------------------------------------------*/



bool pos(map<ll , ll> &mpa , ll x , ll n)
{


	if (mpa[n] >= x)
	{
		mpa[n] -= x;
		rtn true;
	}

	x -= mpa[n];
	mpa[n] = 0;

	auto it = mpa.ub(n / 2);

	if (it == mpa.begin())
	{
		return 0;
	}

	if (n & 1)
	{

		rtn (pos(mpa , x , n / 2) && pos(mpa , x , n / 2 + 1)) ;
	}
	else
	{

		rtn pos(mpa , 2 * x , n / 2);
	}

}

void solve()
{

	ll n , m ;
	cin >> n >> m ;

	vl a(n) , b(m);
	inp(n, a) ;
	inp(m, b);

	debug(a , b);

	map<ll , ll >mpa  , mpb;

	map<ll , ll > have;

	forf(n, i)mpa[a[i]]++;
	forf(m, i)mpb[b[i]]++;

	for (auto i : mpb)
	{

		if (i.ss <= mpa[i.ff])
		{
			have[i.ff] += (mpa[i.ff] - i.ss);
			mpa[i.ff] -= i.ss;
		}
		else
		{
			ll need = i.ss - mpa[i.ff];
			mpa[i.ff] = 0 ;

			if (!pos(mpa, need , i.ff))
			{
				no;
				rtn;

			}

		}


	}

	for (auto i : mpa)
	{
		if (i.ss > 0)
		{
			no;
			rtn;
		}
	}

	yes;
	rtn;

}


int main() {

#ifndef ONLINE_JUDGE

	freopen("input.txt", "r", stdin);

	freopen("output.txt", "w", stdout);

#endif
	fastio();
	int tc;
	cin >> tc;
	while (tc--)
	{
		solve();
	}

}

Solution 2 (runtime: 1124 ms):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll N=1e4+5;

int main(){
    ll T;
    cin>>T;
    while(T--){
        ll n;
        cin>>n;
        ll m;
        cin>>m;
        ll a[n],b[m];
        map<ll,ll> ma,mb;
        queue<ll> q;
        for(ll i=0;i<n;i++){
            cin>>a[i];
            ma[a[i]]=0;
            mb[a[i]]=0;
        }
        for(ll i=0;i<m;i++){
            cin>>b[i];
            ma[b[i]]=0;
        }
        sort(a,a+n);
        sort(b,b+m);
        for(ll i=0;i<m;i++){
            ma[b[i]]++;
        }
        ll count=0;
        ll mini=1e12;
        for(ll i=0;i<n;i++){
            if(ma[a[i]]>0) ma[a[i]]--;
            else{
                mb[a[i]]++;
                count++;
                mini=min(mini,a[i]);
            }
        }
        for(auto z:ma){
            if(z.second>0){
                for(ll i=0;i<z.second;i++) q.push(z.first);
            }
        }
        ll mini1=1e12;
        ll flag=0;
        while(q.empty()==0){
            ll x=q.size();
            if(x>count){
                flag=1;
                break;
            }
            for(ll i=0;i<x;i++){
                ll pp=q.front();
                q.pop();
                ll c=pp/2;
                ll d=pp-c;
                if(mb[c]>0){
                    mb[c]--;
                    count--;
                }
                else{
                    q.push(c);
                    mini1=min(mini1,c);
                }
                if(mb[d]>0){
                    mb[d]--;
                    count--;
                }
                else{
                    q.push(d);
                    mini1=min(mini1,d);
                }
            }
            if(mini1<mini){
                flag=1;
                break;
            }
        }
        if(flag==1 || count>0) cout<<"No"<<endl;
        else cout<<"Yes"<<endl;
    }
    return 0;
}