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

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

using namespace std;

#define py cout << "YES" << endl

#define pn cout << "NO" << endl

#define aans             \

    cout << ans << endl; \

    return;

#define pneg cout << "-1" << endl

#define prDouble(x, y) cout << fixed << setprecision(y) << x

#define bitcount(x) __builtin_popcount(x)

#define ll long long

#define ld long double

#define pb push_back

#define ppb pop_back

#define mp make_pair

#define eb emplace_back

#define forw(i, j, n) for (ll i = j; i < n; i++)

#define all(x) x.begin(), x.end()

#define fastfast()                    \

    ios_base::sync_with_stdio(false); \

    cin.tie(NULL);                    \

    cout.tie(NULL)

#define sz(x) ((int)(x).size())

#define input(arr, i, n) rep(j, i, n) cin >> arr[j];



typedef pair<int, int> pii;

typedef vector<int> vi;

typedef vector<ll> vll;

typedef vector<ld> vld;

typedef vector<double> vd;

typedef vector<bool> vb;

typedef vector<string> vs;

typedef pair<ll, ll> pll;

typedef vector<vector<ll>> vvll;

typedef vector<vector<ld>> vvld;

typedef vector<pll> vpll;

#define mii map<int, int>

#define mll map<ll, ll>





ll gcd(ll a, ll b)

{

    if (b == 0)

        return a;

    else

        return gcd(b, a % b);

}



ll findLCM(ll a, ll b, ll c)

{

    ll GCD = gcd(a, b);

    ll lcm = (a * b) / GCD;

    GCD = gcd(lcm, c);

    lcm = (lcm * c) / GCD;

    return lcm;

}





pair<vll, vll> sol(vll &a, vll &b)

{

    ll i = 0, j = 0;

    ll n = a.size(), m = b.size();

    vll a1, b1;

    sort(all(a));

    sort(all(b));

    while (i < n && j < m)

    {

        while (i < n && a[i] < b[j])

            a1.pb(a[i++]);

        while (i < n && j < m && a[i] == b[j])

            i++, j++;

        while (i < n && j < m && b[j] < a[i])

            b1.pb(b[j++]);

    }

    while (i < n) a1.pb(a[i++]);

    while (j < m) b1.pb(b[j++]);

    return {a1, b1};

}





vll divid(vll &v)

{

    vll a;

    for (ll x : v)

    {

        a.pb(x / 2);

        a.pb((x + 1) / 2);

    }

    sort(all(a));

    return a;

}



// Core logic

void solve()

{

    ll n, m;

    cin >> n >> m;

    vll a(n), b(m);



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

        cin >> a[i];

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

        cin >> b[i];



    sort(all(a));

    sort(all(b));



    vll ne=divid(a);

    for(auto it:ne)cout<<it<<" ";cout<<endl;return;

    vll a1, b1;

    tie(a1, b1) = sol(a, b);



    if (b1.size() > a1.size())

    {

        pn;

        return;

    }

    else if(a1==b1){

        py;return;

    }

    for (ll i = 0; i < 32; i++)

    {

        b1 = divid(b1);

        tie(a1, b1) = sol(a1, b1);

        if (a1 == b1)

        {

            py;

            return;

        }

    }



    pn;

}



// Entry point

int main()

{

    fastfast();

    int t;

    cin >> t;

    while (t--)

    {

        solve();

    }

    return 0;

}



Submission (verdict: Time limit exceeded on test 1):
#include <bits/stdc++.h>

using namespace std;

#define py cout << "YES" << endl

#define pn cout << "NO" << endl

#define aans             \

    cout << ans << endl; \

    return;

#define pneg cout << "-1" << endl

#define prDouble(x, y) cout << fixed << setprecision(y) << x

#define bitcount(x) __builtin_popcount(x)

#define ll long long

#define ld long double

#define pb push_back

#define ppb pop_back

#define mp make_pair

#define eb emplace_back

#define forw(i, j, n) for (ll i = j; i < n; i++)

#define all(x) x.begin(), x.end()

#define fastfast()                    \

    ios_base::sync_with_stdio(false); \

    cin.tie(NULL);                    \

    cout.tie(NULL)

#define sz(x) ((int)(x).size())

#define input(arr, i, n) rep(j, i, n) cin >> arr[j];



typedef pair<int, int> pii;

typedef vector<int> vi;

typedef vector<ll> vll;

typedef vector<ld> vld;

typedef vector<double> vd;

typedef vector<bool> vb;

typedef vector<string> vs;

typedef pair<ll, ll> pll;

typedef vector<vector<ll>> vvll;

typedef vector<vector<ld>> vvld;

typedef vector<pll> vpll;

#define mii map<int, int>

#define mll map<ll, ll>





ll gcd(ll a, ll b)

{

    if (b == 0)

        return a;

    else

        return gcd(b, a % b);

}



ll findLCM(ll a, ll b, ll c)

{

    ll GCD = gcd(a, b);

    ll lcm = (a * b) / GCD;

    GCD = gcd(lcm, c);

    lcm = (lcm * c) / GCD;

    return lcm;

}





pair<vll, vll> sol(vll &a, vll &b)

{

    ll i = 0, j = 0;

    ll n = a.size(), m = b.size();

    vll a1, b1;

    sort(all(a));

    sort(all(b));

    while (i < n && j < m)

    {

        while (i < n && a[i] < b[j])

            a1.pb(a[i++]);

        while (i < n && j < m && a[i] == b[j])

            i++, j++;

        while (i < n && j < m && b[j] < a[i])

            b1.pb(b[j++]);

    }

    while (i < n) a1.pb(a[i++]);

    while (j < m) b1.pb(b[j++]);

    return {a1, b1};

}





vll divid(vll &v)

{

    vll a;

    for (ll x : v)

    {

        a.pb(x / 2);

        a.pb((x + 1) / 2);

    }

    sort(all(a));

    return a;

}



// Core logic

void solve()

{

    ll n, m;

    cin >> n >> m;

    vll a(n), b(m);



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

        cin >> a[i];

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

        cin >> b[i];



    sort(all(a));

    sort(all(b));



    // vll ne=divid(a);

    // for(auto it:ne)cout<<it<<" ";cout<<endl;return;

    vll a1, b1;

    tie(a1, b1) = sol(a, b);



    if (b1.size() > a1.size())

    {

        pn;

        return;

    }

    else if(a1==b1){

        py;return;

    }

    for (ll i = 0; i < 32; i++)

    {

        b1 = divid(b1);

        tie(a1, b1) = sol(a1, b1);

        if (a1 == b1)

        {

            py;

            return;

        }

    }



    pn;

}



// Entry point

int main()

{

    fastfast();

    int t;

    cin >> t;

    while (t--)

    {

        solve();

    }

    return 0;

}