Problem p03472 (C++)

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

using namespace std;

#define fcout(d) cout << fixed << setprecision(d)
#define rep(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define rep1(i, n) for (int(i) = 1; (i) <= (n); ++(i))
#define repU(i, bottom, ceiling)                                               \
  for (auto(i) = (bottom); (i) <= (ceiling); ++(i))
#define repD(i, ceiling, bottom)                                               \
  for (auto(i) = (ceiling); (i) >= (bottom); --(i))
#define repS(n) for (int s = 0; s < 1 << n; ++s)
#define repV(i, v) for (auto(i) = begin(v); (i) < end(v); ++(i))
#define all(v) begin(v), end(v)
#define clr(v) fill(all(v), 0)
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define mkp make_pair
#define mkt make_tuple
#define fir first
#define sec second
#define parity(a, b) (((a)&1) ^ ((b)&1) ^ 1)

typedef long long ll;
typedef unsigned long long ull;
typedef double db;

const pair<int, int> DIR[] = {{1, 0}, {0, 1},  {-1, 0},  {0, -1},
                              {1, 1}, {-1, 1}, {-1, -1}, {1, -1}};
const int INF = -1 + (1 << 30);
const int MOD = (int)1e9 + 7;

template <class T, class U> auto LB(T v, U in) {
  return lower_bound(begin(v), end(v), in);
}

template <class T, class U> auto UB(T v, U in) {
  return upper_bound(begin(v), end(v), in);
}

ull next_subset(ull subset) {
  ull tem = subset + (subset & -subset);
  ull btm = (~tem & subset) / (subset & -subset) >> 1;
  return btm | tem;
}

int N, H, a[10000], b[10000];

void solve() {

  sort(a, a + N);
  sort(b, b + N);

  int p = lower_bound(b, b + N, a[N - 1]) - begin(b);
  int c = 0;

  repD(i, N - 1, p) {
    ++c;
    H -= b[i];
    if (H <= 0) {
      cout << c << endl;
      return;
    }
  }

  c += (H % a[N - 1] > 0);
  cout << c + H / a[N - 1] << endl;

  return;
}

void input() {

  cin >> N >> H;
  rep(i, N) cin >> a[i] >> b[i];

  return;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  input();
  solve();
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

#define fcout(d) cout << fixed << setprecision(d)
#define rep(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define rep1(i, n) for (int(i) = 1; (i) <= (n); ++(i))
#define repU(i, bottom, ceiling)                                               \
  for (auto(i) = (bottom); (i) <= (ceiling); ++(i))
#define repD(i, ceiling, bottom)                                               \
  for (auto(i) = (ceiling); (i) >= (bottom); --(i))
#define repS(n) for (int s = 0; s < 1 << n; ++s)
#define repV(i, v) for (auto(i) = begin(v); (i) < end(v); ++(i))
#define all(v) begin(v), end(v)
#define clr(v) fill(all(v), 0)
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define mkp make_pair
#define mkt make_tuple
#define fir first
#define sec second
#define parity(a, b) (((a)&1) ^ ((b)&1) ^ 1)

typedef long long ll;
typedef unsigned long long ull;
typedef double db;

const pair<int, int> DIR[] = {{1, 0}, {0, 1},  {-1, 0},  {0, -1},
                              {1, 1}, {-1, 1}, {-1, -1}, {1, -1}};
const int INF = -1 + (1 << 30);
const int MOD = (int)1e9 + 7;

template <class T, class U> auto LB(T v, U in) {
  return lower_bound(begin(v), end(v), in);
}

template <class T, class U> auto UB(T v, U in) {
  return upper_bound(begin(v), end(v), in);
}

ull next_subset(ull subset) {
  ull tem = subset + (subset & -subset);
  ull btm = (~tem & subset) / (subset & -subset) >> 1;
  return btm | tem;
}

int N, H, a[100001], b[100001];

void solve() {

  sort(a, a + N);
  sort(b, b + N);

  int p = lower_bound(b, b + N, a[N - 1]) - begin(b);
  int c = 0;

  repD(i, N - 1, p) {
    ++c;
    H -= b[i];
    if (H <= 0) {
      cout << c << endl;
      return;
    }
  }

  c += (H % a[N - 1] > 0);
  cout << c + H / a[N - 1] << endl;

  return;
}

void input() {

  cin >> N >> H;
  rep(i, N) cin >> a[i] >> b[i];

  return;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  input();
  solve();
  return 0;
}