Problem: 2061D - Kevin and Numbers
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>
// #include <atcoder/segtree>
// #include <atcoder/lazysegtree>
// #include <atcoder/dsu>
using namespace std;
// using namespace atcoder;
// using mll = modll998244353;
#define lol 1000000007
#define all(c) c.begin(), c.end()
#define vi vector<ll>
#define vvi vector<vi>
#define fi first
#define se second
#define pb push_back
#define mod1 998244353
#define MAXN 2e6
#pragma GCC optimize("Ofast")
typedef long long ll;
// #define ll int
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update>
constexpr ll N = 3e5 + 1;
ll inf = 1e18;
mt19937_64 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
const ll MOD = 998244353;

struct mi
{
    ll v;
    explicit operator ll() const { return v; }
    mi() { v = 0; }
    mi(long long _v) : v(_v % MOD) { v += (v < 0) * MOD; }
};

mi &operator+=(mi &a, mi b)
{
    if ((a.v += b.v) >= MOD)
        a.v -= MOD;
    return a;
}
mi &operator-=(mi &a, mi b)
{
    if ((a.v -= b.v) < 0)
        a.v += MOD;
    return a;
}
mi operator+(mi a, mi b) { return a += b; }
mi operator-(mi a, mi b) { return a -= b; }
mi operator*(mi a, mi b) { return mi((int)a.v * b.v); }
mi &operator*=(mi &a, mi b) { return a = a * b; }
mi mpow(mi a, long long p)
{
    assert(p >= 0);
    return p == 0 ? 1 : mpow(a * a, p / 2) * (p & 1 ? a : 1);
}
mi inv(mi a)
{
    assert(a.v != 0);
    return mpow(a, MOD - 2);
}
mi operator/(mi a, mi b) { return a * inv(b); }

void solve()
{
    ll n, m;
    cin >> n >> m;
    vi arr(n), check(m);
    for (ll i = 0; i < n; i++)
        cin >> arr[i];
    for (ll i = 0; i < m; i++)
        cin >> check[i];
    sort(all(arr));
    sort(all(check));
    multiset<ll> s;
    for (ll i = 0; i < n; i++)
    {
        s.insert(arr[i]);
    }
    for (ll i = 0; i < m; i++)
    {
        ll p = 0;
        while (s.size())
        {
            auto it = *s.begin();
            s.erase(s.find(it));
            if (it == check[i])
            {
                p = 1;
                break;
            }
            if (s.size() == 0)
                break;
            auto it1 = *s.begin();
            s.erase(s.find(it1));
            if (it1 - it <= 1)
            {
                s.insert(it1 + it);
                continue;
            }
            else
                break;
        }
        if (!p)
        {
            cout << "No\n";
            return;
        }
    }
    if (s.size() == 0)
        cout << "Yes\n";
    else
        cout << "No\n";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll ft = 1;
    cin >> ft;
    while (ft--)
    {

        solve();
    }
}

// DONT GET STUCK ON ONE IDEA
//  think abt your logic thoroughly before implementing, look for all edge cases and stl structures which can cause tle/mle

Submission (verdict: Accepted):
#include <bits/stdc++.h>
// #include <atcoder/segtree>
// #include <atcoder/lazysegtree>
// #include <atcoder/dsu>
using namespace std;
// using namespace atcoder;
// using mll = modll998244353;
#define lol 1000000007
#define all(c) c.begin(), c.end()
#define vi vector<ll>
#define vvi vector<vi>
#define fi first
#define se second
#define pb push_back
#define mod1 998244353
#define MAXN 2e6
#pragma GCC optimize("Ofast")
typedef long long ll;
// #define ll int
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update>
constexpr ll N = 3e5 + 1;
ll inf = 1e18;
mt19937_64 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
const ll MOD = 998244353;

struct mi
{
    ll v;
    explicit operator ll() const { return v; }
    mi() { v = 0; }
    mi(long long _v) : v(_v % MOD) { v += (v < 0) * MOD; }
};

mi &operator+=(mi &a, mi b)
{
    if ((a.v += b.v) >= MOD)
        a.v -= MOD;
    return a;
}
mi &operator-=(mi &a, mi b)
{
    if ((a.v -= b.v) < 0)
        a.v += MOD;
    return a;
}
mi operator+(mi a, mi b) { return a += b; }
mi operator-(mi a, mi b) { return a -= b; }
mi operator*(mi a, mi b) { return mi((int)a.v * b.v); }
mi &operator*=(mi &a, mi b) { return a = a * b; }
mi mpow(mi a, long long p)
{
    assert(p >= 0);
    return p == 0 ? 1 : mpow(a * a, p / 2) * (p & 1 ? a : 1);
}
mi inv(mi a)
{
    assert(a.v != 0);
    return mpow(a, MOD - 2);
}
mi operator/(mi a, mi b) { return a * inv(b); }
map<ll, ll> m;
ll cnt = 0;
ll br = 0;
ll check(ll a)
{
    if (cnt < 0)
        return 0;
    if (m[a] > 0)
    {
        m[a]--;
        br++;
        return 1;
    }
    if (a == 1)
    {

        return 0;
    }
    ll t = a / 2, b = a - t;
    ll p = 0, q = 0;
    if (m[t] > 0)
    {
        p = 1;
        m[t]--;
        br++;
    }
    if (m[b] > 0)
    {
        br++;
        q = 1;
        m[b]--;
    }
    if (p & q)
    {
        return 1;
    }
    else if (p)
    {
        return check(b);
    }
    else if (q)
    {
        return check(t);
    }
    else
    {
        cnt--;
        return check(t) & check(b);
    }
}

void solve()
{
    m.clear();
    ll n, t;
    cin >> n >> t;
    cnt = n;
    br = 0;
    for (ll i = 0; i < n; i++)
    {
        ll a;
        cin >> a;
        m[a]++;
    }
    ll ans = 1;
    for (ll i = 0; i < t; i++)
    {
        ll a;
        cin >> a;
        ans = (ans & check(a));
    }
    ans = ans & (br == n);
    if (ans)
        cout
            << "YES\n";
    else
        cout << "NO\n";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll ft = 1;
    cin >> ft;
    while (ft--)
    {

        solve();
    }
}

// DONT GET STUCK ON ONE IDEA
//  think abt your logic thoroughly before implementing, look for all edge cases and stl structures which can cause tle/mle