alexjercan/bugnet huggingface dataset:
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

int main() {
  int x, n;
  cin >> x >> n;
  bool visited[150];
  memset(visited, false, sizeof(visited));
  int u;
  for (int i = 0; i < n; i++) {
    cin >> u;
    visited[u] = true;
  }
  int smaller = x, larger = x;
  while (true) {
    // cout
    // <<smaller<<","<<larger<<":"<<visited[smaller]<<","<<visited[larger]<<endl;
    if (!visited[smaller]) {
      cout << smaller << endl;
      return 0;
    }
    if (!visited[larger]) {
      cout << larger << endl;
      return 0;
    }
    smaller--;
    larger++;
  }
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  int x, n;
  cin >> x >> n;
  bool visited[n];
  memset(visited, 0, sizeof(visited));
  int u;
  for (int i = 0; i < n; i++) {
    cin >> u;
    visited[u] = true;
  }
  int smaller = x, larger = x;
  while (true) {
    if (!visited[smaller]) {
      cout << smaller << endl;
      return 0;
    }
    if (!visited[larger]) {
      cout << larger << endl;
      return 0;
    }
    smaller--;
    larger++;
  }
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
#define mset(s, _) memset(s, _, sizeof s)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
// head
map<int, int> a;
void run() {
  int n, x;
  cin >> x >> n;
  for (int i = 1; i <= n; i++) {
    int tp;
    cin >> tp;
    a[tp] = 1;
  }
  if (n == 0) {
    cout << x << '\\n';
    return;
  }
  int ans = 0;
  int pre = 1000, pos = 0;
  for (int i = -1000; i <= 1000; i++) {
    if (!a[i] && abs(i - x) < pre)
      pos = i, pre = abs(i - x);
  }
  cout << pos << '\\n';
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(20);
  // int T; cin >> T; while (T--)
  run();
  return 0;
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
#define mset(s, _) memset(s, _, sizeof s)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
// head
int a[110];
void run() {
  int n, x;
  cin >> x >> n;
  for (int i = 1; i <= n; i++) {
    int tp;
    cin >> tp;
    a[tp] = 1;
  }
  if (n == 0) {
    cout << x << '\\n';
    return;
  }
  int ans = 0;
  int pre = 1000, pos = 0;
  for (int i = -1000; i <= 1000; i++) {
    if (!a[i] && abs(i - x) < pre)
      pos = i, pre = abs(i - x);
  }
  cout << pos << '\\n';
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(20);
  // int T; cin >> T; while (T--)
  run();
  return 0;
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

int x, n;
int p[110];
bool ans[110];
bool check[110];
queue<int> que;

int near(int x) {
  check[x] = true;
  if (x - 1 < 0)
    return 0;
  else if (!ans[x - 1])
    return x;
  else {
    if (!check[x - 1])
      que.push(x - 1);
    if (!check[x + 1])
      que.push(x + 1);
    int next = que.front();
    que.pop();
    return near(next);
  }
}

int main() {
  cin >> x >> n;

  if (n == 0) {
    cout << x << endl;
    return 0;
  }

  rep(i, n) cin >> p[i];

  memset(ans, false, sizeof(ans));
  rep(i, n) ans[p[i] - 1] = true;

  cout << near(x) << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

int x, n;
int p[110];
bool ans[110];
queue<int> que;

int near(int x) {
  if (x - 1 >= 0) {
    if (!ans[x - 1])
      return x;
  } else
    return 0;

  que.push(x - 1);
  que.push(x + 1);
  int next = que.front();
  que.pop();
  return near(next);
}

int main() {
  cin >> x >> n;

  rep(i, n) cin >> p[i];
  if (n == 0) {
    cout << x << endl;
    return 0;
  } else if (n == 100) {
    cout << 0 << endl;
    return 0;
  }

  memset(ans, false, sizeof(ans));
  rep(i, n) ans[p[i] - 1] = true;

  cout << near(x) << endl;
  return 0;
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {

  cin.tie(0);
  ios::sync_with_stdio(false);

  int x, n;
  cin >> x >> n;

  if (n == 0) {
    cout << x << endl;
    return 0;
  }

  vector<int> a(n), b(0);
  rep(i, n) cin >> a[i];
  sort(all(a));

  int j = 0;

  rep(i, 100) {
    if (i + 1 != a[j]) {
      b.push_back(i + 1);
      // cout << i+1 << endl;
    } else
      j++;
  }
  int l = b.size();

  if (l == 0) {
    if (x <= 50) {
      cout << 0 << endl;
      return 0;
    } else {
      cout << 101 << endl;
      return 0;
    }
  }
  vector<int> c(l);

  rep(i, l) c[i] = abs(b[i] - x);

  sort(all(c));

  int d = c[0];

  // cout << d << endl;

  rep(i, n) {
    if (b[i] == x - d) {
      cout << x - d << endl;
      return 0;
    } else if (x - d <= 0) {
      cout << 0 << endl;
      return 0;
    } else if (b[i] == x + d) {
      cout << x + d << endl;
      return 0;
    } else if (x + d >= 101) {
      cout << 101 << endl;
      return 0;
    }
  }

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {

  cin.tie(0);
  ios::sync_with_stdio(false);

  int x, n;
  cin >> x >> n;

  if (n == 0) {
    cout << x << endl;
    return 0;
  }

  vector<int> a(n), b(0);
  rep(i, n) cin >> a[i];
  sort(all(a));

  int j = 0;

  rep(i, 100) {
    if (i + 1 != a[j]) {
      b.push_back(i + 1);
      // cout << i+1 << endl;
    } else
      j++;
  }
  int l = b.size();
  vector<int> c(l);

  rep(i, l) c[i] = abs(b[i] - x);

  sort(all(c));

  int d = c[0];

  // cout << d << endl;

  rep(i, n) {
    if (b[i] == x - d) {
      cout << x - d << endl;
      return 0;
    } else if (x - d <= 0) {
      cout << 0 << endl;
      return 0;
    } else if (b[i] == x + d) {
      cout << x + d << endl;
      return 0;
    } else if (x + d >= 101) {
      cout << 101 << endl;
      return 0;
    }
  }

  return 0;
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int x, n;
  int p[105];
  int mi, minv, maxv = 0, ans = 0;
  int flg[105] = {};
  cin >> x >> n;
  minv = 105;
  for (int i = 0; i < n; i++) {
    cin >> p[i];
    flg[p[i]] = 1;
    maxv = max(p[i], maxv);
    minv = min(p[i], minv);
  }
  mi = (x - (minv - 1));
  ans = minv - 1;
  if (n == 0) {
    cout << x << '\\n';
  } else {
    for (int i = minv; i <= maxv + 1; i++) {
      if (mi > abs(x - i)) {
        if (flg[i] != 1) {
          mi = abs(x - i);
          ans = i;
        }
      }
    }
    cout << ans << '\\n';
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int x, n;
  int p[105];
  int mi, minv, maxv = 0, ans = 0;
  int flg[105] = {};
  cin >> x >> n;
  for (int i = 0; i < n; i++) {
    cin >> p[i];
    flg[p[i]] = 1;
    maxv = max(p[i], maxv);
    minv = min(p[i], minv);
  }
  mi = (x - (minv - 1));
  ans = minv - 1;
  if (n == 0) {
    cout << x << '\\n';
  } else {
    for (int i = minv; i <= maxv + 1; i++) {
      if (mi > abs(x - i)) {
        if (flg[i] != 1) {
          mi = abs(x - i);
          ans = i;
        }
      }
    }
    cout << ans << '\\n';
  }
  return 0;
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define reps(i, n) for (ll i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (ll i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (ll i = ((int)(n)); i > 0; --i)
#define ll long long
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define optimize_cin()                                                         \\
  cin.tie(0);                                                                  \\
  ios::sync_with_stdio(false)
#define P pair<int, int>
using namespace std;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
ll lmax(ll a, ll b) {
  if (a >= b)
    return a;
  return b;
}
ll lmin(ll a, ll b) {
  if (a >= b)
    return b;
  return a;
}
static const ll INF = 1e18;

int main() {
  int x, n;
  cin >> x >> n;
  vector<bool> v(n + 1, false);
  rep(i, n) {
    int p;
    cin >> p;
    v[p] = true;
  }

  int ans = 0;
  reps(i, 101) {
    if (v[i])
      continue;
    if (abs(x - ans) > abs(x - i)) {
      ans = i;
    }
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define reps(i, n) for (ll i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (ll i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (ll i = ((int)(n)); i > 0; --i)
#define ll long long
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define optimize_cin()                                                         \\
  cin.tie(0);                                                                  \\
  ios::sync_with_stdio(false)
#define P pair<int, int>
using namespace std;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
ll lmax(ll a, ll b) {
  if (a >= b)
    return a;
  return b;
}
ll lmin(ll a, ll b) {
  if (a >= b)
    return b;
  return a;
}
static const ll INF = 1e18;

int main() {
  int x, n;
  cin >> x >> n;
  priority_queue<int, vector<int>, greater<int>> q;
  rep(i, n) {
    int p;
    cin >> p;
    q.push(p);
  }

  int ans = 0;
  reps(i, 100) {
    if (i == q.top()) {
      q.pop();
    } else {
      if (abs(x - ans) > abs(x - i)) {
        ans = i;
      }
    }
  }

  cout << ans << endl;
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <cmath>
using namespace std;
#define _GLIBCXX_DEBUG
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; i++)
#define vl vector<ll>
#define vpl vector<pair<ll, ll>>
#define vvl vector<vector<ll>> // a(縦行,vector<ll>(横列));
#include <algorithm>           //__gcd(a,b)
#include <cstdlib>
#include <iostream>
#include <vector>
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

const long long INF = 1LL << 60;

int main() {
  ll x, n;
  cin >> x >> n;

  if (n != 0) {
    vl a(n);
    rep(i, n) cin >> a[i];
    ll ans = x + 1;
    ll dis = 0;
    sort(a.begin(), a.end());
    ll j = 0;

    rep(i, a[n] + 200) {

      if (abs(x - i) < ans && i != a[j]) {
        ans = abs(x - i);
        dis = i;
      }
      if (i == a[j])
        j++;
    }

    cout << dis << endl;
  }

  if (n == 0)
    cout << x << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <cmath>
using namespace std;
#define _GLIBCXX_DEBUG
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; i++)
#define vl vector<ll>
#define vpl vector<pair<ll, ll>>
#define vvl vector<vector<ll>> // a(縦行,vector<ll>(横列));
#include <algorithm>           //__gcd(a,b)
#include <cstdlib>
#include <iostream>
#include <vector>
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

const long long INF = 1LL << 60;

int main() {
  ll x, n;
  cin >> x >> n;
  vl a(n);
  rep(i, n) cin >> a[i];
  ll ans = x + 1;
  ll dis = 0;
  sort(a.begin(), a.end());
  ll j = 0;

  rep(i, a[n]) {

    if (abs(x - i) < ans && i != a[j]) {
      ans = abs(x - i);
      dis = i;
    }
    if (i == a[j])
      j++;
  }

  cout << dis << endl;
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define LOOP(i, N) for (int i = 1; i <= (int)N; i++)
#define RREP(i, N) for (int i = (int)N - 1; i >= 0; i--)
#define RLOOP(i, N) for (int i = (int)N; i > 0; i--)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define pb push_back

typedef long long ll;

typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;
// cout<<"Yes"<<endl;
// cout<<"No"<<endl;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
  int x, n;
  cin >> x >> n;
  int v[102];
  memset(v, 0, sizeof(v));
  REP(i, n) {
    int tmp;
    cin >> tmp;
    v[tmp] = 1;
  }
  if (v[x] != 1 || n == 0) {
    cout << x << endl;
    return 0;
  }
  for (int i = 0;; i++) {
    if (x - i >= 0) {
      if (v[x - i] != 1) {
        cout << x - i << endl;
        return 0;
      }
    }
    if (x + i <= 101) {
      if (v[x + i] != 1) {
        cout << x + i << endl;
        return 0;
      }
    }
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define LOOP(i, N) for (int i = 1; i <= (int)N; i++)
#define RREP(i, N) for (int i = (int)N - 1; i >= 0; i--)
#define RLOOP(i, N) for (int i = (int)N; i > 0; i--)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define pb push_back

typedef long long ll;

typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;
// cout<<"Yes"<<endl;
// cout<<"No"<<endl;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
  int x, n;
  cin >> x >> n;
  int v[101];
  memset(v, 0, sizeof(v));
  REP(i, n) {
    int tmp;
    cin >> tmp;
    v[tmp] = 1;
  }
  if (v[x] != 1 || n == 0) {
    cout << x << endl;
    return 0;
  }
  for (int i = 0;; i++) {
    if (x - i > 0) {
      if (v[x - i] != 1) {
        cout << x - i << endl;
        return 0;
      }
    }
    if (x + i <= 100) {
      if (v[x + i] != 1) {
        cout << x + i << endl;
        return 0;
      }
    }
  }
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647 -> 10桁
// MAX ll 9,223,372,036,854,775,807 -> 19桁
// MAX O(n) 10^18 -> 18回

int main() {
  int x, n;
  cin >> x >> n;
  vector<int> d(102);
  rep(i, n) {
    int p;
    cin >> p;
    d[p] = 1;
  }
  P ans(999999, -1);
  for (int i = 0; i <= 101; i++) {
    if (d[i] == 1)
      continue;
    int dif = abs(x - i);
    ans = min(ans, P(dif, i));
  }
  cout << ans.second << endl;
  return 0;
}


Error: -6
malloc(): corrupted top size


Fixed submission:

#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647 -> 10桁
// MAX ll 9,223,372,036,854,775,807 -> 19桁
// MAX O(n) 10^18 -> 18回

int main() {
  int x, n;
  cin >> x >> n;
  vector<int> d(n);
  rep(i, n) {
    int p;
    cin >> p;
    d[p] = 1;
  }
  P ans(999999, -1);
  for (int i = 0; i <= 101; i++) {
    if (d[i] == 1)
      continue;
    int dif = abs(x - i);
    ans = min(ans, P(dif, i));
  }
  cout << ans.second << endl;
  return 0;
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

int main() {
  int X, N;
  cin >> X >> N;
  vector<int> p(N), excluded_p;
  for (int i = 0; i < N; i++)
    cin >> p.at(i);
  sort(p.begin(), p.end());
  for (int i = 0; i <= 101; i++) {
    if (!binary_search(p.begin(), p.end(), i))
      excluded_p.push_back(i);
  }
  // for (auto x : excluded_p) cout << "E" << x << endl;

  int minimum = 0xff;
  int chosen = 0xff;
  for (auto x : excluded_p) {
    int y = abs(X - x);
    if (minimum > y)
      minimum = y, chosen = x;
  }

  cout << chosen << endl;

  // bitset<100> hai;
  // for(int j=0;j<N;j++){
  //   hai.set(hairetu.at(j)-1,1);
  // }
  //
  // int kekka = 1000;
  // int count1=0;
  // int count2=0;
  //
  // for(int k=X;k<101;k++){
  //   if(hai.test(k-1) == 0){
  //     kekka = k;
  //     break;
  //   }
  //   count1++;
  // }
  //
  // for(int l=X;l>0;l--){
  //   if(hai.test(l-1) == 0){
  //     if(count1<count2){
  //       break;
  //     }
  //     else if(count1>=count2){
  //       kekka = l;
  //       break;
  //     }
  //   }
  //   count2++;
  // }
  //
  // if(kekka==1000){
  //   if(X>=51){
  //     cout << 101 <<endl;
  //   }
  //   else{
  //     cout << 0 <<endl;
  //   }
  // }
  // else{
  //   cout << kekka <<endl;
  // }
  //
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {
  int X, N;
  cin >> X >> N;
  vector<int> hairetu(N);
  for (int i = 0; i < N; i++) {
    cin >> hairetu.at(i);
  }

  bitset<100> hai;
  for (int j = 0; j < N; j++) {
    hai.set(hairetu.at(j) - 1, 1);
  }

  int kekka = 1000;
  int count1 = 0;
  int count2 = 0;

  for (int k = X; k < 101; k++) {
    if (hai.test(k - 1) == 0) {
      kekka = k;
      break;
    }
    count1++;
  }

  for (int l = X; l >= 0; l--) {
    if (hai.test(l - 1) == 0) {
      if (count1 < count2) {
        break;
      } else if (count1 >= count2) {
        kekka = l;
        break;
      }
    }
    count2++;
  }

  if (kekka == 1000) {
    if (X >= 51) {
      cout << 101 << endl;
    } else {
      cout << 0 << endl;
    }
  } else {
    cout << kekka << endl;
  }
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <unordered_set>
#include <vector>

#define ull unsigned long long
#define ll long long
#define mp make_pair
#define imei(...) "[ " << #__VA_ARGS__ << " = " << __VA_ARGS__ << " ] "

using namespace std;

void solve(int t) {
  int n;
  cin >> n;
}

int main(int argc, char *argv[]) {
  int target, n;
  set<int> s;
  priority_queue<pair<int, int>> pq;
  cin >> target >> n;
  int mx = 1e9 + 5;
  int ans = target;

  if (!n) {
    cout << target << endl;
    return 0;
  }

  for (int i = 0; i < n; i++) {
    int val;
    cin >> val;
    s.insert(val);
  }

  for (int i = -200; i <= 200; i++) {
    if (s.find(i) != s.end())
      continue;
    if (abs(i - target) < mx) {
      ans = i;
      mx = abs(i - target);
    }
  }

  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <unordered_set>
#include <vector>

#define ull unsigned long long
#define ll long long
#define mp make_pair
#define imei(...) "[ " << #__VA_ARGS__ << " = " << __VA_ARGS__ << " ] "

using namespace std;

void solve(int t) {
  int n;
  cin >> n;
}

int main(int argc, char *argv[]) {
  int target, n;
  set<int> s;
  priority_queue<pair<int, int>> pq;
  cin >> target >> n;

  if (!n) {
    cout << target << endl;
    return 0;
  }

  for (int i = 0; i < n; i++) {
    int val;
    cin >> val;
    s.insert(val);
  }
  for (int i = 1; i <= 100; i++) {
    if (s.find(i) != s.end())
      continue;
    pq.push({-abs(i - target), -i});
  }

  cout << -pq.top().second << endl;

  return 0;
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int X, N;
  cin >> X >> N;

  if (N == 0) {
    cout << X << endl;
    return 0;
  }

  vector<int> P(N);
  vector<int> ans;
  for (int i = 0; i < N; i++) {
    cin >> P[i];
  }
  sort(P.begin(), P.end());

  for (int a = X - (N + 1) / 2; a <= X + (N + 1) / 2; a++) {
    ans.push_back(a);
  }

  for (size_t i = 0; i < P.size(); i++) {
    auto result = find(ans.begin(), ans.end(), P[i]);
    if (result != ans.end()) {
      ans.erase(result);
    }
  }
  int above = *lower_bound(ans.begin(), ans.end(), X);
  int dis = above - X;
  if (dis == 0) {
    cout << X << endl;
    return 0;
  }

  int low = ans[0];
  for (size_t i = 0; i < ans.size(); i++) {
    // X との絶対値の小さいindex を探す
    if (ans[i] < above) {
      low = max(ans[i], low);
    }
  }
  int answer = dis < abs(low - X) ? dis : low - X;
  cout << answer + X << endl;
}

Error: -6
Fatal glibc error: malloc assertion failure in sysmalloc: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)


Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int X, N;
  cin >> X >> N;

  if (N == 0)
    cout << X << endl;

  vector<int> P(N);
  vector<int> ans((N + 1) / 2 + 1);
  for (int i = 0; i < N; i++) {
    cin >> P[i];
  }
  sort(P.begin(), P.end());

  int idx = 0;
  for (int a = X - (N + 1) / 2; a <= X + (N + 1) / 2; a++) {
    ans[idx] = a;
    idx++;
  }

  for (size_t i = 0; i < P.size(); i++) {
    if (count(ans.begin(), ans.end(), P[i]) >= 1) {
      ans.erase(ans.begin() + i);
    }
  }
  int above = *lower_bound(ans.begin(), ans.end(), X);
  int dis = X - above;
  if (dis == 0)
    cout << X << endl;

  int low = ans[0];
  for (size_t i = 0; i < ans.size(); i++) {
    // X との絶対値の小さいindex を探す
    if (ans[i] < above) {
      low = max(ans[i], low);
    }
  }
  int answer = dis < abs(low - X) ? dis : low;
  cout << answer << endl;
}