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


Submission (verdict: Wrong answer on test 3):
/*
|| ॐ त्र्यम्बकं यजामहे सुगन्धिं पुष्टिवर्धनम् उर्वारुकमिव बन्धनान्मृ त्योर्मुक्षीय मामृतात् || हर हर महादेव!
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double lld;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<ll> vl;
typedef pair<ll, ll> pl;
#define yep               \
   cout << "Yes" << endl; \
   return;
#define nope             \
   cout << "No" << endl; \
   return;
#define pb push_back
#define int long long
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i >= b; i--)
#define sq(a) a *a
#define nl endl;
#define inf (1LL << 60)
const int Mod = 1e9 + 7;
#define all(x) x.begin(), x.end()

int inv(ll i)
{
   if (i == 1)
      return 1;
   return (Mod - ((Mod / i) * inv(Mod % i)) % Mod) % Mod;
}
int mod(int a, int m)
{
   return (a % m + m) % m;
}
int mod_mul(int a, int b, int m = Mod) { return mod(mod(a, m) * mod(b, m), m); }
int mod_pow(int a, int b, int m)
{
   if (b == 0)
      return 1;
   else
      return mod_mul(a, mod_pow(a, b - 1, m), m);
}
int mod_div(int a, int b, int d = Mod)
{
   return mod_mul(a, mod_pow(b, d - 2, d));
}
ll power(ll a, ll b, int M = Mod)
{
   a = a % M;
   int result = 1;
   while (b > 0)
   {
      if (b & 1)
         result = (result * 1LL * a) % M;
      a = (a * 1LL * a) % M;
      b >>= 1;
   }
   return result;
}
// uint64_t ; for 64 bits
// uint32_t ; for 32 bits
// no of subarrays if atleast k elements are required from an array of size n = (n+1-k)*(n+2-k)/2;
//__builtin_popcount(x) = returns set bits
void solve()
{
   ll n;
   cin >> n;
   int m;
   cin >> m;
   vector<int> a(n), b(m);
   multiset<int> aa, bb;
   for (int i = 0; i < n; i++)
   {
      cin >> a[i];
      aa.insert(a[i]);
   }
   for (int i = 0; i < m; i++)
   {
      cin >> b[i];
      bb.insert(b[i]);
   }
   // for(auto i : aa){
   //    cout << i << " ";
   // }
   // cout << endl;
   // for(auto i : bb){
   //    cout << i << " ";
   // }
   // cout << endl;
   vector<int> remove;
   for (auto i : aa)
   {
      if (bb.find(i) != bb.end())
      {
         remove.push_back(i);
         bb.erase(bb.find(i));
      }
   }
   // cout << "removing" << endl;
   // for(auto i : remove){
   //    cout << i << " ";
   // }
   // cout << endl;
   for (auto i : remove)
   {
      aa.erase(aa.find(i));
      // bb.erase(bb.find(i));
   }
   // cout << "remainging set " << endl;
   // for(auto i : aa){
   //    cout << i << " ";
   // }
   // cout << endl;
   // for(auto i : bb){
   //    cout << i << " ";
   // }
   // cout << endl;

   // ab a main wo hai jo hume hatane hai and b main wo hai jo bache hai to get
   /*
      ab jaise koi bhi element i hai ... teen options hai jaha ye merge ho sakta hai



      to aisi baat hai .. ki jo sabse chote elements hai .. unko to merge karna hi padega, no option they have
      bade walo ke paas to fir bhi option hai ki ya to apas main merge ho jao, ya fir koi chote wale bade banenge

   */
   // function<bool()> fun = [&]()
   // {
   //    cout << "check kar rhe hai bass" << endl;
   //    return true;
   // };
   // cout << "ans : " << endl;
   while (aa.size() && bb.size())
   {

      int x = *(aa.begin());
      aa.erase(aa.begin());
      // cout << "here : " << x << endl;
      auto itr = aa.lower_bound(x);
      // for(auto i : aa){
      //    cout << i << " ";
      // }
      // cout << endl;
      if (itr == aa.end())
      {
         nope;
      }
      int y = *itr;
      if (abs(y - x) > 1)
      {
         nope;
      }
      else
      {
         // cout << "here2" << endl;
         aa.erase(aa.find(y));
         int s = x + y;
         // cout << "s: " << s << endl;
         if ( bb.find(s) != bb.end())
         {
            bb.erase(bb.find(s));
         }
         else
         {
            // cout << "insert" << endl;
            aa.insert(s);
         }
      }
   }
   if (aa.size() == 0 && bb.size() == 0)
   {
      yep;
   }
   else
   {
      nope;
   }
}
signed main()
{
   ios::sync_with_stdio(0);
   cin.tie(0);
   int t = 1;
   cin >> t;
   while (t--)
   {
      solve();
   }
}
/*
|| ॐ त्र्यम्बकं यजामहे सुगन्धिं पुष्टिवर्धनम् उर्वारुकमिव बन्धनान्मृ त्योर्मुक्षीय मामृतात् || जय शिव शम्भू !
*/