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

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
#define MAXN 200010
#define int long long 
#define INF 2147483647
#define MOD 998244353

using namespace std;

signed main()
{
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int tt=1;
    cin >> tt;
    while(tt--)
    {
        int n,m;
        int sum=0;
        multiset<int> a,b,c;
        
        cin >> n >> m;
        for(int i = 1;i <= n;i++)
        {
            int x;
            cin >> x;
            a.insert(x);
        }
        for(int i = 1;i <= m;i++)
        {
            int x;
            cin >> x;
            b.insert(x);
            sum+=x;
        }
        if(sum>MAXN)
        {
            cout << "No\n";
            continue;
        }


        bool end=false;
        while(!a.empty() && !end)
        {
            end=true;
            c.clear();
            for(auto x : b)
            {
                c.insert(x);
            }
            for(auto x : b)
            {
                if(x!=1)
                {
                    end=false;
                }
                if(a.find(x)!=a.end())
                {
                    c.erase(c.find(x));
                    a.erase(a.find(x));
                    //cout << x << " is dised.\n";
                }else
                {                    
                    if(x==1)
                    {
                        continue;
                    }
                    c.erase(c.find(x));
                    c.insert((x+1)>>1);
                    c.insert(x>>1);
                }
            }
            b.clear();
            for(auto x : c)
            {
                b.insert(x);
            }    
            /*for(auto x : b)
            {
                cout << x << ' ';
            }    
            cout << '\n';*/
        }

        if(!b.empty() ||!a.empty() )
        {
            cout << "No\n";
        }else
        {
            cout << "Yes\n";
        }
        
        
    }
	return 0;
}
/*
001 001 011 011
011 101

  
a<<1|1
a<<1

拆

3 5
->1 1 3 3

3 5
->3 2 3

gredy

3 5



*/    

Submission (verdict: Time limit exceeded on test 5):
#include<bits/stdc++.h>
#define MAXN 200010
#define int long long 
#define INF 2147483647
#define MOD 998244353

using namespace std;

signed main()
{
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int tt=1;
    cin >> tt;
    while(tt--)
    {
        int n,m;
        int sum=0;
        multiset<int> a,b,c;
        
        cin >> n >> m;
        for(int i = 1;i <= n;i++)
        {
            int x;
            cin >> x;
            a.insert(x);
        }
        for(int i = 1;i <= m;i++)
        {
            int x;
            cin >> x;
            b.insert(x);
            sum+=x;
        }


        bool end=false;
        while(!a.empty() && !end)
        {
            if(b.size()>MAXN)
            {
                break;
            }
            end=true;
            c.clear();
            for(auto x : b)
            {
                c.insert(x);
            }
            for(auto x : b)
            {
                if(x!=1)
                {
                    end=false;
                }
                if(a.find(x)!=a.end())
                {
                    c.erase(c.find(x));
                    a.erase(a.find(x));
                    //cout << x << " is dised.\n";
                }else
                {                    
                    if(x==1)
                    {
                        continue;
                    }
                    c.erase(c.find(x));
                    c.insert((x+1)>>1);
                    c.insert(x>>1);
                }
            }
            b.clear();
            for(auto x : c)
            {
                b.insert(x);
            }    
            /*for(auto x : b)
            {
                cout << x << ' ';
            }    
            cout << '\n';*/
        }

        if(!b.empty() ||!a.empty() )
        {
            cout << "No\n";
        }else
        {
            cout << "Yes\n";
        }
        
        
    }
	return 0;
}
/*
001 001 011 011
011 101

  
a<<1|1
a<<1

拆

3 5
->1 1 3 3

3 5
->3 2 3

gredy

3 5



*/