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

Previous submission (verdict: Runtime error on test 2):
// #pragma GCC optimize(2)

#include <bits/stdc++.h>

using namespace std;

#define int long long

#define endl '\n'

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



constexpr int MOD = 1e9 + 7;

// -9.2e18 ~ 9.2e18



void solve()

{

    int n, m;

    cin >> n >> m;

    vector<int> a(n), b(m);

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

    {

        cin >> a[i];

    }

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

    {

        cin >> b[i];

    }



    priority_queue<int, vector<int>> pqa, pqb;

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

    {

        pqa.push(a[i]);

    }

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

    {

        pqb.push(b[i]);

    }

    int k = n - m;

    while (pqa.size() and k)

    {

        auto amax = pqa.top();

        pqa.pop();

        auto bmax = pqb.top();

        pqb.pop();



        if (amax == bmax)

        {

            continue;

        }

        else if (amax > bmax)

        {

            cout << "No";

            return;

        }

        else

        {

            pqa.push(amax);

            auto num1 = bmax / 2, num2 = (bmax + 1) / 2;

            pqb.push(num1);

            pqb.push(num2);

        }

        k--;

    }



    bool equal = true;

    while (!pqa.empty() && !pqb.empty())

    {

        if (pqa.top() != pqb.top())

        {

            equal = false;

            break;

        }

        pqa.pop();

        pqb.pop();

    }

    equal = equal && pqa.empty() && pqb.empty();

    cout << (equal ? "Yes" : "No");

}



signed main()

{

    cin.tie(0)->ios::sync_with_stdio(0);

    cout << setiosflags(ios::fixed) << setprecision(2);

    int TT = 1;

    cin >> TT;

    while (TT--)

    {

        solve();

        cout << endl;

    }

}

Submission (verdict: Accepted):
// #pragma GCC optimize(2)

#include <bits/stdc++.h>

using namespace std;

#define int long long

#define endl '\n'

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



constexpr int MOD = 1e9 + 7;

// -9.2e18 ~ 9.2e18



void solve()

{

    int n, m;

    cin >> n >> m; 



    priority_queue<int, vector<int>> pqa, pqb;

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

    {

        int num;

        cin >> num;

        pqa.push(num);

    }

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

    {

        int num;

        cin >> num;

        pqb.push(num);

    }

    while (pqa.size() and pqb.size())

    {

   

        if (pqa.size() < pqb.size())

        {

            cout << "No";

            return;

        }

        if (pqa.top() == pqb.top())

        {

            pqb.pop();

            pqa.pop();

            continue;

        }

        if (pqa.top() > pqb.top())

        {

            cout << "No";

            return;

        }

        else

        {

            auto num1 = pqb.top() >> 1, num2 = (pqb.top() + 1) >> 1;

            pqb.pop();

            pqb.push(num1);

            pqb.push(num2);

        }

    }



    cout << (pqa.empty() and pqb.empty() ? "Yes" : "No");

}



signed main()

{

    cin.tie(0)->ios::sync_with_stdio(0);

    cout << setiosflags(ios::fixed) << setprecision(2);

    int TT = 1;

    cin >> TT;

    while (TT--)

    {

        solve();

        cout << endl;

    }

}