Problem p02996 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define loop(i, m, n) for (ll i = m; i < n; ++i)
#define ggr                                                                    \
  getchar();                                                                   \
  getchar();                                                                   \
  return 0;
#define pie 3.141592653589793238462643383279
#define elif else if
#define P pair<ll, ll>
const int inf = 1000000007;
int bin(int bina) {
  int ans = 0;
  for (int i = 0; bina > 0; i++) {
    ans = ans + (bina % 2) * pow(10, i);
    bina = bina / 2;
  }
  return ans;
}
bool prime(int n) {
  for (ll i = 2; i <= sqrt(n); i++) {
    if (n % i == 0)
      return false;
  }
  return n != 1;
}
int gcd(int x, int y) {
  if (y == 0)
    return x;
  return gcd(y, x % y);
}
int lcm(int x, int y) { return x * y / gcd(x, y); }
int kai(int x) {
  if (x == 0)
    return 1;
  return kai(x - 1) * x % inf;
}
int mod_pow(int x, int y, int mod) {
  int res = 1;
  while (y > 0) {
    if (y & 1) {
      res = res * x % mod;
    }
    x = x * x % mod;
    y >>= 1;
  }
  return res;
}
int comb(int x, int y) {
  return kai(x) * mod_pow(kai(x - y), inf - 2, inf) % inf *
         mod_pow(kai(y), inf - 2, inf) % inf;
}
struct union_find {
  int par[200010], size_[200010];
  void init(int x) {
    rep(i, x) {
      par[i] = i;
      size_[i] = 1;
    }
  }
  int find(int x) {
    if (par[x] == x)
      return x;
    return par[x] = find(par[x]);
  }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y)
      return;
    if (size_[x] < size_[y]) {
      par[x] = y;
      size_[y] += size_[x];
    } else {
      par[y] = x;
      size_[x] += size_[y];
    }
  }
};
struct edge {
  int to, cost;
};
pair<int, int> p[100010];
signed main() {
  int n;
  cin >> n;
  rep(i, n) { cin >> p[i].second >> p[i].first; }
  sort(p, p + n);
  int sum = 0;
  rep(i, n) {
    sum += p[i].second;
    if (p[i].first < sum) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define loop(i, m, n) for (ll i = m; i < n; ++i)
#define ggr                                                                    \
  getchar();                                                                   \
  getchar();                                                                   \
  return 0;
#define pie 3.141592653589793238462643383279
#define elif else if
#define P pair<ll, ll>
const int inf = 1000000007;
int bin(int bina) {
  int ans = 0;
  for (int i = 0; bina > 0; i++) {
    ans = ans + (bina % 2) * pow(10, i);
    bina = bina / 2;
  }
  return ans;
}
bool prime(int n) {
  for (ll i = 2; i <= sqrt(n); i++) {
    if (n % i == 0)
      return false;
  }
  return n != 1;
}
int gcd(int x, int y) {
  if (y == 0)
    return x;
  return gcd(y, x % y);
}
int lcm(int x, int y) { return x * y / gcd(x, y); }
int kai(int x) {
  if (x == 0)
    return 1;
  return kai(x - 1) * x % inf;
}
int mod_pow(int x, int y, int mod) {
  int res = 1;
  while (y > 0) {
    if (y & 1) {
      res = res * x % mod;
    }
    x = x * x % mod;
    y >>= 1;
  }
  return res;
}
int comb(int x, int y) {
  return kai(x) * mod_pow(kai(x - y), inf - 2, inf) % inf *
         mod_pow(kai(y), inf - 2, inf) % inf;
}
struct union_find {
  int par[200010], size_[200010];
  void init(int x) {
    rep(i, x) {
      par[i] = i;
      size_[i] = 1;
    }
  }
  int find(int x) {
    if (par[x] == x)
      return x;
    return par[x] = find(par[x]);
  }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y)
      return;
    if (size_[x] < size_[y]) {
      par[x] = y;
      size_[y] += size_[x];
    } else {
      par[y] = x;
      size_[x] += size_[y];
    }
  }
};
struct edge {
  int to, cost;
};
pair<int, int> p[200010];
signed main() {
  int n;
  cin >> n;
  rep(i, n) { cin >> p[i].second >> p[i].first; }
  sort(p, p + n);
  int sum = 0;
  rep(i, n) {
    sum += p[i].second;
    if (p[i].first < sum) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}