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

Previous 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!=st.end()) 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();

  }

}



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;

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)!=st.end()) {

      // 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!=st.end()) 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();

  }

}