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

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


#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key
//---- Debugger ---- //
#ifndef ONLINE_JUDGE
#define debarr(a,n) cout<<#a<<" : ";for(int i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl;
#define debmat(mat,row,col) cout<<#mat<<" :\n";for(int i=0;i<row;i++) {for(int j=0;j<col;j++) cout<<mat[i][j]<<" ";cout<<endl;}
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const unordered_set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const unordered_map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const multiset<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void dbs(string str, T t) {cout << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cout << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...);}
template <class T> void prc(T a, T b) {cout << "["; for (T i = a; i != b; ++i) {if (i != a) cout << ", "; cout << *i;} cout << "]\n";}
//----------------- //
#else
#define pr(...){}
#define debarr(a,n){}
#define debmat(mat,row,col){}
#endif

#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(nullptr);cout.tie(nullptr);
#define nl cout<<'\n'
#define ppb pop_back
#define pb push_back
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define repr(i, a, b) for (ll i = a; i >= b; i--)
#define fr for(int i=0  ; i < n ; i++ )
#define all(a) a.begin(), a.end()
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define sortt(ar) sort(ar.begin(),ar.end())
#define int long long
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define spi set<pair<int,int>>
#define pi vector<pair<int,int>>
#define vvi vector<vector<int>>
#define printans(ans) for(auto it:ans)cout<<it<<" ";
#define endl '\n' 
void solve()
{
    int n,m;
    cin >> n >> m;
    map<int,int> mp;
    multiset<int> se;
    rep(i,0,n)
    {
        int x;
        cin>>x;
        mp[x]++;
        se.insert(x);
    }
    multiset<int> ms;
    rep(i,0,m)
    {
        int x;
        cin>>x;
        if(se.find(x)!=se.end())
            {
                se.erase(se.find(x));
                mp[x]--;
            }
        else
            ms.insert(x);
    }
    for(auto ii : ms)
    {
        int var1= ii;
        int var2=-1;
        map<int,int> mpned;
        mpned[var1]++;
        int prev1=0,prev2=0;
        while( !(mp[var1] >= mpned[var1] && mp[var2] >= mpned[var2]))
        {
        set<int> lev;
            if(mp[var1] < mpned[var1])
            {
                 if(var1%2==0)
                {
                    prev1 = var1/2;
                    lev.insert(prev1);
                    mpned[prev1]+=2;
                }
                else
                {
                    prev1 = var1/2;
                    prev2 = var1/2+1;
                    lev.insert(prev1);
                    lev.insert(prev2);
                    mpned[prev1]+=1;
                    mpned[prev2]+=1;
                }
            }
            if(mp[var2] < mpned[var2])
            {
                 if(var2%2==0)
                {
                    prev2 = var2/2;
                    lev.insert(prev2);
                    mpned[prev2]+=2;
                }
                else
                {
                    prev2 = var2/2+1;
                    lev.insert(prev2-1);
                    lev.insert(prev2);
                    mpned[var2/2]+=1;
                    mpned[var2/2 +1 ]+=1;
                }
            }
            auto op = lev.begin();
            var1 = *op;
            op++;
            var2 = (op!=lev.end() ? *op : -1);
            if(mp[var1]>=mpned[var1])
            {
                mp[var1]-=mpned[var1];
                mpned[var1]=0;
                var1 = -1;
            }
             if(mp[var2]>=mpned[var2])
            {
                mp[var2]-=mpned[var2];
                mpned[var2]=0;
                var2 = -1;
            }

            if(var1 == 1 || var2==1)
            {
                no;return;
            }
        }
    }
    int cnt=0;
    // pr(mp);
    for(auto ii = mp.begin() ; ii != mp.end() ; ii++)
    {
        if(ii->second!= 0)
        {
            cnt++;
        }
    }
    if(cnt)
        {
            no;return;
        }
        yes;return;








    
}
signed main()
{
   fast
       int t; cin>>t ;   for(int i=0;i<t;i++)
      solve();
 

 }

Submission (verdict: Wrong answer on test 3):
#include<bits/stdc++.h>
using namespace std;


