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

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

#define IO cin.tie(0) -> sync_with_stdio(0)

#define endl "\n"

#define F first

#define S second

#define pLL pair<LL, LL>

#define mkp make_pair

#define pb emplace_back

#define LL loli

#define loli long long

using namespace std;

template<typename T> using Vec = vector<T>;

template<typename T> using Mat = Vec<Vec<T> >;

const LL mod = 1e9+7, inf = 9e18, maxN = 0;



LL TT = 1;

LL n, m;

priority_queue<LL, Vec<LL>, greater<LL>> pq;

Vec<LL> vec;



void solve() {

  cin >> n >> m;

  while(!pq.empty()) pq.pop();

  while(n--) {

    LL x;

    cin >> x;

    pq.push(x);

  }

  vec.assign(m, 0);

  for(auto &i : vec) cin >> i;

  sort(vec.begin(), vec.end());

  bool bln=1;

  for(auto &i : vec) {

    bool bln2=0;

    while(pq.size()>=2) {

      if(i==pq.top()) {

        pq.pop();

        bln2=1;

        break;

      }

      LL a = pq.top(); pq.pop();

      LL b = pq.top(); pq.pop();

      // cout << a << ' ' << b << "???" << endl;

      if(llabs(a-b)>1) {

        bln2=1;

        bln=0;

        break;

      }

      pq.push(a+b);

    }

    if(!bln2) {

      if(pq.empty()) bln=0;

      else if(pq.top()!=i) bln=0;

      else pq.pop();

    }

    if(!bln) break;

  }

  bln &= pq.empty();

  cout << (bln ? "Yes" : "No") << endl;

}



int main() {

  IO;

  cin >> TT;

  for(int cs=0; cs<TT; cs++) {

    solve();

  }

}



Submission (verdict: Runtime error on test 3):
#include<bits/stdc++.h>

#define IO cin.tie(0) -> sync_with_stdio(0)

#define endl "\n"

#define F first

#define S second

#define pLL pair<LL, LL>

#define mkp make_pair

#define pb emplace_back

#define LL loli

#define loli long long

using namespace std;

template<typename T> using Vec = vector<T>;

template<typename T> using Mat = Vec<Vec<T> >;

const LL mod = 1e9+7, inf = 9e18, maxN = 0;



LL TT = 1;

LL n, m;

multiset<LL> st;

Vec<LL> vec;



void solve() {

  cin >> n >> m;

  st.clear();

  while(n--) {

    LL x;

    cin >> x;

    st.insert(x);

  }

  vec.assign(m, 0);

  for(auto &i : vec) cin >> i;

  sort(vec.begin(), vec.end());

  bool bln=0;

  for(auto &i : vec) {

    if(*st.find(i)==i) {

      // cout << i << " !!!" << endl;

      st.erase(st.find(i));

      continue;

    }

    LL a = i/2, b = i-a;

    bool bln2=0;

    while(st.size()>=2) {

      auto ait = st.find(a), bit = st.find(b);

      if(bit==ait) bit = next(bit);

      if(ait!=st.end() && bit!=st.end() && *bit==b) {

        // cout << a << ' ' << b << ' ' << i << " !!!" << endl;

        st.erase(ait);

        st.erase(st.find(b));

        bln2=1;

        break;

      }

      LL x = *st.begin(); st.erase(st.begin());

      LL y = *st.begin(); st.erase(st.begin());

      if(y-x>1) {

        bln2=1;

        bln=1;

        break;

      }

      st.insert(x+y);

    }

    if(!bln2) {

      if(st.empty()) bln=1;

      else if(*st.begin()!=i) bln=1;

      else st.erase(st.begin());

    }

    if(bln) break;

  }

  bln |= !st.empty();

  cout << (!bln ? "Yes" : "No") << endl;

}



int main() {

  IO;

  cin >> TT;

  for(int cs=0; cs<TT; cs++) {

    solve();

  }

}