Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 3):
// author: лелутик :3
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <cassert>
#include <map>
#include <cmath>
#include <iomanip>
#include <random>
#include <functional>
#include <string>
#include <queue>
#include <stack>

using namespace std;
#define int               long long
#define pii               pair<int, int>
#define line              cout << "\n"
#define pb                push_back
#define ppb               pop_back
#define sz(a)             (int) a.size()
#define all(a)            a.begin(), a.end()
#define rall(a)           a.rbegin(), a.rend()
#define fast              ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
typedef long long ll;
typedef long double ld;
typedef string str;
mt19937 rnd(time(0));
const int MOD = 998244353;


void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(m);
    multiset<int> st;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        st.insert(a[i]);
    }
    for (int i = 0; i < m; i++) {
        cin >> b[i];
    }
    sort(all(b));
    int i = 0;
    while (sz(st) && i < sz(b)) {
        int x = *st.begin();
        st.erase(st.begin());
        if (x == b[i]) {
            i++;
            continue;
        }
        if (!sz(st)) {
            cout << "No"; line;
            return;
        }
        int y = *st.begin();
        st.erase(st.begin());
        if (y - x > 1) {
            cout << "No"; line;
            return;
        }
        st.insert(x + y);
    }
    if (sz(st) || i != sz(b)) {
        cout << "No"; line;
        return;
    }
    cout << "Yes"; line;
}


signed main() {
    fast;


#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif


    int t = 1;
    cin >> t;
    while (t--) {
        solve();
    }
}


Submission (verdict: Time limit exceeded on test 1):
// author: лелутик :3
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <cassert>
#include <map>
#include <cmath>
#include <iomanip>
#include <random>
#include <functional>
#include <string>
#include <queue>
#include <stack>

using namespace std;
#define int               long long
#define pii               pair<int, int>
#define line              cout << "\n"
#define pb                push_back
#define ppb               pop_back
#define sz(a)             (int) a.size()
#define all(a)            a.begin(), a.end()
#define rall(a)           a.rbegin(), a.rend()
#define fast              ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
typedef long long ll;
typedef long double ld;
typedef string str;
mt19937 rnd(time(0));
const int MOD = 998244353;


void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(m);
    map<int, int> st;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        st[a[i]]++;
    }
    for (int i = 0; i < m; i++) {
        cin >> b[i];
    }
    sort(all(b));
    int i = m - 1;
    while (sz(st) && i >= 0) {
        int x = (--st.end())->first;
        st[x]--;
        if (x == b[i]) {
            if (st[x] == 0) {
                st.erase(x);
            }
            i--;
            continue;
        }
        if (sz(st) == 1) {
            if (!st[x]) {
                cout << "No"; line;
                return;
            }
            st[x]--;
            if (!st[x]) {
                st.erase(x);
            }
            st[x + x]++;
        }
        if (st[x] && x + x <= b[i]) {
            st[x]--;
            if (!st[x]) {
                st.erase(x);
            }
            st[x + x]++;
        }
        if (sz(st) == 1) {
            cout << "No"; line;
            return;
        }
        int y = (----st.end())->first;
        st[y]--;
        if (!st[x]) {
            st.erase(x);
        }
        if (!st[y]) {
            st.erase(y);
        }
        st[x + y]++;
    }
    if (sz(st) || i >= 0) {
        cout << "No"; line;
        return;
    }
    cout << "Yes"; line;
}


signed main() {
    fast;


#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif


    int t = 1;
    cin >> t;
    while (t--) {
        solve();
    }
}