Problem p03203 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

#define x first
#define y second
#define y1 Y1
#define y2 Y2
#define mp make_pair
#define pb push_back
#define DEBUG(x) cout << #x << " = " << x << endl;

using namespace std;

typedef long long LL;
typedef pair<int, int> pii;

template <typename T> inline int Chkmax(T &a, T b) {
  return a < b ? a = b, 1 : 0;
}
template <typename T> inline int Chkmin(T &a, T b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T> inline T read() {
  T sum = 0, fl = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-')
      fl = -1;
  for (; isdigit(ch); ch = getchar())
    sum = (sum << 3) + (sum << 1) + ch - '0';
  return sum * fl;
}

inline void proc_status() {
  ifstream t("/proc/self/status");
  cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>())
       << endl;
}

const int Maxn = 1e5 + 100;

int N, M, K;
pii A[Maxn];
map<pii, int> Map;
vector<int> vec[Maxn];

inline int Check(int t, int x, int y) {
  for (int i = 0; i < vec[t].size(); ++i)
    if (x <= vec[t][i] && vec[t][i] <= y)
      return 1;
  return 0;
}

inline void Solve() {
  int pos = 1;
  for (int i = 1; i <= N; ++i) {
    if (Check(i + 1, 1, pos)) {
      cout << i << endl;
      return;
    }

    if (!Map[mp(i + 1, pos + 1)])
      ++pos;
  }
}

inline void Input() {
  N = read<int>(), M = read<int>(), K = read<int>();
  for (int i = 1; i <= K; ++i) {
    A[i].x = read<int>(), A[i].y = read<int>();
    Map[mp(A[i].x, A[i].y)] = 1;
    vec[A[i].x].pb(A[i].y);
  }
  for (int i = 1; i <= N; ++i)
    vec[N + 1].pb(i), Map[mp(N + 1, i)] = 1;
}

int main() {

#ifdef hk_cnyali
  freopen("D.in", "r", stdin);
  freopen("D.out", "w", stdout);
#endif

  Input();
  Solve();

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

#define x first
#define y second
#define y1 Y1
#define y2 Y2
#define mp make_pair
#define pb push_back
#define DEBUG(x) cout << #x << " = " << x << endl;

using namespace std;

typedef long long LL;
typedef pair<int, int> pii;

template <typename T> inline int Chkmax(T &a, T b) {
  return a < b ? a = b, 1 : 0;
}
template <typename T> inline int Chkmin(T &a, T b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T> inline T read() {
  T sum = 0, fl = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-')
      fl = -1;
  for (; isdigit(ch); ch = getchar())
    sum = (sum << 3) + (sum << 1) + ch - '0';
  return sum * fl;
}

inline void proc_status() {
  ifstream t("/proc/self/status");
  cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>())
       << endl;
}

const int Maxn = 2e5 + 100;

int N, M, K;
pii A[Maxn];
map<pii, int> Map;
vector<int> vec[Maxn];

inline int Check(int t, int x, int y) {
  for (int i = 0; i < vec[t].size(); ++i)
    if (x <= vec[t][i] && vec[t][i] <= y)
      return 1;
  return 0;
}

inline void Solve() {
  int pos = 1;
  for (int i = 1; i <= N; ++i) {
    if (Check(i + 1, 1, pos)) {
      cout << i << endl;
      return;
    }

    if (!Map[mp(i + 1, pos + 1)])
      ++pos;
  }
}

inline void Input() {
  N = read<int>(), M = read<int>(), K = read<int>();
  for (int i = 1; i <= K; ++i) {
    A[i].x = read<int>(), A[i].y = read<int>();
    Map[mp(A[i].x, A[i].y)] = 1;
    vec[A[i].x].pb(A[i].y);
  }
  for (int i = 1; i <= N; ++i)
    vec[N + 1].pb(i), Map[mp(N + 1, i)] = 1;
}

int main() {

#ifdef hk_cnyali
  freopen("D.in", "r", stdin);
  freopen("D.out", "w", stdout);
#endif

  Input();
  Solve();

  return 0;
}