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

Previous submission (verdict: Runtime error on test 2):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
vector<ll> factorial, inverse;
ll power(ll base, ll exp)
{
    ll res = 1;
    while (exp > 0)
    {
        if (exp % 2 == 1)
        {
            res = (res * base) % MOD;
        }
        base = (base * base) % MOD;
        exp /= 2;
    }
    return res;
}
void precompute(int n)
{
    factorial.resize(n + 1);
    inverse.resize(n + 1);
    factorial[0] = 1;
    for (int i = 1; i <= n; i++)
    {
        factorial[i] = (factorial[i - 1] * i) % MOD;
    }
    inverse[n] = power(factorial[n], MOD - 2);
    for (int i = n - 1; i >= 0; i--)
    {
        inverse[i] = (inverse[i + 1] * (i + 1)) % MOD;
    }
}
ll nCr(int n, int r)
{
    if (r > n || r < 0)
    {
        return 0;
    }
    return (factorial[n] * inverse[r] % MOD * inverse[n - r] % MOD) % MOD;
}
void solve()
{
    ll n,m;
    cin>>n>>m;
    multiset<ll>a;
    multiset<ll>b;
    for(ll i=0;i<n;i++)
    {
        ll in;
        cin>>in;
        a.insert(in);
    }
    multiset<ll>check;
    for(auto x:a)
    {
        check.insert(x);
    }
    for(ll i=0;i<m;i++)
    {
        ll in;
        cin>>in;
        b.insert(in);
    }
    vector<ll>store;
    ll pos=0;
    while(b.size()!=n)
    {
        auto it=b.end();
        it--;
        advance(it,-pos);
        if(a.find(*it)!=a.end())
        {
            a.erase(a.find(*it));
            pos++;
        }
        else
        {
            ll val=*it;
            b.insert((val+1)/2);
            b.insert((val)/2);
            b.erase(it);
        }    
    }
    for(auto it:b)
    {
        if(check.find(it)==check.end())
        {
        cout<<"No"<<endl;
            return;
        }
        else
        {
            check.erase(check.find(it));
        }
    }
    cout<<"Yes"<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t;
    cin >> t;
    while (t--)
    {
        solve();
    }
}

Submission (verdict: Time limit exceeded on test 7):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
vector<ll> factorial, inverse;
ll power(ll base, ll exp)
{
    ll res = 1;
    while (exp > 0)
    {
        if (exp % 2 == 1)
        {
            res = (res * base) % MOD;
        }
        base = (base * base) % MOD;
        exp /= 2;
    }
    return res;
}
void precompute(int n)
{
    factorial.resize(n + 1);
    inverse.resize(n + 1);
    factorial[0] = 1;
    for (int i = 1; i <= n; i++)
    {
        factorial[i] = (factorial[i - 1] * i) % MOD;
    }
    inverse[n] = power(factorial[n], MOD - 2);
    for (int i = n - 1; i >= 0; i--)
    {
        inverse[i] = (inverse[i + 1] * (i + 1)) % MOD;
    }
}
ll nCr(int n, int r)
{
    if (r > n || r < 0)
    {
        return 0;
    }
    return (factorial[n] * inverse[r] % MOD * inverse[n - r] % MOD) % MOD;
}
void solve()
{
    ll n,m;
    cin>>n>>m;
    multiset<ll>a;
    multiset<ll>b;
    for(ll i=0;i<n;i++)
    {
        ll in;
        cin>>in;
        a.insert(in);
    }
    multiset<ll>check;
    for(auto x:a)
    {
        check.insert(x);
    }
    for(ll i=0;i<m;i++)
    {
        ll in;
        cin>>in;
        b.insert(in);
    }
    vector<ll>store;
    ll pos=0;
    while(pos<b.size() and b.size()!=n)
    {
        auto it=b.end();
        it--;
        advance(it,-pos);
        if(a.find(*it)!=a.end())
        {
            a.erase(a.find(*it));
            pos++;
        }
        else
        {
            ll val=*it;
            b.insert((val+1)/2);
            b.insert((val)/2);
            b.erase(it);
        }    
    }
    if(b.size()!=n)
    {
        cout<<"No"<<endl;
        return;
    }
    for(auto it:b)
    {
        if(check.find(it)==check.end())
        {
        cout<<"No"<<endl;
            return;
        }
        else
        {
            check.erase(check.find(it));
        }
    }
    cout<<"Yes"<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t;
    cin >> t;
    while (t--)
    {
        solve();
    }
}