Problem p02996 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define LL long long
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define I insert
#define bull bool
#define Max(a, b) ((b < a) ? a : b)
#define Min(a, b) ((a < b) ? a : b)

const LL N = 100005, mod = 1000000007;

using namespace std;

LL n, m, i, j, k, l, r, t, ans;
pair<LL, LL> p[N];

LL getint() {
  char c = getchar();
  LL t = 0;
  while (!isdigit(c))
    c = getchar();
  while (isdigit(c)) {
    t = (t << 3) + (t << 1);
    t += c - '0';
    c = getchar();
  }
  return t;
}

int main() {
  /*/
  freopen ( "detectivein.txt", "r", stdin);
  freopen ( "detectiveout.txt", "w", stdout);
  /**/
  cin >> n;
  for (i = 0; i < n; ++i) {
    cin >> p[i].S >> p[i].F;
  }
  sort(p, p + n);

  k = 0;
  for (i = 0; i < n; ++i) {
    if (k + p[i].S > p[i].F) {
      cout << "No\n";
      return 0;
    }
    k += p[i].S;
  }
  cout << "Yes\n";

  return 0;
}
/**/
//      IIIIIIIII      OOOOO             A          NN        N    EEEEEEEEEE
//          I         O     O           A A         N N       N    E
//          I        O       O         A   A        N  N      N    E
//          I        O       O        A     A       N   N     N    E
//          I        O       O       AAAAAAAAA      N    N    N    EEEEEEEE
//          I        O       O      A         A     N     N   N    E
//          I        O       O     A           A    N      N  N    E
//          I         O     O     A             A   N       N N    E
//      IIIIIIIII      OOOOO     A               A  N        NN    EEEEEEEEEE
//      ___ KAPANADZE

Fixed submission:
#include <bits/stdc++.h>
#define LL long long
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define I insert
#define bull bool
#define Max(a, b) ((b < a) ? a : b)
#define Min(a, b) ((a < b) ? a : b)

const LL N = 200005, mod = 1000000007;

using namespace std;

LL n, m, i, j, k, l, r, t, ans;
pair<LL, LL> p[N];

LL getint() {
  char c = getchar();
  LL t = 0;
  while (!isdigit(c))
    c = getchar();
  while (isdigit(c)) {
    t = (t << 3) + (t << 1);
    t += c - '0';
    c = getchar();
  }
  return t;
}

int main() {
  /*/
  freopen ( "detectivein.txt", "r", stdin);
  freopen ( "detectiveout.txt", "w", stdout);
  /**/
  cin >> n;
  for (i = 0; i < n; ++i) {
    cin >> p[i].S >> p[i].F;
  }
  sort(p, p + n);

  k = 0;
  for (i = 0; i < n; ++i) {
    if (k + p[i].S > p[i].F) {
      cout << "No\n";
      return 0;
    }
    k += p[i].S;
  }
  cout << "Yes\n";

  return 0;
}
/**/
//      IIIIIIIII      OOOOO             A          NN        N    EEEEEEEEEE
//          I         O     O           A A         N N       N    E
//          I        O       O         A   A        N  N      N    E
//          I        O       O        A     A       N   N     N    E
//          I        O       O       AAAAAAAAA      N    N    N    EEEEEEEE
//          I        O       O      A         A     N     N   N    E
//          I        O       O     A           A    N      N  N    E
//          I         O     O     A             A   N       N N    E
//      IIIIIIIII      OOOOO     A               A  N        NN    EEEEEEEEEE
//      ___ KAPANADZE