Problem p02996 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a, i, j, v)                                                      \
  for (ll k = i; k <= j; k++) {                                                \
    a[k] = v;                                                                  \
  }

int main() {
  ll n;
  cin >> n;
  pair<ll, ll> arr[200001];
  ll a, b;
  REP(i, n) { cin >> arr[i].first >> arr[i].second; }
  sort(begin(arr), begin(arr) + n,
       [](pair<ll, ll> const &lhs, pair<ll, ll> const &rhs) {
         if (lhs.second != rhs.second)
           return lhs.second < rhs.second;
         if (lhs.first != rhs.first)
           return lhs.first > rhs.first;
         return true;
       });
  ll tmp = 0;
  REP(i, n) {
    if (tmp + arr[i].first <= arr[i].second) {
      tmp += arr[i].first;
    } else {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a, i, j, v)                                                      \
  for (ll k = i; k <= j; k++) {                                                \
    a[k] = v;                                                                  \
  }

int main() {
  ll n;
  cin >> n;
  pair<ll, ll> arr[200001];
  ll a, b;
  REP(i, n) { cin >> arr[i].first >> arr[i].second; }
  sort(begin(arr), begin(arr) + n,
       [](pair<ll, ll> a, pair<ll, ll> b) { return a.second < b.second; });
  ll tmp = 0;
  REP(i, n) {
    if (tmp + arr[i].first <= arr[i].second) {
      tmp += arr[i].first;
    } else {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}