Problem p02996 (C++)

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

#define int long long
#define ll long long
#define vi vector<int>
#define vii vector<pair<int, int>>
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repD(i, a, b) for (int i = a; i > b; i--)
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define MOD 1000000007
#define PI 3.14159265359
/*

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

using namespace __gnu_pbds;
typedef tree<pii,null_type,less
<pii>,rb_tree_tag,tree_order_statistics_node_update>ind_set;
*/
///*X.find_by_order("index")
/// X.order_of_key("key")

#define deb(x) cerr << #x << " : " << x << "\n";
#ifndef local
#define deb(x) ;
#endif
///----------------------------------------------------------------------------------

int n;
pii arr[100005];

void solve() {
  cin >> n;
  rep(i, 0, n) cin >> arr[i].ss >> arr[i].ff;
  sort(arr, arr + n);

  int ct = 0;

  rep(i, 0, n) {
    ct += arr[i].ss;
    if (ct > arr[i].ff) {
      cout << "No";
      return;
    }
  }
  cout << "Yes";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

#ifdef local
/// freopen("input.txt","r",stdin);
/// freopen("output.txt","w",stdout);
#endif

  clock_t qwertyuiop = clock();
  int t = 1;
  /// cin>>t;
  rep(a, 0, t) {
    /// cout<<"Case #"<<a+1<<": ";
    solve();
  }
#ifdef local
  {
    qwertyuiop = clock() - qwertyuiop;
    double time_taken = ((double)qwertyuiop) / CLOCKS_PER_SEC;
    cerr << fixed << setprecision(5) << "\n\nTime Taken : " << time_taken
         << " seconds\n";
  }
#endif
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define ll long long
#define vi vector<int>
#define vii vector<pair<int, int>>
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repD(i, a, b) for (int i = a; i > b; i--)
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define MOD 1000000007
#define PI 3.14159265359
/*

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

using namespace __gnu_pbds;
typedef tree<pii,null_type,less
<pii>,rb_tree_tag,tree_order_statistics_node_update>ind_set;
*/
///*X.find_by_order("index")
/// X.order_of_key("key")

#define deb(x) cerr << #x << " : " << x << "\n";
#ifndef local
#define deb(x) ;
#endif
///----------------------------------------------------------------------------------

int n;
pii arr[400005];

void solve() {
  cin >> n;
  rep(i, 0, n) cin >> arr[i].ss >> arr[i].ff;
  sort(arr, arr + n);

  int ct = 0;

  rep(i, 0, n) {
    ct += arr[i].ss;
    if (ct > arr[i].ff) {
      cout << "No";
      return;
    }
  }
  cout << "Yes";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

#ifdef local
/// freopen("input.txt","r",stdin);
/// freopen("output.txt","w",stdout);
#endif

  clock_t qwertyuiop = clock();
  int t = 1;
  /// cin>>t;
  rep(a, 0, t) {
    /// cout<<"Case #"<<a+1<<": ";
    solve();
  }
#ifdef local
  {
    qwertyuiop = clock() - qwertyuiop;
    double time_taken = ((double)qwertyuiop) / CLOCKS_PER_SEC;
    cerr << fixed << setprecision(5) << "\n\nTime Taken : " << time_taken
         << " seconds\n";
  }
#endif
}