prithivMLmods/Coder-Stat huggingface dataset:
Problem p03471 (C++)

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

int main() {
  int N, Y, a = 0, i, j, k;
  cin >> N >> Y;

  for (i = 0; i <= N; i++) {
    for (j = 0; j <= N; j++) {
      for (k = 0; k <= N; k++) {
        if (Y == 10000 * i + 5000 * j + 1000 * k && N == i + j + k) {
          a = 1;
          break;
        }
      }
      if (a)
        break;
    }
    if (a)
      break;
  }

  if (a)
    cout << i << " " << j << " " << k << endl;
  else
    cout << "-1 -1 -1" << endl;
}


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

int main() {
  int N, Y, a = 0, i, j, k;
  cin >> N >> Y;

  for (i = 0; i <= N; i++) {
    for (j = 0; i + j <= N; j++) {
      k = N - i - j;
      if (Y == 10000 * i + 5000 * j + 1000 * k && N == i + j + k) {
        a = 1;
        break;
      }
      if (a)
        break;
    }
    if (a)
      break;
  }

  if (a)
    cout << i << " " << j << " " << k << endl;
  else
    cout << "-1 -1 -1" << endl;
}
Problem p03471 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main() {
  int n, y;
  cin >> n >> y;

  rep(i, n + 1) {
    rep(j, n + 1) {
      rep(k, n + 1) {
        if (y == 10000 * i + 5000 * j + 1000 * k && n == i + j + k) {
          cout << i << " " << j << " " << k << endl;
          return 0;
        }
      }
    }
  }
  cout << "-1 -1 -1" << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main() {
  int n, y;
  cin >> n >> y;

  rep(i, n + 1) {
    rep(j, n + 1) {
      if (y == 10000 * i + 5000 * j + 1000 * (n - i - j) && n - i - j >= 0) {
        cout << i << " " << j << " " << n - i - j << endl;
        return 0;
      }
    }
  }
  cout << "-1 -1 -1" << endl;
}
Problem p03471 (C++)

Buggy submission (status: Runtime Error):

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (ll)(n); i++)
typedef long long ll;

int main() {
  ll N, Y;
  cin >> N >> Y;

  rep2(i, 0, N + 1) {
    rep2(j, 0, N - i + 1) {
      if (i * 10000 + 5000 * j + 1000 * (N - i - j) == Y) {
        cout << i << " " << j << " " << N - i - j << endl;
        return 0;
      }
    }
  }

  cout << -1 << " " << -1 << " " << -1 << endl;
  return 1;
}


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (ll)(n); i++)
typedef long long ll;

int main() {
  ll N, Y;
  cin >> N >> Y;

  rep2(i, 0, N + 1) {
    rep2(j, 0, N - i + 1) {
      if (i * 10000 + 5000 * j + 1000 * (N - i - j) == Y) {
        cout << i << " " << j << " " << N - i - j << endl;
        return 0;
      }
    }
  }

  cout << -1 << " " << -1 << " " << -1 << endl;
  return 0;
}
Problem p03471 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i < (int)(n + 1); i++)
int main() {
  int N, Y;
  cin >> N >> Y;
  bool ans = false;
  rep(i, N + 1) {
    rep(j, N + 1) {
      rep(k, N + 1) {
        if (i + j + k == N) {
          if (i * 10000 + j * 5000 + k * 1000 == Y) {
            cout << i << " " << j << " " << k << endl;
            ans = true;
            i += N;
            j += N;
            k += N;
            break;
          }
        }
      }
    }
  }

  if (ans == false) {
    cout << -1 << " " << -1 << " " << -1 << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i < (int)(n + 1); i++)
int main() {
  int N, Y;
  cin >> N >> Y;
  bool ans = false;
  rep(i, N + 1) {
    rep(j, N + 1) {
      int k = N - i - j;
      if (0 <= k) {
        if (i * 10000 + j * 5000 + k * 1000 == Y) {
          cout << i << " " << j << " " << k << endl;
          ans = true;
          i += N;
          j += N;
          k += N;
          break;
        }
      }
    }
  }

  if (ans == false) {
    cout << -1 << " " << -1 << " " << -1 << endl;
  }
}
Problem p03472 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
using namespace std;

struct sword {
  int att, typ;
} a[20005];

bool cmp(sword a, sword b) { return a.att > b.att; }
int main() {
  memset(a, 0, sizeof a);
  int n, h;
  scanf("%d%d", &n, &h);
  int amax = -2147483647;
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &(a[2 * i].att), &(a[2 * i + 1].att));
    a[2 * i].typ = 1;
    a[2 * i + 1].typ = 0;
    amax = max(amax, a[2 * i].att);
  }
  sort(a, a + 2 * n, cmp);
  int i, attsum = 0, cnt;
  for (i = 0; i < 2 * n; i++) {
    if (attsum >= h || a[i].typ) {
      cnt = i;
      break;
    }
    attsum += a[i].att;
  }
  if (attsum < h)
    printf("%d", cnt + (int)ceil((double)(h - attsum) / amax));
  else
    printf("%d", cnt);
  puts("");
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
using namespace std;

struct sword {
  int att, typ;
} a[200005];

bool cmp(sword a, sword b) { return a.att > b.att; }
int main() {
  memset(a, 0, sizeof a);
  int n, h;
  scanf("%d%d", &n, &h);
  int amax = -2147483647;
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &(a[2 * i].att), &(a[2 * i + 1].att));
    a[2 * i].typ = 1;
    a[2 * i + 1].typ = 0;
    amax = max(amax, a[2 * i].att);
  }
  sort(a, a + 2 * n, cmp);
  int i, attsum = 0, cnt;
  for (i = 0; i < 2 * n; i++) {
    if (attsum >= h || a[i].typ) {
      cnt = i;
      break;
    }
    attsum += a[i].att;
  }
  if (attsum < h)
    printf("%d", cnt + (int)ceil((double)(h - attsum) / amax));
  else
    printf("%d", cnt);
  puts("");
  return 0;
}
Problem p03472 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <chrono>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <vector>

#define out(t) cout << (t) << "\n"

using namespace std;

typedef long long ll;
typedef unsigned int uint;

void swap(int &a, int &b) {
  a ^= b;
  b ^= a;
  a ^= b;
}

