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

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
#define int long long
using namespace std;

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sortall(x) sort(all(x))
#define sz(x) (int)(x.size())
#define endl '\n'
#define PI 3.141592653589793238462
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define MP make_pair
#define pr(a) for(auto x:a) cout<<x<<" ";cout<<endl;
#define print(a , n) for(int i = 0 ; i < n  ;i ++) cout<<a[i]<<" "; cout<<endl;
#define read(a,n) for(int i=0;i<n;i++) cin>>a[i];
 
typedef long long lli;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<lli, lli> pll;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<ii> vii;
typedef vector<pll> vll;
const lli mod = 1000000007;
 
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[] = {1, 0, -1, 0, 1, -1, 1, -1};
 
bool comp2(const pair<int, int>& a, const pair<int, int>& b){
    if(max(a.first,a.second)==max(b.first,b.second)){
        return min(a.first,a.second)<min(b.first,b.second);
    }
    return max(a.first,a.second)<max(b.first,b.second);
}
 
int n; 
vi v; vi p;
void pre(){
    int cnt=2;
    int l=2; int r=4;
    while(l<=100010){
        v.push_back(l); p.push_back(cnt); cnt++;
        l=r+1; r=2*l;
    }
}


vector<int> sieve_of_eratosthenes(int n)
{   vector<bool> prime(n+1,true);
    for(int p=2;p*p <= n;p++)
    {   if(prime[p] == true)
        { for(int i=p*p;i<=n;i+=p)
            { prime[i] = false;}}} 
    vector<int> v;
    for(int i=2; i<= n;i++)
    {  if(prime[i]) { v.push_back(i);}}
    return v; }


//-------------------------------------------------------------------------------------------------------------------------------------------//
int find_set(int v, vector<int> &parent) {
    // cout << v << endl;
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v],parent);
}

void make_set(int v,vector<int> &parent, vector<int> &rank) {
    parent[v] = v;
    rank[v] = 0;
}

void union_sets(int a, int b,vector<int> &parent, vector<int> &rank) {
    // cout << a << " " << b << endl;
    a = find_set(a,parent);
    b = find_set(b,parent);
    if (a != b) {
        if (rank[a] < rank[b])
            swap(a, b);
        parent[b] = a;
        if (rank[a] == rank[b])
            rank[a]++;
    }
}

// Had to take hints from editorial
void solve()
{
    int n;
    cin >> n;
    int m;
    cin >> m;
    int a[n];
    int b[m];
    multiset<int> st;
    for(int i=0;i<n;i++)
    {
        cin >> a[i];
        st.insert(a[i]);
    }
    priority_queue<int> pq;
    for(int i=0;i<m;i++)
    {
        cin >> b[i];
        pq.push(b[i]);
    }
    
    int diff = n-m;
    while(diff>0)
    {
        if(pq.size()==0)
        {
            break;
        }
        int top = pq.top();
        pq.pop();
        if(st.find(top)==st.end())
        {
            int kk = top/2;
            // cout << kk << endl;
            pq.push(kk);
            if(top&1)
            {
                pq.push(top/2+1);
            }
            else
            {
                pq.push(top/2);
            }
            diff--;
        }
        else 
        {
            auto itr = st.find(top);
            st.erase(itr);
            if(st.size()==0)
            {
                break;
            }
        }
        
    }
    bool ans = true;
    while(pq.size()>0)
    {
        int top = pq.top();
        pq.pop();
        if(st.find(top)==st.end())
        {
            ans = false;
            break;
        }
        else
        {
            auto itr = st.find(top);
            st.erase(itr);
        }
    }
    if(ans)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
}

int32_t main() 
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    while(t--)
    {
        solve();
    }
    
    return 0;
}



Submission (verdict: Accepted):
#include <bits/stdc++.h>
#define int long long
using namespace std;

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sortall(x) sort(all(x))
#define sz(x) (int)(x.size())
#define endl '\n'
#define PI 3.141592653589793238462
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define MP make_pair
#define pr(a) for(auto x:a) cout<<x<<" ";cout<<endl;
#define print(a , n) for(int i = 0 ; i < n  ;i ++) cout<<a[i]<<" "; cout<<endl;
#define read(a,n) for(int i=0;i<n;i++) cin>>a[i];
 
typedef long long lli;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<lli, lli> pll;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<ii> vii;
typedef vector<pll> vll;
const lli mod = 1000000007;
 
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[] = {1, 0, -1, 0, 1, -1, 1, -1};
 
bool comp2(const pair<int, int>& a, const pair<int, int>& b){
    if(max(a.first,a.second)==max(b.first,b.second)){
        return min(a.first,a.second)<min(b.first,b.second);
    }
    return max(a.first,a.second)<max(b.first,b.second);
}
 
int n; 
vi v; vi p;
void pre(){
    int cnt=2;
    int l=2; int r=4;
    while(l<=100010){
        v.push_back(l); p.push_back(cnt); cnt++;
        l=r+1; r=2*l;
    }
}


vector<int> sieve_of_eratosthenes(int n)
{   vector<bool> prime(n+1,true);
    for(int p=2;p*p <= n;p++)
    {   if(prime[p] == true)
        { for(int i=p*p;i<=n;i+=p)
            { prime[i] = false;}}} 
    vector<int> v;
    for(int i=2; i<= n;i++)
    {  if(prime[i]) { v.push_back(i);}}
    return v; }


//-------------------------------------------------------------------------------------------------------------------------------------------//
int find_set(int v, vector<int> &parent) {
    // cout << v << endl;
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v],parent);
}

void make_set(int v,vector<int> &parent, vector<int> &rank) {
    parent[v] = v;
    rank[v] = 0;
}

void union_sets(int a, int b,vector<int> &parent, vector<int> &rank) {
    // cout << a << " " << b << endl;
    a = find_set(a,parent);
    b = find_set(b,parent);
    if (a != b) {
        if (rank[a] < rank[b])
            swap(a, b);
        parent[b] = a;
        if (rank[a] == rank[b])
            rank[a]++;
    }
}

// Had to take hints from editorial
void solve()
{
    int n;
    cin >> n;
    int m;
    cin >> m;
    int a[n];
    int b[m];
    multiset<int> st;
    for(int i=0;i<n;i++)
    {
        cin >> a[i];
        st.insert(a[i]);
    }
    priority_queue<int> pq;
    for(int i=0;i<m;i++)
    {
        cin >> b[i];
        pq.push(b[i]);
    }
    
    int diff = n-m;
    while(diff>0)
    {
        if(pq.size()==0)
        {
            break;
        }
        int top = pq.top();
        pq.pop();
        if(st.find(top)==st.end())
        {
            int kk = top/2;
            // cout << kk << endl;
            pq.push(kk);
            if(top&1)
            {
                pq.push(top/2+1);
            }
            else
            {
                pq.push(top/2);
            }
            diff--;
        }
        else 
        {
            auto itr = st.find(top);
            st.erase(itr);
            if(st.size()==0)
            {
                break;
            }
        }
        
    }
    bool ans = true;
    while(pq.size()>0 && st.size()>0)
    {
        int top = pq.top();
        pq.pop();
        if(st.find(top)==st.end())
        {
            ans = false;
            break;
        }
        else
        {
            auto itr = st.find(top);
            st.erase(itr);
        }
    }
    if(st.size()+pq.size()>0)
    {
        cout << "NO" << endl;
        return;
    }
    if(ans)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
}

int32_t main() 
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    while(t--)
    {
        solve();
    }
    
    return 0;
}