Problem: 2061D - Kevin and Numbers
Language: C++17 (GCC 7-32)

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

#include<cstdio>

#include <ext/pb_ds/tree_policy.hpp>

#include <ext/pb_ds/assoc_container.hpp>

#define no cout<<"NO\n";

#define yes cout<<"YES\n";

#define ll long long

using namespace std;

using namespace __gnu_pbds;

template<class T>

using Tree=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

//ll lcm(ll a,ll b){return (a/__gcd(a,b))*1LL*b;}

map<ll,ll>mp;

bool rec(ll a,ll b,ll cnt)

{

    if(!cnt)return 1;

    if(!a||!b)return 0;

    mp[a+b]+=cnt;

    int o=mp[a],z=mp[b];

    mp[a]-=cnt;

    mp[b]-=cnt;

    if(a==b)

    {

        if(mp[a]<2*cnt)

        {

            return rec(a/2,a/2+a%2,cnt-o/2);

        }

    }

    else

    {

        if(mp[a]<cnt)

        {

            return rec(a/2,a/2+a%2,cnt-o);

        }

        if(mp[b]<cnt)

        {

            return rec(b/2,b/2+b%2,cnt-z);

        }

    }

}

int main()

{

	ios_base::sync_with_stdio(NULL);

	cin.tie(0); cout.tie(0);

	//freopen("intern.in", "r", stdin);

	//freopen("flags.out", "w", stdout);

	int t;

	cin>>t;

	while(t--)

    {

        mp.clear();

        ll n,m,x;

        cin>>n>>m;

        set<ll>st;

        map<ll,ll>mp1,mp2;

        for(int i=0;i<n;++i)

            cin>>x,st.insert(x),mp1[x]++;

        for(int i=0;i<m;++i)

            cin>>x,st.insert(x),mp2[x]++;

        bool f=0;

        for(auto it:st)

        {

            if(mp1[it]==mp2[it])continue;

            if(mp1[it]<mp2[it])

            {

                x=mp2[it]-mp1[it];

                if(!rec(it/2,it/2+it%2,x)){f=1;break;}

                else {mp[it]-=x,mp1[it]=mp2[it];}

                continue;

            }

            x=mp1[it]-mp2[it];

            mp1[it]=mp2[it];

            mp[it]+=x;

        }

        for(auto [u,v] : mp)

        {

            if(v){f=1;break;}

        }

        if(f)no

        else yes

    }

}



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

#include<cstdio>

#include <ext/pb_ds/tree_policy.hpp>

#include <ext/pb_ds/assoc_container.hpp>

#define no cout<<"NO\n";

#define yes cout<<"YES\n";

#define ll long long

using namespace std;

using namespace __gnu_pbds;

template<class T>

using Tree=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

//ll lcm(ll a,ll b){return (a/__gcd(a,b))*1LL*b;}

map<ll,ll>mp;

bool rec(ll a,ll b,ll cnt)

{

  //  cout<<a<<" "<<b<<" "<<cnt<<" "<<mp[a]<<" "<<mp[b]<<"\n";

    if(!cnt)return 1;

    if(!a||!b)return 0;

    mp[a+b]+=cnt;

    int o=mp[a],z=mp[b];

    mp[a]-=cnt;

    mp[b]-=cnt;

    if(a==b)

    {

        if(mp[a]<2*cnt)

        {

            return rec(a/2,a/2+a%2,2*cnt-o);

        }

    }

    else

    {

        return ((o<cnt ? rec(a/2,a/2+a%2,cnt-o) : 1)&(z<cnt ? rec(b/2,b/2+b%2,cnt-z) : 1));

    }

    return 1;

}

int main()

{

	ios_base::sync_with_stdio(NULL);

	cin.tie(0); cout.tie(0);

	//freopen("intern.in", "r", stdin);

	//freopen("flags.out", "w", stdout);

	int t;

	cin>>t;

	while(t--)

    {

        mp.clear();

        ll n,m,x;

        cin>>n>>m;

        set<ll>st;

        map<ll,ll>mp1,mp2;

        for(int i=0;i<n;++i)

            cin>>x,st.insert(x),mp1[x]++;

        for(int i=0;i<m;++i)

            cin>>x,st.insert(x),mp2[x]++;

        bool f=0;

        for(auto it:st)

        {

            if(mp1[it]==mp2[it])continue;

            if(mp1[it]<mp2[it])

            {

                x=mp2[it]-mp1[it];

                if(!rec(it/2,it/2+it%2,x)){f=1;break;}

                else {mp[it]-=x,mp1[it]=mp2[it];}

                continue;

            }

            x=mp1[it]-mp2[it];

            mp1[it]=mp2[it];

            mp[it]+=x;

        }

        for(auto [u,v] : mp)

        {

            if(v){f=1;break;}

        }

        if(f)no

        else yes

    }

}