uint tzcnt(uint x) {
  x = ~x & (x - 1);
  x -= x >> 1 & 0x55555555;
  x = (x & 0x33333333) + (x >> 2 & 0x33333333);
  x = x + (x >> 4) & 0x0F0F0F0F;
  return x * 0x01010101 >> 24;
}

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

  int n, h;
  cin >> n >> h;

  vector<int> a, b;
  a.reserve(100000);
  b.reserve(100000);

  for (int i = 0; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    a.push_back(x);
    b.push_back(y);
  }

  // vector<int> c(a), d(b);

  sort(a.begin(), a.end(), greater<int>());
  sort(b.begin(), b.end(), greater<int>());

  int i = 0, sum = 0;
  for (; a[0] < b[i] && sum < h; ++i) {
    sum += b[i];
  }

  if (h - sum > 0) {
    i += (h - sum) / a[0] + ((h - sum) % a[i] != 0 ? 1 : 0);
  }

  out(i);

  int ttttttt;
  cin >> ttttttt;
}

Fixed submission:
#include <algorithm>
#include <chrono>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <vector>

#define out(t) cout << (t) << "\n"

using namespace std;

typedef long long ll;
typedef unsigned int uint;

void swap(int &a, int &b) {
  a ^= b;
  b ^= a;
  a ^= b;
}

uint tzcnt(uint x) {
  x = ~x & (x - 1);
  x -= x >> 1 & 0x55555555;
  x = (x & 0x33333333) + (x >> 2 & 0x33333333);
  x = x + (x >> 4) & 0x0F0F0F0F;
  return x * 0x01010101 >> 24;
}

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

  int n, h;
  cin >> n >> h;

  vector<int> a, b;
  a.reserve(100000);
  b.reserve(100000);

  for (int i = 0; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    a.push_back(x);
    b.push_back(y);
  }

  // vector<int> c(a), d(b);

  sort(a.begin(), a.end(), greater<int>());
  sort(b.begin(), b.end(), greater<int>());

  int i = 0, sum = 0;
  for (; a[0] < b[i] && sum < h; ++i) {
    sum += b[i];
  }

  if (h - sum > 0) {
    i += (h - sum) / a[0] + ((h - sum) % a[0] != 0 ? 1 : 0);
  }

  out(i);

  int ttttttt;
  cin >> ttttttt;
}
Problem p03472 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;
ll a[101000], b[101000];
bool cmp(ll a, ll b) { return a > b; }

