Problem p02996 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
#define INF 1000000007
#define LINF 1000000000000000007
#define MOD 1000000007
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout << #X << ": " << X << " ";
#define ARDEB(i, X) cout << #X << "[" << i << "]: " << X[i] << " ";
#define END cout << endl;
#else
#define DEB(X)                                                                 \
  {}
#define ARDEB(i, X)                                                            \
  {}
#define END                                                                    \
  {}
#endif
typedef pair<int, int> P;
struct edge {
  int to, cost;
};
typedef long long ll;

int ans, ans2;

// �ő����
ll gcd(ll a, ll b) {

  if (a == 0 || b == 0)
    return 0;
  if (a < b) {
    ll sw;
    sw = a;
    a = b;
    b = sw;
  }

  ll r;
  while ((r = a % b) != 0) {
    a = b;
    b = r;
  }
  return b;
}
// �ŏ����{��
ll lcm(ll a, ll b) {

  if (a == 0 || b == 0)
    return 0;

  return a / gcd(a, b) * b;
}

signed main() {

  int n;
  pair<int, int> p[111111];
  cin >> n;
  rep(i, n) cin >> p[i].second >> p[i].first;
  sort(p, p + n);
  int time = 0;
  rep(i, n) {
    time += p[i].second;
    if (time > p[i].first) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
#define INF 1000000007
#define LINF 1000000000000000007
#define MOD 1000000007
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout << #X << ": " << X << " ";
#define ARDEB(i, X) cout << #X << "[" << i << "]: " << X[i] << " ";
#define END cout << endl;
#else
#define DEB(X)                                                                 \
  {}
#define ARDEB(i, X)                                                            \
  {}
#define END                                                                    \
  {}
#endif
typedef pair<int, int> P;
struct edge {
  int to, cost;
};
typedef long long ll;

int ans, ans2;

// �ő����
ll gcd(ll a, ll b) {

  if (a == 0 || b == 0)
    return 0;
  if (a < b) {
    ll sw;
    sw = a;
    a = b;
    b = sw;
  }

  ll r;
  while ((r = a % b) != 0) {
    a = b;
    b = r;
  }
  return b;
}
// �ŏ����{��
ll lcm(ll a, ll b) {

  if (a == 0 || b == 0)
    return 0;

  return a / gcd(a, b) * b;
}

signed main() {

  int n;
  pair<int, int> p[2 * 111111];
  cin >> n;
  rep(i, n) cin >> p[i].second >> p[i].first;
  sort(p, p + n);
  int time = 0;
  rep(i, n) {
    time += p[i].second;
    if (time > p[i].first) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}