#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key
//---- Debugger ---- //
#ifndef ONLINE_JUDGE
#define debarr(a,n) cout<<#a<<" : ";for(int i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl;
#define debmat(mat,row,col) cout<<#mat<<" :\n";for(int i=0;i<row;i++) {for(int j=0;j<col;j++) cout<<mat[i][j]<<" ";cout<<endl;}
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const unordered_set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const unordered_map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const multiset<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void dbs(string str, T t) {cout << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cout << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...);}
template <class T> void prc(T a, T b) {cout << "["; for (T i = a; i != b; ++i) {if (i != a) cout << ", "; cout << *i;} cout << "]\n";}
//----------------- //
#else
#define pr(...){}
#define debarr(a,n){}
#define debmat(mat,row,col){}
#endif

#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(nullptr);cout.tie(nullptr);
#define nl cout<<'\n'
#define ppb pop_back
#define pb push_back
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define repr(i, a, b) for (ll i = a; i >= b; i--)
#define fr for(int i=0  ; i < n ; i++ )
#define all(a) a.begin(), a.end()
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define sortt(ar) sort(ar.begin(),ar.end())
#define int long long
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define spi set<pair<int,int>>
#define pi vector<pair<int,int>>
#define vvi vector<vector<int>>
#define printans(ans) for(auto it:ans)cout<<it<<" ";
#define endl '\n' 
void solve()
{
    int n,m;
    cin >> n >> m;
    map<int,int> mp;
    multiset<int> se;
    rep(i,0,n)
    {
        int x;
        cin>>x;
        mp[x]++;
        se.insert(x);
    }
    multiset<int> ms;
    rep(i,0,m)
    {
        int x;
        cin>>x;
        if(se.find(x)!=se.end())
            {
                se.erase(se.find(x));
                mp[x]--;
            }
        else
            ms.insert(x);
    }
    for(auto ii : ms)
    {
        int var1= ii;
        int var2=-1;
        map<int,int> mpned;
        mpned[var1]++;
        int prev1=0,prev2=0;
        while( !(mp[var1] >= mpned[var1] && mp[var2] >= mpned[var2]))
        {
        set<int> lev;
        // pr(mp);
        // pr(mpned);
            if(mp[var1] < mpned[var1])
            {
                 if(var1%2==0)
                {
                    prev1 = var1/2;
                    lev.insert(prev1);
                    mpned[prev1]+=2*mpned[var1];
                }
                else
                {
                    prev1 = var1/2;
                    prev2 = var1/2+1;
                    lev.insert(prev1);
                    lev.insert(prev2);
                    mpned[prev1]+=1*mpned[var1];
                    mpned[prev2]+=1*mpned[var1];
                }
            }
            if(mp[var2] < mpned[var2])
            {
                 if(var2%2==0)
                {
                    prev2 = var2/2;
                    lev.insert(prev2);
                    mpned[prev2]+=2*mpned[var2];
                }
                else
                {
                    prev2 = var2/2+1;
                    lev.insert(prev2-1);
                    lev.insert(prev2);
                    mpned[var2/2]+=1*mpned[var2];
                    mpned[var2/2 +1 ]+=1*mpned[var2];
                }
            }
            auto op = lev.begin();
            var1 = *op;
            op++;
            var2 = (op!=lev.end() ? *op : -1);
            if(mp[var1]!=0 )
            {
                if(mp[var1]>=mpned[var1])
                {mp[var1]-=mpned[var1];
                mpned[var1]=0;
                var1 = -1;}
                else{
                    mpned[var1]-=mp[var1];
                    mp[var1]=0;
                }
            }
             if(mp[var2]!=0)
             {
                if(mp[var2]>=mpned[var2]){
                mp[var2]-=mpned[var2];
                mpned[var2]=0;
                var2 = -1;}
                else
                {
                    mpned[var2]-=mp[var2];
                    mp[var2]=0;
                }
            }
            //  pr(var1);
            //  pr(var2);
            if(var1==-1 && var2 == -1)
                break;
            if(var1 == 1 || var2==1)
            {
                no;return;
            }
        }
    }
    int cnt=0;
    // pr(mp);
    for(auto ii = mp.begin() ; ii != mp.end() ; ii++)
    {
        if(ii->second!= 0)
        {
            cnt++;
        }
    }
    if(cnt)
        {
            no;return;
        }
        yes;return;








    
}
signed main()
{
   fast
       int t; cin>>t ;   for(int i=0;i<t;i++)
      solve();
 

 }