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

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

using ll = long long;
using vi = vector <ll>;
using vll = vector<ll>;
using vs = vector <string>;
using vb = vector <bool>;
using vd = vector <double>;
using vc = vector <char>;
using pii = pair<ll, ll>;
using pib = pair<ll, bool>;
using vpib = vector<pair<ll, bool>>;
using pll = pair<ll, ll>;
using vpii = vector <pii>;

bool update(map<ll, ll> &freqa, map<ll, ll> &freqb) {
    auto q = freqb.rbegin();
    if(freqa.find(q->first) != freqa.end()){
        // cerr<<q->first<<" "<<q->second<<" "<<freqa[q->first]<<".\n";
        ll diff = min(freqa[q->first], freqb[q->first]);
        ll num = q->first;
        freqb[q->first] -= diff;
        freqa[q->first] -= diff;
        if(freqb[q->first] == 0){
            freqb.erase(q->first);
        }
        if(freqa[num] == 0)
            freqa.erase(num);
        return true;
    }
    ll x = q->first / 2, y = (q->first + 1) / 2;
    if(x == 0)
    {
        freqb.erase(q->first);
        return true;
    }
    freqb[x] += freqb[q->first];
    freqb[y] += freqb[q->first];
    // cerr<<q->first<<" "<<q->second<<"h:"<<'\n';
    freqb.erase(q->first);
    return true;
}

void solve(){
    ll n, m;
    cin>>n>>m;
    map<ll, ll> freqa;
    map<ll, ll> freqb;
    vector<ll> el(n);

    ll sum1 = 0, sum2 = 0;
    for(auto &x : el)
    {
        cin>>x;
        freqa[x]++;
        sum1 += x;
    }
    vector<ll> el2(m);

    for(auto &x : el2)
    {
        cin>>x;
        freqb[x]++;
        sum2 += x;
    }
    
    if(sum1 != sum2)
    {
        cout<<"No\n";
        return;
    }

    while(freqb.size() and freqa.size()){
        auto q = freqb.rbegin();
        update(freqa, freqb);
    }

    if(freqb.empty() and freqa.empty())
    {
        cout<<"Yes\n";
    }
    else 
        cout<<"No\n";
    
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);

    ll t;
    cin>>t;
    while(t--)
        solve();
}

Submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define B7AIRY                    \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define YES return void(cout << "YES\n")
#define NO return void(cout << "NO\n")
#define RN1 return void(cout << "-1\n")
#define ld long double
#define ll long long
#define PI acos(-1) a
#define endl "\n"
#define int ll
const ll N = 1e6 + 10, mod = 1e9 + 7;
const int dx[] = { 1, -1, 0, 0, 1, -1, 1, -1 };
const int dy[] = { 0, 0, 1, -1, 1, 1, -1, -1 };
class DSU {
private:
    vector<int> Parent;
    vector<int> GroupSize;
    vector<int> Max;
    int Components;
public:
    DSU(int n) {
        Parent = vector<int>(n + 1);
        iota(Parent.begin(), Parent.end(), 0);
        Parent.push_back(0);
        Components = n;
        GroupSize = vector<int>(n + 1, 1);
    }
    int FindParent(int node) {
        if (Parent[node] == node) return node;
        return Parent[node] = FindParent(Parent[node]);
    }
    int GetGroupSize(int node) {
        return GroupSize[FindParent(node)];
    }
    void Merge(int u, int v) {
        u = FindParent(u);
        v = FindParent(v);
        if (u == v) return;
        if (GroupSize[u] < GroupSize[v]) swap(u, v);
        Parent[v] = u;
        GroupSize[u] += GroupSize[v];
        Components--;
    }

    int GetGroupCount() {
        return Components;
    }
    bool IsSameGroup(int u, int v) {
        return FindParent(u) == FindParent(v);
    }
};
void solution() {
    int n, m; cin >> n >> m;
    multiset<int>mst1, mst2;
    for (int i = 0; i < n; i++) {
        int x; cin >> x;
        mst1.insert(x);
    }
    for (int i = 0; i < m; i++) {
        int x; cin >> x;
        mst2.insert(x);
    }
    vector<int>tt;
    for (auto i : mst2) {
        auto it = (mst1.find(i));
        if (it != mst1.end())tt.push_back(*it), mst1.erase(it);
    }
    for (auto t : tt)mst2.erase(mst2.find(t));
    m += 10;
    while (mst1.size() && mst2.size() && m--) {

        while (mst1.size() && mst2.size() && *mst1.begin() == *mst2.begin()) {
            mst1.erase(mst1.begin());
            mst2.erase(mst2.begin());
        }
        if (!mst2.size())YES;
        int mx = *mst2.rbegin();
        //  cout << mx << endl;
        if (mst1.find(mx / 2) != mst1.end()) {
            mst1.erase(mst1.find(mx / 2));
        }
        else mst2.insert((mx) / 2);
        if (mst1.find((mx + 1) / 2) != mst1.end()) {
            mst1.erase(mst1.find((mx + 1) / 2));
        }
        else mst2.insert((mx + 1) / 2);
        mst2.erase(mst2.find(mx));
    }
    if (mst1 == mst2)YES;
    else NO;
}
signed main()
{
    B7AIRY
#ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int t = 1;
    cin >> t;
    for (int i = 1; i <= t; i++)
    {

        // cout< "Case #" << i << ": ";
        solution();
    }
}