int main() {
  int n;
  ll h;
  cin >> n >> h;
  ll ma = -1;
  for (int i = 1; i <= n; i++) {
    cin >> a[i] >> b[i];
    ma = max(a[i], ma);
  }
  sort(b + 1, b + n + 1, cmp);
  int ans = 0;
  for (int i = 1;; i++) {
    if (i > n)
      i = n + 1;
    if (h <= 0)
      break;
    if (b[i] > ma) {
      h -= b[i];
      ans++;
    } else {
      h -= ma;
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;
ll a[101000], b[101000];
bool cmp(ll a, ll b) { return a > b; }

int main() {
  int n;
  ll h;
  cin >> n >> h;
  ll ma = -1;
  for (int i = 1; i <= n; i++) {
    cin >> a[i] >> b[i];
    ma = max(a[i], ma);
  }
  sort(b + 1, b + n + 1, cmp);
  int ans = 0;
  for (int i = 1;; i++) {
    if (i > n)
      i = n + 1;
    if (h <= 0)
      break;
    if (b[i] > ma) {
      h -= b[i];
      ans++;
    } else {
      int t = h / ma;
      ans += t;
      h -= ma * t;
      if (h == 0)
        break;
      else {
        ans++;
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03472 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
using namespace std;
int main(void) {
  int n, hp;
  int a, b[10000];
  int maxa = 0;
  cin >> n >> hp;
  for (int i = 0; i < n; i++) {
    cin >> a;
    cin >> b[i];
    if (maxa < a)
      maxa = a;
  }
  sort(b, b + n);

  int cnt = 0;
  for (int i = n - 1; hp > 0 && i >= 0 && b[i] > maxa; i--) {
    cnt++;
    hp -= b[i];
  }
  if (hp > 0)
    cnt += (hp + maxa - 1) / maxa;

  cout << cnt << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
using namespace std;
int main(void) {
  int n, hp;
  int a, b[1000000];
  int maxa = 0;
  cin >> n >> hp;
  for (int i = 0; i < n; i++) {
    cin >> a;
    cin >> b[i];
    if (maxa < a)
      maxa = a;
  }
  sort(b, b + n);

  int cnt = 0;
  for (int i = n - 1; hp > 0 && i >= 0 && b[i] > maxa; i--) {
    cnt++;
    hp -= b[i];
  }
  if (hp > 0)
    cnt += (hp + maxa - 1) / maxa;

  cout << cnt << endl;
  return 0;
}
Problem p03472 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;

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

int main(int argc, char *args[]) {
  int counter = 0;
  cin >> N >> H;
  for (int i = 0; i < N; i++) {
    cin >> a[i] >> b[i];
  }
  sort(a, a + N);
  sort(b, b + N);
  int a_max = a[N - 1];
  for (int i = N - 1; i >= 0; i--) {
    if (a_max >= b[i])
      break;
    counter = counter + 1;
    H = H - b[i];
    if (H <= 0)
      break;
  }

  if (H > 0) {
    counter += (H + a_max - 1) / a_max;
  }

  cout << counter << endl;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;

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

int main(int argc, char *args[]) {
  int counter = 0;
  cin >> N >> H;
  for (int i = 0; i < N; i++) {
    cin >> a[i] >> b[i];
  }
  sort(a, a + N);
  sort(b, b + N);
  int a_max = a[N - 1];
  for (int i = N - 1; i >= 0; i--) {
    if (a_max >= b[i])
      break;
    counter = counter + 1;
    H = H - b[i];
    if (H <= 0)
      break;
  }

  if (H > 0) {
    counter += (H + a_max - 1) / a_max;
  }

  cout << counter << endl;
}
Problem p03472 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define Max(a, b) (a > b ? a : b)
#define Min(a, b) (a < b ? a : b)
typedef long long ll;
inline int read() {
  int f = 1, x = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c <= '9' && c >= '0') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}

inline void file() {
  freopen("1.in", "r", stdin);
  freopen("1.out", "w", stdout);
}

using namespace std;
const int maxn = 1e5 + 10;
ll a[maxn], b[maxn];

int main() {
  file();
  ll k, n, h;
  // scanf("%lld%lld",&n,&h);
  cin >> n >> h;
  for (register int i = 1; i <= n; ++i)
    cin >> a[i] >> b[i];

  sort(a + 1, a + n + 1);
  for (register int i = 1; i <= n; ++i)
    b[i] = max(b[i], a[n]);
  sort(b + 1, b + n + 1);

  ll ovo = 0;
  for (register int i = n; i >= 1; --i) {
    ovo += b[i];
    if (ovo >= h) {
      printf("%lld", n - i + 1);
      return 0;
    }
  }
  int ans = n;
  ans += (h - ovo) / a[n];
  if ((h - ovo) % a[n] > 0)
    ++ans;
  cout << ans;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define Max(a, b) (a > b ? a : b)
#define Min(a, b) (a < b ? a : b)
typedef long long ll;
inline int read() {
  int f = 1, x = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c <= '9' && c >= '0') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}

inline void file() {
  freopen("1.in", "r", stdin);
  freopen("1.out", "w", stdout);
}

using namespace std;
const int maxn = 1e5 + 10;
ll a[maxn], b[maxn];

int main() {
  // file();
  ll k, n, h;
  // scanf("%lld%lld",&n,&h);
  cin >> n >> h;
  for (register int i = 1; i <= n; ++i)
    cin >> a[i] >> b[i];

  sort(a + 1, a + n + 1);
  for (register int i = 1; i <= n; ++i)
    b[i] = max(b[i], a[n]);
  sort(b + 1, b + n + 1);

  ll ovo = 0;
  for (register int i = n; i >= 1; --i) {
    ovo += b[i];
    if (ovo >= h) {
      printf("%lld", n - i + 1);
      return 0;
    }
  }
  int ans = n;
  ans += (h - ovo) / a[n];
  if ((h - ovo) % a[n] > 0)
    ++ans;
  cout << ans;
  return 0;
}
Problem p03472 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int a[10000], b[10000];
int main() {
  int n, h;
  cin >> n >> h;
  for (int i = 0; i < n; i++)
    cin >> a[i] >> b[i];
  int x = *max_element(a, a + n);
  sort(b, b + n);
  reverse(b, b + n);
  int ans = (h + x - 1) / x;
  for (int i = 0; i < n; i++) {
    h -= b[i];
    int t;
    if (h <= 0)
      t = 0;
    else
      t = (h + x - 1) / x;
    if (i + 1 + t < ans)
      ans = i + 1 + t;
  }
  cout << ans;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int a[1000000], b[1000000];
int main() {
  int n, h;
  cin >> n >> h;
  for (int i = 0; i < n; i++)
    cin >> a[i] >> b[i];
  int x = *max_element(a, a + n);
  sort(b, b + n);
  reverse(b, b + n);
  int ans = (h + x - 1) / x;
  for (int i = 0; i < n; i++) {
    h -= b[i];
    int t;
    if (h <= 0)
      t = 0;
    else
      t = (h + x - 1) / x;
    if (i + 1 + t < ans)
      ans = i + 1 + t;
  }
  cout << ans;

  return 0;
}
Problem p03472 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, h, c = 0, d = 0;
  cin >> n >> h;
  int a[n], b[n];
  for (int i = 0; i < n - 1; i++) {
    cin >> a[i] >> b[i];
    d = max(d, a[i]);
  }
  sort(b, b + n);
  for (int i = n - 1; i >= 0; i--) {
    if (b[i] < d)
      break;
    h -= b[i];
    c++;
    if (h <= 0) {
      cout << c;
      return 0;
    }
  }
  cout << c + (h - 1) / d + 1;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, h, c = 0, d = 0;
  cin >> n >> h;
  int a[n], b[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
    d = max(d, a[i]);
  }
  sort(b, b + n);
  for (int i = n - 1; i >= 0; i--) {
    if (b[i] < d)
      break;
    h -= b[i];
    c++;
    if (h <= 0) {
      cout << c;
      return 0;
    }
  }
  cout << c + (h - 1) / d + 1;
}
Problem p03472 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define C 0.5772156649
#define ls l, m, rt << 1
#define rs m + 1, r, rt << 1 | 1
#define pil pair<int, ll>
#define pii pair<int, int>
#define ull unsigned long long
#define base 1000000000000000000
#define fio                                                                    \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0)

using namespace std;

const double g = 10.0, eps = 1e-12;
const int N = 200000 + 10, maxn = 200000 + 10, inf = 0x3f3f3f3f;

struct point {
  point(int _x = 0, int _y = 0) { x = _x, y = _y; }
  int x, y;
  bool operator<(const point &rhm) const { return x < rhm.x; }
} p[N];
priority_queue<point> Q;
int main() {
  int n, h;
  scanf("%d%d", &n, &h);
  for (int i = 0; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    Q.push(point(x, 1));
    Q.push(point(y, 2));
  }
  int ans = 0;
  while (h > 0) {
    point cur = Q.top();
    if (cur.y == 2)
      Q.pop();
    // printf("%d %d ####\n",cur.x,cur.y);
    h -= cur.x;
    ans++;
  }
  printf("%d\n", ans);
  return 0;
}
/********************

********************/


Fixed submission:
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define C 0.5772156649
#define ls l, m, rt << 1
#define rs m + 1, r, rt << 1 | 1
#define pil pair<int, ll>
#define pii pair<int, int>
#define ull unsigned long long
#define base 1000000000000000000
#define fio                                                                    \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0)

using namespace std;

const double g = 10.0, eps = 1e-12;
const int N = 200000 + 10, maxn = 200000 + 10, inf = 0x3f3f3f3f;

struct point {
  point(int _x = 0, int _y = 0) { x = _x, y = _y; }
  int x, y;
  bool operator<(const point &rhm) const { return x < rhm.x; }
} p[N];
priority_queue<point> Q;
int main() {
  int n, h;
  scanf("%d%d", &n, &h);
  for (int i = 0; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    Q.push(point(x, 1));
    Q.push(point(y, 2));
  }
  int ans = 0;
  while (h > 0) {
    point cur = Q.top();
    if (cur.y == 2)
      Q.pop();
    else {
      ans += h / cur.x;
      if (h % cur.x)
        ans++;
      break;
    }
    h -= cur.x;
    ans++;
  }
  printf("%d\n", ans);
  return 0;
}
/********************

********************/
Problem p03472 (C++)

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

using namespace std;

int a[111111];
int main() {
  int n, h;
  cin >> n >> h;
  for (int i = 0; i < n; i++) {
    scanf("%d%d", a + i * 2, a + i * 2 + 1);
    a[i * 2] *= 2;
    a[i * 2 + 1] = a[i * 2 + 1] * 2 + 1;
  }
  sort(a, a + n * 2, greater<int>());
  auto l = 0ll;
  int m = 0;
  for (; m < n * 2; m++) {
    if (a[m] % 2) {
      l += a[m] / 2;
      if (l >= h)
        break;
      continue;
    }
    m += (h - l - 1) / (a[m] / 2);
    break;
  }
  cout << m + 1 << endl;
  return 0;
}


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

using namespace std;

int a[211111];
int main() {
  int n, h;
  cin >> n >> h;
  for (int i = 0; i < n; i++) {
    scanf("%d%d", a + i * 2, a + i * 2 + 1);
    a[i * 2] *= 2;
    a[i * 2 + 1] = a[i * 2 + 1] * 2 + 1;
  }
  sort(a, a + n * 2, greater<int>());
  auto l = 0ll;
  int m = 0;
  for (; m < n * 2; m++) {
    if (a[m] % 2) {
      l += a[m] / 2;
      if (l >= h)
        break;
      continue;
    }
    m += (h - l - 1) / (a[m] / 2);
    break;
  }
  cout << m + 1 << endl;
  return 0;
}
Problem p03472 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <math.h>
#include <numeric>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>

#define rep(i, n) for ((i) = 0; i < (int)(n); i++)
#define max(a, b) (a < b ? b : a)
#define min(a, b) (a > b ? b : a)

using namespace std;

int main() {
  int i, j, k;
  int N, H;
  int a[100] = {0};
  int b[100] = {0};
  cin >> N >> H;
  rep(i, N) { cin >> a[i] >> b[i]; }
  sort(a, a + N);
  sort(b, b + N);
  int ans = 0;
  i = N - 1;
  j = N - 1;
  while (H > 0) {
    if (a[i] >= b[j] || j < 0) {
      ans += H / a[i];
      ans += (H % a[i] == 0 ? 0 : 1);
      cout << ans;
      return 0;
    } else {
      H -= b[j];
      j--;
      ans++;
    }
  }
  cout << ans;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <math.h>
#include <numeric>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>

#define rep(i, n) for ((i) = 0; i < (int)(n); i++)
#define max(a, b) (a < b ? b : a)
#define min(a, b) (a > b ? b : a)

using namespace std;

int main() {
  int i, j, k;
  int N, H;
  int a[100000] = {0};
  int b[100000] = {0};
  cin >> N >> H;
  rep(i, N) { cin >> a[i] >> b[i]; }
  sort(a, a + N);
  sort(b, b + N);
  int ans = 0;
  i = N - 1;
  j = N - 1;
  while (H > 0) {
    if (a[i] >= b[j] || j < 0) {
      ans += H / a[i];
      ans += (H % a[i] == 0 ? 0 : 1);
      cout << ans;
      return 0;
    } else {
      H -= b[j];
      j--;
      ans++;
    }
  }
  cout << ans;
  return 0;
}
Problem p03472 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iterator>
#include <limits>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stdio.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define log(i, n) log(n) / log(i);
using namespace std;
typedef long long ll;

int main() {
  ll n, h;
  cin >> n >> h;
  vector<ll> a(n), b(n), c, cnt;
  rep(i, n) cin >> a[i] >> b[i];
  sort(b.begin(), b.end());
  reverse(b.begin(), b.end());
  rep(i, n) {
    c.push_back(max(h - accumulate(b.begin(), b.begin() + (i + 1), 0LL), 0LL));
  }
  ll ma = *max_element(a.begin(), a.end());
  rep(i, n) { cnt.push_back((i + 1) + ceil((double)c[i] / (double)ma)); }
  cout << *min_element(cnt.begin(), cnt.end()) << endl;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iterator>
#include <limits>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stdio.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define log(i, n) log(n) / log(i);
using namespace std;
typedef long long ll;

int main() {
  ll n, h;
  cin >> n >> h;
  vector<ll> a(n), b(n), c, cnt;
  rep(i, n) cin >> a[i] >> b[i];
  sort(b.begin(), b.end());
  reverse(b.begin(), b.end());
  rep(i, n) {
    // O(N^2)c.push_back(max(h-accumulate(b.begin(), b.begin() + (i+1),
    // 0LL),0LL));となりTLE？
    h -= b[i];
    c.push_back(max(h, 0LL));
  }
  ll ma = *max_element(a.begin(), a.end());
  rep(i, n) { cnt.push_back((i + 1) + ceil((double)c[i] / (double)ma)); }
  cout << *min_element(cnt.begin(), cnt.end()) << endl;
}
Problem p03472 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
struct katana {
  int a, b;
} k[100010];
int n, h;
int ans;
bool cmp(katana x, katana y) { return x.b > y.b; }
int main() {
  freopen("Katana.in", "r", stdin);
  freopen("Katana.out", "w", stdout);
  cin >> n >> h;
  int i, j;
  int maxv = 0;
  for (i = 1; i <= n; i++)
    cin >> k[i].a >> k[i].b, maxv = max(maxv, k[i].a);
  sort(k + 1, k + n + 1, cmp);
  i = 1;
  while (i <= n && k[i].b > maxv) {
    h -= k[i].b;
    ans++;
    if (h <= 0) {
      cout << ans << endl;
      return 0;
    }
    i++;
  }
  ans += h / maxv;
  if (h % maxv != 0)
    ans++;
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
struct katana {
  int a, b;
} k[100010];
int n, h;
int ans;
bool cmp(katana x, katana y) { return x.b > y.b; }
int main() {
  // freopen("Katana.in","r",stdin);
  // freopen("Katana.out","w",stdout);
  cin >> n >> h;
  int i, j;
  int maxv = 0;
  for (i = 1; i <= n; i++)
    cin >> k[i].a >> k[i].b, maxv = max(maxv, k[i].a);
  sort(k + 1, k + n + 1, cmp);
  i = 1;
  while (i <= n && k[i].b > maxv) {
    h -= k[i].b;
    ans++;
    if (h <= 0) {
      cout << ans << endl;
      return 0;
    }
    i++;
  }
  ans += h / maxv;
  if (h % maxv != 0)
    ans++;
  cout << ans << endl;
  return 0;
}
Problem p03472 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, s = 0, ma = 0, p;
  vector<int> x, y;
  priority_queue<int, vector<int>, less<int>> q;
  scanf("%d%d", &n, &m);
  x.resize(n);
  y.resize(m);
  for (i = 0; i < n; i++) {
    scanf("%d%d", &x[i], &y[i]);
    if (x[i] > ma) {
      ma = x[i];
      p = i;
    }
  }
  for (i = 0; i < n; i++) {
    if (y[i] > ma && i != p) {
      q.push(y[i]);
    }
  }
  q.push(0);
  while (m) {
    if (y[p] >= m) {
      s++;
      break;
    }
    if (ma > q.top()) {
      s++;
      m -= ma;
    } else {
      s++;
      m -= q.top();
      q.pop();
    }
  }
  printf("%d", s);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, s = 0, ma = 0, p;
  vector<int> x, y;
  priority_queue<int, vector<int>, less<int>> q;
  scanf("%d%d", &n, &m);
  x.resize(n);
  y.resize(n);
  for (i = 0; i < n; i++) {
    scanf("%d%d", &x[i], &y[i]);
    if (x[i] > ma) {
      ma = x[i];
      p = i;
    }
  }
  for (i = 0; i < n; i++) {
    if (y[i] > ma && i != p) {
      q.push(y[i]);
    }
  }
  q.push(0);
  while (m) {
    if (y[p] >= m) {
      s++;
      break;
    }
    if (ma > q.top()) {
      s++;
      m -= ma;
    } else {
      s++;
      m -= q.top();
      q.pop();
    }
  }
  printf("%d", s);
  return 0;
}
Problem p03472 (C++)

Buggy submission (status: Runtime Error):
/*SorooshH*/
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> tpi;
typedef pair<pii, pii> qpi;
const int MAX = 500;
const int MV = 1e5;
const int MOD = 1e9 + 7;
const int INF = 2e9;
ll MA = -INF, MI = INF;

ll n, h;
ll th[MAX + 10], wi[MAX + 10];
ll curr;

ll ceil(ll n, ll m) {
  if (n <= 0)
    return 0;
  if (n % m == 0)
    return n / m;
  else
    return (n / m) + 1;
}

int32_t main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> h;

  for (int i = 1; i <= n; i++)
    cin >> wi[i] >> th[i], MA = max(MA, wi[i]);

  sort(th + 1, th + n + 1), reverse(th + 1, th + n + 1);

  for (int i = 0; i <= n; i++)
    h -= th[i], MI = min(MI, i + ceil(h, MA));
  cout << MI << "\n";
  return 0;
}


Fixed submission:
/*SorooshH*/
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> tpi;
typedef pair<pii, pii> qpi;
const int MAX = 1e5;
const int MV = 1e5;
const int MOD = 1e9 + 7;
const int INF = 2e9;
ll MA = -INF, MI = INF;

ll n, h;
ll th[MAX + 10], wi[MAX + 10];
ll curr;

ll ceil(ll n, ll m) {
  if (n <= 0)
    return 0;
  if (n % m == 0)
    return n / m;
  else
    return (n / m) + 1;
}

int32_t main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> h;

  for (int i = 1; i <= n; i++)
    cin >> wi[i] >> th[i], MA = max(MA, wi[i]);

  sort(th + 1, th + n + 1), reverse(th + 1, th + n + 1);

  for (int i = 0; i <= n; i++)
    h -= th[i], MI = min(MI, i + ceil(h, MA));
  cout << MI << "\n";
  return 0;
}
Problem p03472 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {

  ll n, h;
  cin >> n >> h;
  vector<pair<ll, ll>> pa;
  for (ll i = 0; i < n; i++) {
    ll a, b;
    cin >> a >> b;
    pa.push_back({a, -1});
    pa.push_back({b, 1});
  }
  sort(pa.rbegin(), pa.rend());
  ll ans = 0;
  ll index = 0;
  while (0 < h) {
    if (pa[index].second == -1) {
      h -= pa[index].first;
    } else {
      h -= pa[index].first;
      index++;
    }
    ans++;
  }
  cout << ans << endl;
  return 0;
}

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

int main() {

  ll n, h;
  cin >> n >> h;
  vector<pair<ll, ll>> pa;
  for (ll i = 0; i < n; i++) {
    ll a, b;
    cin >> a >> b;
    pa.push_back({a, -1});
    pa.push_back({b, 1});
  }
  sort(pa.rbegin(), pa.rend());
  ll ans = 0;
  ll index = 0;
  while (0 < h) {
    if (pa[index].second == -1) {
      if (h % pa[index].first == 0) {
        ans += h / pa[index].first;
      } else {
        ans += h / pa[index].first + 1;
      }
      break;
    } else {
      h -= pa[index].first;
      index++;
    }
    ans++;
  }
  cout << ans << endl;
  return 0;
}
Problem p03472 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  int N, H, B[10010];
  int amax = 0;
  int cnt = 0;
  cin >> N >> H;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a >> B[i];
    amax = max(a, amax);
  }
  sort(B, B + N);
  for (int i = N - 1; i >= 0; i--) {
    if (B[i] >= amax) {
      H -= B[i];
      cnt++;
    }
    if (H <= 0) {
      cout << cnt << endl;
      return 0;
    }
  }
  cout << cnt + (H + amax - 1) / amax << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  int N, H, B[100000];
  int amax = 0;
  int cnt = 0;
  cin >> N >> H;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a >> B[i];
    amax = max(a, amax);
  }
  sort(B, B + N);
  for (int i = N - 1; i >= 0; i--) {
    if (B[i] >= amax) {
      H -= B[i];
      cnt++;
    }
    if (H <= 0) {
      cout << cnt << endl;
      return 0;
    }
  }
  cout << cnt + (H + amax - 1) / amax << endl;
  return 0;
}
Problem p03472 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
using namespace std;

int main(void) {
  int n, h;
  cin >> n >> h;

  int a, a_max = 0;
  int b[10000];
  int i;
  for (i = 0; i < n; i++) {
    cin >> a >> b[i];
    if (a > a_max) {
      a_max = a;
    }
  }

  sort(b, b + n, greater<int>());

  int cnt = 0;
  i = 0;
  while (b[i] > a_max) {
    h -= b[i];
    cnt++;
    i++;
    if (h <= 0 || i >= n) {
      break;
    }
  }

  if (h > 0) {
    cnt += (h - 1) / a_max + 1;
  }

  cout << cnt << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
using namespace std;

int main(void) {
  int n, h;
  cin >> n >> h;

  int a, a_max = 0;
  int b[100000];
  int i;
  for (i = 0; i < n; i++) {
    cin >> a >> b[i];
    if (a > a_max) {
      a_max = a;
    }
  }

  sort(b, b + n, greater<int>());

  int cnt = 0;
  i = 0;
  while (b[i] > a_max) {
    h -= b[i];
    cnt++;
    i++;
    if (h <= 0 || i >= n) {
      break;
    }
  }

  if (h > 0) {
    cnt += (h - 1) / a_max + 1;
  }

  cout << cnt << endl;

  return 0;
}
Problem p03472 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  long long n, t, k, kcase;
  long long a, b[2000005];
  long long m = 0;
  int flag = 1;
  k = 0;
  kcase = 0;
  cin >> n >> t;
  for (int i = 0; i < n; i++) {
    cin >> a >> b[i];
    if (m < a) {
      m = a;
      k = b[i];
    } else if (m == a) {
      if (b[k] > b[i])
        k = b[i];
    }
  }
  sort(b, b + n);
  for (int i = n - 1; i >= 0; i--) {
    if (t - k <= 0) {
      cout << kcase + 1 << endl;
      return 0;
    }
    if (b[i] == k && flag) {
      flag = 0;
      continue;
    }
    if (b[i] > m)
      t = t - b[i];
    else {
      t = t - m;
    }
    kcase++;
    if (t <= 0) {
      cout << kcase << endl;
      return 0;
    }
  }
  t = t - k;
  kcase++;
  if (t <= 0)
    cout << kcase << endl;
  else {
    kcase += t / m;
    t = t - (t / m) * m;
    if (t > 0)
      kcase++;
    cout << kcase << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  long long n, t, k, kcase;
  long long a, b[2000005];
  long long m = 0;
  int flag = 1;
  k = 0;
  kcase = 0;
  cin >> n >> t;
  for (int i = 0; i < n; i++) {
    cin >> a >> b[i];
    if (m < a) {
      m = a;
      k = b[i];
    } else if (m == a) {
      if (k > b[i])
        k = b[i];
    }
  }
  sort(b, b + n);
  for (int i = n - 1; i >= 0; i--) {
    if (t - k <= 0) {
      cout << kcase + 1 << endl;
      return 0;
    }
    if (b[i] == k && flag) {
      flag = 0;
      continue;
    }
    if (b[i] > m)
      t = t - b[i];
    else {
      t = t - m;
    }
    kcase++;
    if (t <= 0) {
      cout << kcase << endl;
      return 0;
    }
  }
  t = t - k;
  kcase++;
  if (t <= 0)
    cout << kcase << endl;
  else {
    kcase += t / m;
    t = t - (t / m) * m;
    if (t > 0)
      kcase++;
    cout << kcase << endl;
  }
  return 0;
}
Problem p03472 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, H;
  cin >> N >> H;
  vector<int> A(N);
  vector<int> B(N);
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    A.at(i) = a;
    B.at(i) = b;
  }
  sort(A.begin(), A.end());
  int Max = A.at(N - 1);
  sort(B.begin(), B.end());
  auto itr = lower_bound(B.begin(), B.end(), A.at(N - 1));
  int k = distance(B.begin(), itr);
  int ans = 0;
  int sum = 0;
  for (int i = 0;; i++) {
    if (i <= N - k + 1) {
      sum += B.at(k + i);
      if (H <= sum) {
        ans = i + 1;
        break;
      }
    } else {
      sum += A.at(N - 1);
      if (H <= sum) {
        ans = i + 1;
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, H;
  cin >> N >> H;
  vector<int> A(N);
  vector<int> B(N);
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    A.at(i) = a;
    B.at(i) = b;
  }
  sort(A.begin(), A.end());
  int Max = A.at(N - 1);
  sort(B.begin(), B.end());
  auto itr = lower_bound(B.begin(), B.end(), A.at(N - 1));
  int k = distance(B.begin(), itr);
  int ans = 0;
  int sum = 0;
  for (int i = 0;; i++) {
    if (i <= N - k - 1) {
      sum += B.at(N - 1 - i);
      if (H <= sum) {
        ans = i + 1;
        break;
      }
    } else {
      sum += A.at(N - 1);
      if (H <= sum) {
        ans = i + 1;
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03472 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int maxn = 10000 + 1;
int main(int argc, char *argv[]) {
  int n;
  int h;
  scanf("%d%d", &n, &h);
  int maxw = -1;
  int w[maxn], t[maxn];
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d", &w[i], &t[i]);
    if (w[i] > maxw)
      maxw = w[i];
  }
  sort(t + 1, t + 1 + n);
  int ans = 0;
  for (int i = n; i >= 1; --i) {
    if (t[i] <= maxw)
      break;
    if (h > 0) {
      h -= t[i];
      ++ans;
    } else
      break;
  }
  if (h > 0) {
    ans += (h - 1) / maxw + 1;
  }
  printf("%d", ans);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 1;
int main(int argc, char *argv[]) {
  int n;
  int h;
  scanf("%d%d", &n, &h);
  int maxw = -1;
  int w[maxn], t[maxn];
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d", &w[i], &t[i]);
    if (w[i] > maxw)
      maxw = w[i];
  }
  sort(t + 1, t + 1 + n);
  int ans = 0;
  for (int i = n; i >= 1; --i) {
    if (t[i] <= maxw)
      break;
    if (h > 0) {
      h -= t[i];
      ++ans;
    } else
      break;
  }
  if (h > 0) {
    ans += (h - 1) / maxw + 1;
  }
  printf("%d", ans);
  return 0;
}
Problem p03472 (C++)

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

int main() {
  int N, H;
  cin >> N >> H;
  vector<int> a(N), b(N);
  for (int i = 0; i < N; i++)
    cin >> a.at(i) >> b.at(i);
  int amax = 0;
  for (int i = 0; i < a.size(); i++)
    if (amax < a.at(i))
      amax = a.at(i);
  sort(b.begin(), b.end(), greater<int>());

  int i = 0;
  while (true) {
    if (H > 0 || (i < b.size() && b.at(i) > amax)) {
      H -= b.at(i);
      i++;
    } else {
      if (H < 0) {
        cout << i << endl;
        break;
      }
      i += H / amax;
      if (H % amax == 0)
        cout << i << endl;
      else
        cout << i + 1 << endl;
      break;
    }
  }
}


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

int main() {
  int N, H;
  cin >> N >> H;
  vector<int> a(N), b(N);
  for (int i = 0; i < N; i++)
    cin >> a.at(i) >> b.at(i);
  int amax = 0;
  for (int i = 0; i < a.size(); i++)
    if (amax < a.at(i))
      amax = a.at(i);
  sort(b.begin(), b.end(), greater<int>());

  int i = 0;
  while (true) {
    if (H > 0 && i < b.size() && b.at(i) > amax) {
      H -= b.at(i);
      i++;
    } else {
      if (H < 0) {
        cout << i << endl;
        break;
      }
      i += H / amax;
      if (H % amax == 0)
        cout << i << endl;
      else
        cout << i + 1 << endl;
      break;
    }
  }
}
Problem p03472 (C++)

Buggy submission (status: Runtime Error):
#define DREP(i, s, e) for (register int i = s; i >= e; i--)
#define REP(i, s, e) for (register int i = s; i <= e; i++)

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <vector>

using namespace std;
const int maxn = 30010;

template <typename T> T read() {
  T ans(0), p(1);
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-')
      p = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    ans = ans * 10 + c - 48;
    c = getchar();
  }
  return ans * p;
}
long long n, m, sb;

#define kan pair<long long, long long>
#define a first
#define b second

kan k[maxn];
inline bool cmp(kan a, kan b) { return a.a > b.a; }

int main() {
#ifdef CraZYali
  freopen("d.in", "r", stdin);
  freopen("d.out", "w", stdout);
#endif
  cin >> n >> m;
  REP(i, 1, n) {
    scanf("%lld%lld", &k[i].a, &k[i + n].a);
    k[i].b = 1;
    k[i + n].b = 0;
  }
  sort(k + 1, k + 1 + 2 * n, cmp);
  n *= 2;
  register long long now = 0;
  REP(i, 1, n)
  if (k[i].b == 1) {
    cout << (m % k[i].a == 0 ? m / k[i].a : m / k[i].a + 1) + now;
    return 0;
  } else {
    m -= k[i].a;
    now++;
    if (m <= 0) {
      cout << now << endl;
      return 0;
    }
  }
  return 0;
}


Fixed submission:
#define DREP(i, s, e) for (register int i = s; i >= e; i--)
#define REP(i, s, e) for (register int i = s; i <= e; i++)

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <vector>

using namespace std;
const int maxn = 300010;

template <typename T> T read() {
  T ans(0), p(1);
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-')
      p = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    ans = ans * 10 + c - 48;
    c = getchar();
  }
  return ans * p;
}
long long n, m, sb;

#define kan pair<long long, long long>
#define a first
#define b second

kan k[maxn];
inline bool cmp(kan a, kan b) { return a.a > b.a; }

int main() {
#ifdef CraZYali
  freopen("d.in", "r", stdin);
  freopen("d.out", "w", stdout);
#endif
  cin >> n >> m;
  REP(i, 1, n) {
    scanf("%lld%lld", &k[i].a, &k[i + n].a);
    k[i].b = 1;
    k[i + n].b = 0;
  }
  sort(k + 1, k + 1 + 2 * n, cmp);
  n *= 2;
  register long long now = 0;
  REP(i, 1, n)
  if (k[i].b == 1) {
    cout << (m % k[i].a == 0 ? m / k[i].a : m / k[i].a + 1) + now;
    return 0;
  } else {
    m -= k[i].a;
    now++;
    if (m <= 0) {
      cout << now << endl;
      return 0;
    }
  }
  return 0;
}
Problem p03472 (C++)

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

using namespace std;

#define LIMIT 100
typedef int64_t ll;
typedef pair<ll, ll> ii;
typedef tuple<int, int, int> iii;
int gcd(ll a, ll b) { return (b == 0) ? a : gcd(b, a % b); }
int lcm(ll a, ll b) {
  ll i = (a / gcd(a, b)) * b;
  assert(i > 0);
  return i;
}

//  ***** MAIN *****
int main() {
  // ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n, h;
  cin >> n >> h;
  queue<iii> qu;

  int a[10000];
  int b[10000];
  for (int i = 0; i < n; ++i) {
    cin >> a[i] >> b[i];
  }
  sort(b, b + n);
  sort(a, a + n);
  int i = n - 1, k = n - 1;
  int t = 0;
  while (h > 0) {
    if (b[k] > a[i]) {
      h -= b[k];
      k--;
    } else {
      h -= a[i];
    }
    t++;
  }
  std::cout << t << std::endl;

  return 0;
}


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

using namespace std;

#define LIMIT 100
typedef int64_t ll;
typedef pair<ll, ll> ii;
typedef tuple<int, int, int> iii;
int gcd(ll a, ll b) { return (b == 0) ? a : gcd(b, a % b); }
int lcm(ll a, ll b) {
  ll i = (a / gcd(a, b)) * b;
  assert(i > 0);
  return i;
}

//  ***** MAIN *****
int main() {
  // ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n, h;
  cin >> n >> h;
  queue<iii> qu;

  int a[100000];
  int b[100000];

  for (int i = 0; i < n; ++i) {
    cin >> a[i] >> b[i];
  }
  sort(b, b + n);
  sort(a, a + n);
  int i = n - 1, k = n - 1;
  int t = 0;
  while (h > 0) {
    if (b[k] > a[i]) {
      h -= b[k];
      k--;
    } else {
      h -= a[i];
    }
    t++;
  }
  std::cout << t << std::endl;

  return 0;
}
Problem p03472 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
int a[1000], b[1000];
int n, h, m;
int main() {
  cin >> n >> h;
  for (int i = 0; i <= n - 1; i++)
    cin >> a[i] >> b[i];
  sort(a, a + n);
  sort(b, b + n);
  for (int i = n - 1; i >= 0; i--) {
    if (a[n - 1] < b[i])
      h -= b[i];
    else
      h -= a[n - 1];

    if (h <= 0) {
      cout << n - i;
      system("pause");
      return 0;
    }
  }

  while (h > 0) {
    h -= a[n - 1];
    m++;
    if (h <= 0) {
      cout << m + n;
    }
  }
  system("pause");
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
int a[100000], b[100000];
int n, h, m;
int main() {
  cin >> n >> h;
  for (int i = 0; i <= n - 1; i++)
    cin >> a[i] >> b[i];
  sort(a, a + n);
  sort(b, b + n);
  for (int i = n - 1; i >= 0; i--) {
    if (a[n - 1] < b[i])
      h -= b[i];
    else
      h -= a[n - 1];

    if (h <= 0) {
      cout << n - i;
      system("pause");
      return 0;
    }
  }

  while (h > 0) {
    h -= a[n - 1];
    m++;
    if (h <= 0) {
      cout << m + n;
    }
  }
  system("pause");
  return 0;
}
Problem p03472 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
const int MAXN = 10001;
struct edge {
  int a, b;
} con[MAXN];
inline bool cmp1(const edge &x, const edge &y) { return x.b > y.b; }
int main() {
  int n, total, tot = 0, ans = 0, maxa = 0;
  scanf("%d%d", &n, &total);
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d", &con[i].a, &con[i].b);
    maxa = max(maxa, con[i].a);
  }
  sort(con + 1, con + n + 1, cmp1);
  for (int i = n; i >= 1; --i)
    if (con[i].b <= maxa)
      --n;
    else
      break;
  for (int i = 1; i <= n; ++i) {
    tot += con[i].b;
    ++ans;
    if (tot >= total)
      break;
  }
  if (tot >= total)
    printf("%d", ans);
  else {
    int k = total - tot;
    if (k % maxa == 0)
      ans += k / maxa;
    else
      ans += (k / maxa + 1);
    printf("%d", ans);
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
const int MAXN = 100001;
struct edge {
  int a, b;
} con[MAXN];
inline bool cmp1(const edge &x, const edge &y) { return x.b > y.b; }
int main() {
  int n, total, tot = 0, ans = 0, maxa = 0;
  scanf("%d%d", &n, &total);
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d", &con[i].a, &con[i].b);
    maxa = max(maxa, con[i].a);
  }
  sort(con + 1, con + n + 1, cmp1);
  for (int i = n; i >= 1; --i)
    if (con[i].b <= maxa)
      --n;
    else
      break;
  for (int i = 1; i <= n; ++i) {
    tot += con[i].b;
    ++ans;
    if (tot >= total)
      break;
  }
  if (tot >= total)
    printf("%d", ans);
  else {
    int k = total - tot;
    if (k % maxa == 0)
      ans += k / maxa;
    else
      ans += (k / maxa + 1);
    printf("%d", ans);
  }
  return 0;
}
Problem p03472 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for (int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
  priority_queue<int> q;
  set<int> st;
  int n, h;
  cin >> n >> h;
  imfor(i, n) {
    int a, b;
    cin >> a >> b;
    q.push(a);
    q.push(b);
    st.insert(a);
  }
  int ans = 0;
  while (true) {
    ans++;
    h -= q.top();
    if (st.find(q.top()) == st.end()) {
      q.pop();
    }
    if (h <= 0) {
      break;
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for (int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
  priority_queue<int> q;
  set<int> st;
  int n, h;
  cin >> n >> h;
  imfor(i, n) {
    int a, b;
    cin >> a >> b;
    q.push(a);
    q.push(b);
    st.insert(a);
  }
  int ans = 0;
  while (true) {
    ans++;
    h -= q.top();
    if (st.find(q.top()) == st.end()) {
      q.pop();
    } else {
      while (h > 0) {
        h -= q.top();
        ans++;
      }
    }
    if (h <= 0) {
      break;
    }
  }
  cout << ans << endl;
}
Problem p03472 (C++)

Buggy submission (status: Runtime Error):
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <stdio.h>

struct Katana {
  int damage;
  bool isSingle;
};

Katana a[200000];

int main() {
  freopen("input.txt", "r", stdin);
  int N, H;
  scanf("%d %d", &N, &H);
  for (int i = 0; i < N; ++i) {
    scanf("%d %d", &a[2 * i].damage, &a[2 * i + 1].damage);
    a[2 * i].isSingle = false;
    a[2 * i + 1].isSingle = true;
  }
  std::sort(a, a + 2 * N, [](const Katana &a, const Katana &b) {
    return a.damage > b.damage;
  });
  int ans = 0;
  int i = 0;
  while (H > 0) {
    if (a[i].isSingle) {
      H -= a[i++].damage;
      ++ans;
    } else {
      int t = H / a[i].damage;
      ans += t;
      H -= a[i].damage * t;
      if (H > 0) {
        H -= a[i].damage;
        ++ans;
      }
    }
  }
  printf("%d", ans);
  return 0;
}

Fixed submission:
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <stdio.h>

struct Katana {
  int damage;
  bool isSingle;
};

Katana a[200000];

int main() {
  int N, H;
  scanf("%d %d", &N, &H);
  for (int i = 0; i < N; ++i) {
    scanf("%d %d", &a[2 * i].damage, &a[2 * i + 1].damage);
    a[2 * i].isSingle = false;
    a[2 * i + 1].isSingle = true;
  }
  std::sort(a, a + 2 * N, [](const Katana &a, const Katana &b) {
    return a.damage > b.damage;
  });
  int ans = 0;
  int i = 0;
  while (H > 0) {
    if (a[i].isSingle) {
      H -= a[i++].damage;
      ++ans;
    } else {
      int t = H / a[i].damage;
      ans += t;
      H -= a[i].damage * t;
      if (H > 0) {
        H -= a[i].damage;
        ++ans;
      }
    }
  }
  printf("%d", ans);
  return 0;
}