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

// include
//------------------------------------------
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define SHOW_VECTOR(v)                                                         \\
  {                                                                            \\
    std::cerr << #v << "\\t:";                                                  \\
    for (const auto &xxx : v) {                                                \\
      std::cerr << xxx << " ";                                                 \\
    }                                                                          \\
    std::cerr << "\\n";                                                         \\
  }
#define SHOW_MAP(v)                                                            \\
  {                                                                            \\
    std::cerr << #v << endl;                                                   \\
    for (const auto &xxx : v) {                                                \\
      std::cerr << xxx.first << " " << xxx.second << "\\n";                     \\
    }                                                                          \\
  }

int main() {

  int N;
  cin >> N;

  vector<int> A(N), B(N);
  for (int i = 0; i < N; i++)
    cin >> A[i] >> B[i];

  vector<int> AB;
  for (int i = 0; i < N; i++)
    AB.push_back(A[i]), AB.push_back(B[i]);
  sort(AB.begin(), AB.end());
  AB.erase(unique(AB.begin(), AB.end()), AB.end());

  map<int, int> M;
  for (int i = 0; i < AB.size(); i++)
    M[AB[i]] = i + 1;

  for (int i = 0; i < N; i++)
    A[i] = M[A[i]];
  for (int i = 0; i < N; i++)
    B[i] = M[B[i]];

  vector<int> imos(200100, 0);
  for (int i = 0; i < N; i++) {
    imos[A[i]]++;
    imos[B[i] + 1]--;
  }
  for (int i = 0; i < imos.size() - 2; i++)
    imos[i + 1] += imos[i];

  int ans = *max_element(imos.begin(), imos.end());
  cout << ans << endl;
}


Error: 0

Fixed submission:

// include
//------------------------------------------
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define SHOW_VECTOR(v)                                                         \\
  {                                                                            \\
    std::cerr << #v << "\\t:";                                                  \\
    for (const auto &xxx : v) {                                                \\
      std::cerr << xxx << " ";                                                 \\
    }                                                                          \\
    std::cerr << "\\n";                                                         \\
  }
#define SHOW_MAP(v)                                                            \\
  {                                                                            \\
    std::cerr << #v << endl;                                                   \\
    for (const auto &xxx : v) {                                                \\
      std::cerr << xxx.first << " " << xxx.second << "\\n";                     \\
    }                                                                          \\
  }

int main() {

  long long N;
  cin >> N;

  vector<long long> imos(100010, 0);
  for (int i = 0; i < N; i++) {
    int A, B;
    cin >> A >> B;
    imos[A]++;
    imos[B + 1]--;
  }

  for (int i = 1; i <= 100008; i++) {
    imos[i] += imos[i - 1];
  }

  long long maxV = *max_element(imos.begin(), imos.end());

  cout << maxV << endl;
}