Problem p02641 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
struct Edge {
  ll to;
  ll cost;
};
using Graph = vector<vector<Edge>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 2.0 * asin(1.0);
const ll INF = 1L << 60;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ll MAX = 10000000;
/****** define constant end ********/
/****** define variable start ******/
ll x, n;
vl p;
/******* define variable end *******/
int solve() {
  cin >> x >> n;
  p.resize(n);
  REP(i, n) { cin >> p[i]; }
  if (n == 0) {
    cout << x << endl;
    return 0;
  }
  vl no;
  for (ll i = -1; i <= 105; i++) {
    if (find(ALL(p), i) == p.end()) {
      no.push_back(i);
    }
  }
  ll mi = INF;
  ll ite = 0;
  sort(ALL(no));
  for (ll i = no.size() - 1; i >= 0; i--) {
    if (abs(no[i] - x) <= mi) {
      mi = abs(no[i] - x);
      ite = no[i];
    }
  }
  cout << ite << endl;
  return 0;
}

int main() {
  // clock_t start = clock();
  cout << std::fixed << std::setprecision(10);
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int end_solve = solve();
  /*
  clock_t end = clock();
  const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
  1000.0; printf("time %lf[ms]\\n", time);
  */

  return end_solve;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
struct Edge {
  ll to;
  ll cost;
};
using Graph = vector<vector<Edge>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 2.0 * asin(1.0);
const ll INF = 1L << 60;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ll MAX = 10000000;
/****** define constant end ********/
/****** define variable start ******/
ll x, n;
vl p;
/******* define variable end *******/
int solve() {
  cin >> x >> n;
  p.resize(n);
  REP(i, n) { cin >> p[i]; }
  if (n == 0) {
    cout << x << endl;
    return 0;
  }
  vl no;
  for (ll i = 1; i <= 100; i++) {
    if (find(ALL(p), i) == p.end()) {
      no.push_back(i);
    }
  }
  ll mi = INF;
  ll ite = 0;
  for (ll i = p.size() - 1; i >= 0; i--) {
    if (abs(no[i] - x) <= mi) {
      mi = abs(no[i] - x);
      ite = no[i];
    }
  }
  cout << ite << endl;
  return 0;
}

int main() {
  // clock_t start = clock();
  cout << std::fixed << std::setprecision(10);
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int end_solve = solve();
  /*
  clock_t end = clock();
  const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
  1000.0; printf("time %lf[ms]\\n", time);
  */

  return end_solve;
}