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

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
 
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ln '\n'
#define sep ' '
#define ve vector

using namespace std;
 
using pii = pair<int, int>;
using ll  = long long;
using ull = unsigned ll;

constexpr int N = 2e5;
int n, m, a[N], b[N];

void solve()
{
  cin >> n >> m;
  map<int, int> freqa, freqb;
  for (int i = 0; i < n; ++i) 
  {
    cin >> a[i];
    ++freqa[a[i]];
  }
  for (int i = 0; i < m; ++i) 
  {
    cin >> b[i];
    ++freqb[b[i]];
  }
  bool ok = true;
  multiset<ll> mst;
  for (const auto &[k, v] : freqa)
  {
    if (v > freqb[k])
    {
      for (int i = 0; i < v; ++i) mst.insert(k);
    }
  }
  while (mst.size() >= 2)
  {
    ll x = *mst.begin(), y = *next(mst.begin());
    if (freqa[x] == freqb[x])
    {
      mst.erase(mst.begin());
      continue;
    }
    if (freqa[y] == freqb[y])
    {
      mst.erase(next(mst.begin()));
      continue;
    }
    if (x == y && freqa[x] - freqb[x] < 2)
    {
      mst.erase(mst.begin());
      continue;
    }
    if (y - x > 1) 
    { 
      mst.erase(mst.begin());
      continue;
    }
    mst.erase(mst.begin()); mst.erase(mst.begin());
    --freqa[x]; --freqa[y];
    ++freqa[x + y]; mst.insert(x + y);
  }
  for (auto it = freqa.begin(); it != freqa.end(); )
  {
    if (it->second == 0) it = freqa.erase(it);
    else ++it;
  }
  for (auto it = freqb.begin(); it != freqb.end(); )
  {
    if (it->second == 0) it = freqb.erase(it);
    else ++it;
  }
  ok &= freqa == freqb;
  if (ok) cout << "Yes\n";
  else cout << "No\n";
}

int main()
{
  fastio;
  int t = 1; 
  cin >> t;
  while (t--)
  {
    solve();
  }
  return 0;
}


Submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>
 
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ln '\n'
#define sep ' '
#define ve vector

using namespace std;
 
using pii = pair<int, int>;
using ll  = long long;
using ull = unsigned ll;

constexpr int N = 2e5;
int n, m, a[N], b[N];

void solve()
{
  cin >> n >> m;
  map<ll, int> freqa, freqb;
  for (int i = 0; i < n; ++i) 
  {
    cin >> a[i];
    ++freqa[a[i]];
  }
  for (int i = 0; i < m; ++i) 
  {
    cin >> b[i];
    ++freqb[b[i]];
  }
  bool ok = true;
  multiset<ll> mst;
  for (const auto &[k, v] : freqa)
  {
    if (v != freqb[k])
    {
      for (int i = 0; i < v; ++i) mst.insert(k);
    }
  }
  while (mst.size() >= 2)
  {
    ll x = *mst.begin(), y = *next(mst.begin());
    if (freqa[x] == freqb[x])
    {
      mst.erase(mst.begin());
      continue;
    }
    if (freqa[y] == freqb[y])
    {
      mst.erase(next(mst.begin()));
      continue;
    }
    if (x == y && freqa[x] - 2 < freqb[x])
    {
      mst.erase(mst.begin());
      continue;
    }
    if (y - x > 1) 
    { 
      mst.erase(mst.begin());
      continue;
    }
    mst.erase(mst.begin()); mst.erase(mst.begin());
    --freqa[x]; --freqa[y];
    ++freqa[x + y]; mst.insert(x + y);
  }
  for (auto it = freqa.begin(); it != freqa.end(); )
  {
    if (it->second == 0) it = freqa.erase(it);
    else ++it;
  }
  for (auto it = freqb.begin(); it != freqb.end(); )
  {
    if (it->second == 0) it = freqb.erase(it);
    else ++it;
  }
  ok &= freqa == freqb;
  if (ok) cout << "Yes\n";
  else cout << "No\n";
}

int main()
{
  fastio;
  int t = 1; 
  cin >> t;
  while (t--)
  {
    solve();
  }
  return 0;
}