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


Submission (verdict: Wrong answer on test 1):
#ifndef __MINGW32__
#define __MINGW32__
#endif

#include <bits/stdc++.h>
using namespace std;
#define FAST_IO ios_base::sync_with_stdio(false), cin.tie(nullptr),cout.tie(nullptr)
// #pragma GCC optimize("O3,unroll-loops,Ofast")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
/*----------------------------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------------------------*/
template<typename... T>
void see(T&... args) { ((cin >> args), ...);}
template<typename... T>
void put(T&&... args) { ((cout << args << " "), ...);}
template<typename... T>
void putl(T&&... args) { ((cout << args << " "), ...); cout<<'\n';}
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {cerr << *it << "=" << a << ", "; err(++it, args...);}
/*----------------------------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------------------------*/
#define int long long
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define dbV(arr) cout << #arr << "=[ "; \
for(auto i:arr) cout << i << " "; cout << "]\n";
// #define fo(i, n) for (int i = 0; i < int(n); i++)
// #define fi(i, n, x) for (int i = x; i < int(n); i++)
// #define rep(i,n) for(int i = 0; i < (n); ++i)
// #define repF(i,a,n) for(int i = (a); i <= (n); ++i)
// #define repB(i,a,n) for(int i = (a); i >= (n); --i)
#define pii pair<int,int>
#define tiii tuple<int,int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vp vector<pii>
#define vs vector<string>
#define vb vector<bool>
#define vvi vector<vector<int>>
#define vd vector<double>
#define umii unordered_map<int,int>
#define umll unordered_map<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define seti set<int>
#define setl set<ll>
#define pb push_back
#define F first
#define S second
#define all(z) z.begin(),z.end()
#define rall(v) v.rbegin(),v.rend()
#define sz(a) (int)a.size()
using ll = long long;

const int N = 1e5+1;
const int MOD= 1e9+7;
const int INF = 1e18;

/*----------------------------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------------------------*/


void solve() {
    int n, m; see(n, m);
    multiset<int> a, b;
    for(int i = 0; i < n; i++) {
        int x; see(x);
        a.insert(x);
    }
    for(int i = 0; i < m; i++) {
        int x; see(x);
        b.insert(x);
    }
    while(!a.empty() && !b.empty()) {
        int largest = *b.rbegin();
        if(a.find(largest) != a.end()) {
            a.erase(a.find(largest));
            b.erase(--b.end());
            continue;
        }
        int first = largest / 2;
        int second = (largest + 1) / 2;
        if(a.find(first) != a.end() && a.find(second) != a.end()) {
            a.erase(a.find(first));
            a.erase(a.find(second));
            b.erase(--b.end());
        } else {
            putl("No");
            return;
        }
    }
    putl(a.empty() && b.empty() ? "Yes" : "No");
}

int32_t main(){
    FAST_IO;
    // freopen("cowtip.in","r",stdin);
    // freopen("cowtip.out","w",stdout);
    int t=1;
    cin>>t;
    // cout<<t<<'\n';
    // int c=1;

    while(t--) {
        // cout<<"Case "<<c<<": ";
        solve();
        // c++;
    }
    #ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
    return 0;
}