prithivMLmods/Coder-Stat huggingface dataset:
Problem p03472 (Python)

Buggy submission (status: Time Limit Exceeded):
N, H = map(int, input().split())
A = []
B = []
for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

max_a = max(A)
filtered = [b_i for b_i in B if b_i > max_a]
sum_b = sum(filtered)
if sum_b <= H:
    print(-(-(H - sum_b) // max_a) + len(filtered))
else:
    filtered.sort()
    filtered.reverse()
    print(len([x for x in [sum(filtered[: i + 1]) for i in range(N)] if x < H]) + 1)


Fixed submission:
N, H = map(int, input().split())
A = []
B = []
for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

max_a = max(A)
filtered = [b_i for b_i in B if b_i > max_a]
sum_b = sum(filtered)
if sum_b <= H:
    print(-(-(H - sum_b) // max_a) + len(filtered))
else:
    filtered.sort()
    filtered.reverse()
    s = 0
    for i in range(len(filtered)):
        s += filtered[i]
        if s >= H:
            print(i + 1)
            break
Problem p03472 (C++)

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

#define printLn(X) cout << X << endl
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

int a[10000];
int b[10000];
int main() {
  int N, H;
  cin >> N >> H;
  rep(i, N) { cin >> a[i] >> b[i]; }
  sort(a, a + N);
  sort(b, b + N);
  reverse(b, b + N);
  int maxA = a[N - 1];
  int ans = 0;
  rep(i, N) {
    if (b[i] <= maxA) {
      break;
    }
    ans++;
    H -= b[i];
    if (H <= 0) {
      printLn(ans);
      return 0;
    }
  }
  ans += (H + maxA - 1) / maxA;
  printLn(ans);
  return 0;
}


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

#define printLn(X) cout << X << endl
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

int a[100000];
int b[100000];
int main() {
  int N, H;
  cin >> N >> H;
  rep(i, N) { cin >> a[i] >> b[i]; }
  sort(a, a + N);
  sort(b, b + N);
  reverse(b, b + N);
  int maxA = a[N - 1];
  int ans = 0;
  rep(i, N) {
    if (b[i] <= maxA) {
      break;
    }
    ans++;
    H -= b[i];
    if (H <= 0) {
      printLn(ans);
      return 0;
    }
  }
  ans += (H + maxA - 1) / maxA;
  printLn(ans);
  return 0;
}
Problem p03472 (C++)

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

using namespace std;

#define rep(i, n) REP(i, 0, n)
#define REP(i, s, e) for (int i = (s); i < (int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for (int i = (int)(s - 1); i >= (int)(e); i--)
#define pb push_back
#define all(r) r.begin(), r.end()
#define rall(r) r.rbegin(), r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main() {
  ll n, h;
  cin >> n >> h;
  vl a(n), b(n);
  rep(i, n) cin >> a[i] >> b[i];
  ll A = -1;
  rep(i, n) A = max(A, a[i]);
  vl s;
  rep(i, n) {
    if (b[i] > A)
      s.pb(b[i]);
  }
  sort(rall(s));
  REP(i, 1, s.size()) s[i] += s[i - 1];
  auto calc = [&](ll m) {
    if (m == 0)
      return 0LL;
    if (m <= (ll)s.size())
      return s[m - 1];
    return s.back() + (m - (ll)s.size()) * A;
  };
  ll l = 0LL, r = 2e9;
  rep(i, 128) {
    ll m = (l + r) / 2;
    if (calc(m) >= h)
      r = m;
    else
      l = m;
  }
  cout << r << endl;
  return 0;
}

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

using namespace std;

#define rep(i, n) REP(i, 0, n)
#define REP(i, s, e) for (int i = (s); i < (int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for (int i = (int)(s - 1); i >= (int)(e); i--)
#define pb push_back
#define all(r) r.begin(), r.end()
#define rall(r) r.rbegin(), r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main() {
  ll n, h;
  cin >> n >> h;
  vl a(n), b(n);
  rep(i, n) cin >> a[i] >> b[i];
  ll A = -1;
  rep(i, n) A = max(A, a[i]);
  vl s;
  rep(i, n) {
    if (b[i] > A)
      s.pb(b[i]);
  }
  sort(rall(s));
  REP(i, 1, s.size()) s[i] += s[i - 1];
  auto calc = [&](ll m) {
    if (m == 0)
      return 0LL;
    if (m <= (ll)s.size())
      return s[m - 1];
    return (s.size() > 0 ? s.back() : 0) + (m - (ll)s.size()) * A;
  };
  ll l = 0LL, r = 2e9;
  rep(i, 128) {
    ll m = (l + r) / 2;
    if (calc(m) >= h)
      r = m;
    else
      l = m;
  }
  cout << r << endl;
  return 0;
}
Problem p03472 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll, ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll, ll>>>
#define PL pair<ll, ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main() {
  ll N, H;
  cin >> N >> H;
  VP p(N);
  ll mxa = 0;
  rep(i, 0, N) {
    cin >> p[i].second >> p[i].first;
    mxa = max(mxa, p[i].second);
  }
  sort(ALL(p), greater<PL>());
  cerr << "foo" << endl;
  VL sum;
  ll i = 0, now = 0;
  while (p[i].first > mxa && i < N) {
    sum.push_back(now + p[i].first);
    now += p[i].first;
    i++;
  }
  cerr << "hoge" << endl;
  ll r = sum.size();
  ll L = 0, R = 1e9 + 1;
  while (R - L > 1) {
    ll M = L + (R - L) / 2;
    ll mx;
    if (M <= r) {
      mx = sum[M - 1];
    } else {
      mx = sum[r - 1] + mxa * (M - r);
    }
    if (mx >= H)
      R = M;
    else
      L = M;
  }
  cout << R << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll, ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll, ll>>>
#define PL pair<ll, ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main() {
  ll N, H;
  cin >> N >> H;
  VP p(N);
  ll mxa = 0;
  rep(i, 0, N) {
    cin >> p[i].second >> p[i].first;
    mxa = max(mxa, p[i].second);
  }
  sort(ALL(p), greater<PL>());
  cerr << "foo" << endl;
  VL sum;
  ll i = 0, now = 0;
  while (p[i].first > mxa && i < N) {
    sum.push_back(now + p[i].first);
    now += p[i].first;
    i++;
  }
  cerr << "hoge" << endl;
  ll r = sum.size();
  ll L = 0, R = 1e9 + 1;
  while (R - L > 1) {
    ll M = L + (R - L) / 2;
    ll mx;
    if (r == 0) {
      mx = mxa * M;
    } else if (M <= r) {
      mx = sum[M - 1];
    } else {
      mx = sum[r - 1] + mxa * (M - r);
    }
    if (mx >= H)
      R = M;
    else
      L = M;
  }
  cout << R << endl;
  return 0;
}
Problem p03472 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
//*******************
// Mahmoud Magdy    *
//*******************
#define ll long long
#define endl "\n"

void fast() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
inline int D() {
  int m;
  cin >> m;
  return m;
}
inline ll lD() {
  ll m;
  cin >> m;
  return m;
}
inline double dD() {
  double m;
  cin >> m;
  return m;
}
int a[100005], b[100005];
int main() {
  int n = D(), k = D();
  for (int i = 0; i < n; ++i) {
    a[i] = D();
    b[i] = D();
  }
  sort(a, a + n);
  int mx = a[n - 1];
  ll sum = 0;
  int c = 0;
  sort(b, b + n);
  for (int i = n - 1; i >= 0; ++i) {
    if (sum >= k) {
      cout << c << endl;
      return 0;
    }
    if (mx <= b[i]) {
      sum += b[i];
      c++;
    }
  }
  if (sum >= k)
    cout << c << endl;
  else {
    int idx = (k - sum) / mx;
    if (idx >= 0) {
      if (idx * mx + sum < k)
        idx++;
    }
    cout << idx + c << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
//*******************
// Mahmoud Magdy    *
//*******************
#define ll long long
#define endl "\n"

void fast() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
inline int D() {
  int m;
  cin >> m;
  return m;
}
inline ll lD() {
  ll m;
  cin >> m;
  return m;
}
inline double dD() {
  double m;
  cin >> m;
  return m;
}
int a[100005], b[100005];
int main() {
  int n = D(), k = D();
  for (int i = 0; i < n; ++i) {
    a[i] = D();
    b[i] = D();
  }
  sort(a, a + n);
  int mx = a[n - 1];
  ll sum = 0;
  int c = 0;
  sort(b, b + n);
  for (int i = n - 1; i >= 0; --i) {
    if (sum >= k) {
      cout << c << endl;
      return 0;
    }
    if (mx <= b[i]) {
      sum += b[i];
      c++;
    }
  }
  if (sum >= k)
    cout << c << endl;
  else {
    int idx = (k - sum) / mx;
    if (idx >= 0) {
      if (idx * mx + sum < k)
        idx++;
    }
    cout << idx + c << endl;
  }
}
Problem p03472 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int arr_wield[100001], arr_throw[100001];
bool mycompare(const int &a, const int &b) { return a > b; }
int main() {
  int n, h = 0, i, count = 0, ans = 0, pos_w = 0, pos_t = 0;
  scanf("%d %d", &n, &h);
  for (i = 0; i < n; i++) {
    scanf("%d %d", &arr_wield[i], &arr_throw[i]);
  }
  sort(arr_wield, arr_wield + n, mycompare);
  sort(arr_throw, arr_throw + n, mycompare);
  while (h > 0) {
    if (arr_throw[pos_t] > arr_wield[0]) {
      h -= arr_throw[pos_t++];
      ans++;
    } else {
      ans += h / arr_wield[0];
      ans += h % arr_wield[0] == 0 ? 0 : 1;
    }
  }
  printf("%d", ans);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int arr_wield[100001], arr_throw[100001];
bool mycompare(const int &a, const int &b) { return a > b; }
int main() {
  int n, h = 0, i, count = 0, ans = 0, pos_w = 0, pos_t = 0;
  scanf("%d %d", &n, &h);
  for (i = 0; i < n; i++) {
    scanf("%d %d", &arr_wield[i], &arr_throw[i]);
  }
  sort(arr_wield, arr_wield + n, mycompare);
  sort(arr_throw, arr_throw + n, mycompare);
  while (h > 0) {
    if (arr_throw[pos_t] > arr_wield[0]) {
      h -= arr_throw[pos_t++];
      ans++;
    } else {
      ans += h / arr_wield[0];
      ans += h % arr_wield[0] == 0 ? 0 : 1;
      break;
    }
  }
  printf("%d", ans);
  return 0;
}
Problem p03472 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;

ll A_MAX = -1;
ll B[10000];

int N;
ll H;

int main() {
  cin >> N;
  cin >> H;

  ll a, b;

  for (int i = 0; i < N; i++) {
    cin >> a >> b;
    A_MAX = max(A_MAX, a);
    B[i] = b;
  }

  sort(B, B + N);

  int result = 0;

  int cou = N - 1;
  while (A_MAX < B[cou] && 0 <= cou) {
    H -= B[cou];
    cou--;
    result++;
    if (H <= 0) {
      cout << result << endl;
      return 0;
    }
  }

  int temp = H / A_MAX;
  if (H % A_MAX != 0)
    temp++;
  result += temp;

  cout << result << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;

ll A_MAX = -1;
ll B[100000];

int N;
ll H;

int main() {
  cin >> N;
  cin >> H;

  ll a, b;

  for (int i = 0; i < N; i++) {
    cin >> a >> b;
    A_MAX = max(A_MAX, a);
    B[i] = b;
  }

  sort(B, B + N);

  int result = 0;

  int cou = N - 1;
  while (A_MAX < B[cou] && 0 <= cou) {
    H -= B[cou];
    cou--;
    result++;
    if (H <= 0) {
      cout << result << endl;
      return 0;
    }
  }

  int temp = H / A_MAX;
  if (H % A_MAX != 0)
    temp++;
  result += temp;

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

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

using namespace std;

typedef long long int ll;
const double eps = 1e-7;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<double, int> di;
#define inf 100000000
const double PI = 2 * acos(0);

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  // freopen("ing.txt", "r", stdin);
  // freopen("outg.txt", "w", stdout);
  ll n, h;
  while (cin >> n >> h) {
    vector<pair<ll, ll>> a(n), b(n);
    for (ll i = 0; i < n; i++) {
      cin >> a[i].first >> b[i].first;
      a[i].second = b[i].second = i;
    }
    sort(a.rbegin(), a.rend());
    sort(b.rbegin(), b.rend());
    ll moves = 0;
    bool done = false;
    ll i = n - 1;
    while (b[i] <= a[0])
      i--;
    for (ll j = 0; j <= i; j++) {
      h -= b[j].first;
      moves++;
      if (h <= 0) {
        done = true;
        break;
      }
    }
    if (done) {
      cout << moves << "\n";
      continue;
    }
    ll step = (h + a[0].first - 1) / a[0].first;
    h -= step * a[0].first;
    moves += step;
    cout << moves << "\n";
  }

  return 0;
}

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

using namespace std;

typedef long long int ll;
const double eps = 1e-7;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<double, int> di;
#define inf 100000000
const double PI = 2 * acos(0);

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  // freopen("ing.txt", "r", stdin);
  // freopen("outg.txt", "w", stdout);
  ll n, h;
  while (cin >> n >> h) {
    vector<pair<ll, ll>> a(n), b(n);
    for (ll i = 0; i < n; i++) {
      cin >> a[i].first >> b[i].first;
      a[i].second = b[i].second = i;
    }
    sort(a.rbegin(), a.rend());
    sort(b.rbegin(), b.rend());
    ll moves = 0;
    bool done = false;
    ll i = n - 1;
    while (i and b[i] <= a[0])
      i--;
    for (ll j = 0; j <= i; j++) {
      h -= b[j].first;
      moves++;
      if (h <= 0) {
        done = true;
        break;
      }
    }
    if (done) {
      cout << moves << "\n";
      continue;
    }
    ll step = (h + a[0].first - 1) / a[0].first;
    h -= step * a[0].first;
    moves += step;
    cout << moves << "\n";
  }

  return 0;
}
Problem p03472 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
int main() {
  std::cin.tie(0);
  std::cin.sync_with_stdio(false);
  size_t n;
  int X;
  std::cin >> n >> X;
  std::vector<int> a(n), b(n);
  for (size_t i = 0; i < n; i++) {
    std::cin >> a[i] >> b[i];
  }
  int max = *std::max_element(a.begin(), a.end());
  std::sort(b.begin(), b.end(), std::greater<int>());
  unsigned ret = 0;
  while (X > 0) {
    auto x = b.front();
    if (x > max) {
      X -= x;
      ret++;
      b.erase(b.begin());
    } else {
      ret += (X + max - 1) / max;
      X = 0;
    }
  }
  std::cout << ret << std::endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
int main() {
  std::cin.tie(0);
  std::cin.sync_with_stdio(false);
  size_t n;
  int X;
  std::cin >> n >> X;
  std::vector<int> a(n), b(n);
  for (size_t i = 0; i < n; i++) {
    std::cin >> a[i] >> b[i];
  }
  int max = *std::max_element(a.begin(), a.end());
  std::sort(b.begin(), b.end(), std::greater<int>());
  unsigned ret = 0;
  while (X > 0) {
    if (!b.empty() && b.front() > max) {
      X -= b.front();
      ret++;
      b.erase(b.begin());
    } else {
      ret += (X + max - 1) / max;
      X = 0;
    }
  }
  std::cout << ret << std::endl;
  return 0;
}
Problem p03472 (C++)

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

using namespace std;

typedef long long ll;

bool reversecompare(int a, int b) { return a > b; }

struct katana {
  ll nom;
  ll wi;
  ll th;
};

bool bandingwi(katana a, katana b) { return a.wi > b.wi; }

bool bandingth(katana a, katana b) { return a.th > b.th; }

bool bandingthbalik(katana a, katana b) { return a.th < b.th; }

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

  katana pedang[10010];
  ll N, H, counta, counter;
  katana dummy;

  cin >> N >> H;

  for (int i = 0; i < N; i++) {
    pedang[i].nom = i;
    cin >> pedang[i].wi >> pedang[i].th;
  }

  stable_sort(pedang, pedang + N, bandingthbalik);
  stable_sort(pedang, pedang + N, bandingwi);

  dummy = pedang[0];
  counta = 0;
  counter = 0;

  stable_sort(pedang, pedang + N, bandingth);

  while (H > 0) {
    if (dummy.th >= H) {
      counta++;
      H -= dummy.th;
    } else {
      if (counter >= N) {
        H -= dummy.wi;
        counta++;
      } else if (pedang[counter].nom == dummy.nom) {
        counter++;
      } else if (dummy.wi >= pedang[counter].th) {
        H -= dummy.wi;
        counta++;
      } else {
        H -= pedang[counter].th;
        counter++;
        counta++;
      }
    }
  }

  cout << counta << endl;

  return 0;
}

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

using namespace std;

typedef long long ll;

bool reversecompare(int a, int b) { return a > b; }

struct katana {
  ll nom;
  ll wi;
  ll th;
};

bool bandingwi(katana a, katana b) { return a.wi > b.wi; }

bool bandingth(katana a, katana b) { return a.th > b.th; }

bool bandingthbalik(katana a, katana b) { return a.th < b.th; }

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

  katana pedang[100010];
  ll N, H, counta, counter;
  katana dummy;

  cin >> N >> H;

  for (int i = 0; i < N; i++) {
    pedang[i].nom = i;
    cin >> pedang[i].wi >> pedang[i].th;
  }

  stable_sort(pedang, pedang + N, bandingthbalik);
  stable_sort(pedang, pedang + N, bandingwi);

  dummy = pedang[0];
  counta = 0;
  counter = 0;

  stable_sort(pedang, pedang + N, bandingth);

  while (H > 0) {
    if (dummy.th >= H) {
      counta++;
      H -= dummy.th;
    } else {
      if (counter >= N) {
        H -= dummy.wi;
        counta++;
      } else if (pedang[counter].nom == dummy.nom) {
        counter++;
      } else if (dummy.wi >= pedang[counter].th) {
        H -= dummy.wi;
        counta++;
      } else {
        H -= pedang[counter].th;
        counter++;
        counta++;
      }
    }
  }

  cout << counta << endl;

  return 0;
}
Problem p03472 (C++)

Buggy submission (status: Runtime Error):
//@editor aokabi
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
const int INF = 1e9;
typedef long long ll;
typedef pair<ll, ll> P;

int main() {
  ll N, H;
  cin >> N >> H;
  vector<ll> a(N), b(H);
  for (int i = 0; i < N; i++)
    cin >> a[i] >> b[i];

  // ふり最強剣
  ll a_max = *max_element(all(a));
  // 強いものから投げる
  sort(all(b));
  reverse(all(b));
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    if (a_max < b[i]) {
      H -= b[i];
      ans++;
      // 投げで倒した
      if (H <= 0)
        break;
    }
  }
  // 剣を振りまくって倒す
  // ans += ceil(H/a_max) : H/max以上の最大の整数
  if (H > 0)
    ans += (H + (a_max - 1)) / a_max;
  cout << ans << endl;
}

Fixed submission:
//@editor aokabi
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
const int INF = 1e9;
typedef long long ll;
typedef pair<ll, ll> P;

int main() {
  ll N, H;
  cin >> N >> H;
  vector<ll> a(N), b(N);
  for (int i = 0; i < N; i++)
    cin >> a[i] >> b[i];

  // ふり最強剣
  ll a_max = *max_element(all(a));
  // 強いものから投げる
  sort(all(b));
  reverse(all(b));
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    if (a_max < b[i]) {
      H -= b[i];
      ans++;
      // 投げで倒した
      if (H <= 0)
        break;
    }
  }
  // 剣を振りまくって倒す
  // ans += ceil(H/a_max) : H/max以上の最大の整数
  if (H > 0)
    ans += (H + (a_max - 1)) / a_max;
  cout << ans << endl;
}
Problem p03472 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int N = 10000 + 10;
int a[N];
bool cmp(int a, int b) { return a > b; }
int main() {
  int n, w;
  while (~scanf("%d%d", &n, &w)) {
    int x, y, _max = 0;

    for (int i = 0; i < n; i++) {
      scanf("%d%d", &x, &a[i]);
      _max = max(_max, x);
    }
    sort(a, a + n, cmp);
    int sum = 0;
    for (int i = 0; i < n; i++) {
      if (_max > a[i])
        break;
      sum++;
      w -= a[i];
      if (w <= 0)
        break;
    }
    if (w > 0) {
      sum += w % _max == 0 ? w / _max : w / _max + 1;
    }
    printf("%d\n", sum);
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int N = 100000 + 10;
int a[N];
bool cmp(int a, int b) { return a > b; }
int main() {
  int n, w;
  while (~scanf("%d%d", &n, &w)) {
    int x, y, _max = 0;

    for (int i = 0; i < n; i++) {
      scanf("%d%d", &x, &a[i]);
      _max = max(_max, x);
    }
    sort(a, a + n, cmp);
    int sum = 0;
    for (int i = 0; i < n; i++) {
      if (_max > a[i])
        break;
      sum++;
      w -= a[i];
      if (w <= 0)
        break;
    }
    if (w > 0) {
      sum += w % _max == 0 ? w / _max : w / _max + 1;
    }
    printf("%d\n", sum);
  }

  return 0;
}
Problem p03472 (C++)

Buggy submission (status: Runtime Error):

#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
typedef struct pair<ll, int> P;

int a[10001] = {};
int b[10001] = {};

int main() {
  int n, h;

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


Fixed submission:

#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
typedef struct pair<ll, int> P;

int a[100001] = {};
int b[100001] = {};

int main() {
  int n, h;

  cin >> n >> h;
  for (int i = 0; i < n; ++i)
    cin >> a[i] >> b[i];
  sort(a, a + n);
  sort(b, b + n);
  int t = 0;
  int c = 0;
  int k = n - 1;
  while (t < h) {
    if (b[k] > a[n - 1] && (k >= 0)) {
      t += b[k];
      k--;
      c++;
    } else {
      c += ((h - t) / a[n - 1]);
      if ((h - t) % a[n - 1] > 0)
        c++;
      t = h + 1;
    }
  }
  cout << c << endl;
  return 0;
}
Problem p03472 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;
long long H;
int n, a[100100], b[100100], amax = -1, d[100100], ok = 0, cnt, i, ans;
int main() {
  // freopen("1.in","r",stdin);freopen("1.out","w",stdout)
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> H;
  for (i = 1; i <= n; i++) {
    cin >> a[i] >> b[i];
    amax = max(amax, a[i]);
  }
  sort(b + 1, b + n + 1);
  for (i = 1; i <= n; i++) {
    if (b[n - i + 1] > amax) {
      d[++cnt] = d[i - 1] + b[n - i + 1];
      if (d[cnt] >= H)
        goto num1;
    } else
      break;
  }
  while (d[cnt] < H) {
    d[cnt + 1] = d[cnt] + amax;
    cnt++;
  }
num1:
  cout << cnt << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;
long long H;
int n, a[100100], b[100100], amax = -1, d[100100], ok = 0, cnt, i, ans;
int main() {
  // freopen("1.in","r",stdin);freopen("1.out","w",stdout)
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> H;
  for (i = 1; i <= n; i++) {
    cin >> a[i] >> b[i];
    amax = max(amax, a[i]);
  }
  sort(b + 1, b + n + 1);
  for (i = 1; i <= n; i++) {
    if (b[n - i + 1] > amax) {
      d[++cnt] = d[i - 1] + b[n - i + 1];
      if (d[cnt] >= H)
        goto num1;
    } else
      break;
  }

  if (d[cnt] < H) {
    if ((H - d[cnt]) % amax == 0)
      cnt += (H - d[cnt]) / amax;
    else
      cnt += ((H - d[cnt]) / amax) + 1;
  }
num1:
  cout << cnt << endl;
  return 0;
}
Problem p03472 (C++)

Buggy submission (status: Runtime Error):
/* 2018-01-07-17.30.16 */

#include <bits/stdc++.h>
#define ll long long int
#define N 100010
using namespace std;
struct type {
  ll n, t;
};
bool compare(type a, type b) { return a.n > b.n; }
int main() {
  ll n, h, i;
  cin >> n >> h;
  type a[N];
  for (i = 0; i < n; i++) {
    ll x, y;
    cin >> x >> y;
    a[2 * i].n = x, a[2 * i].t = 1;
    a[2 * i + 1].n = y, a[2 * i + 1].t = 2;
  }
  sort(a, a + 2 * n, compare);
  ll cnt = 0;
  for (i = 0; i < 2 * n; i++) {
    if (a[i].t == 1) {
      if (h % a[i].n == 0)
        cnt += h / a[i].n;
      else
        cnt += (h / a[i].n + 1);
      break;
    }
    h -= a[i].n;
    cnt++;
    if (h <= 0)
      break;
  }
  cout << cnt << endl;
  return 0;
}


Fixed submission:
/* 2018-01-07-17.30.16 */

#include <bits/stdc++.h>
#define ll long long int
#define N 1000010
using namespace std;
struct type {
  ll n, t;
};
bool compare(type a, type b) { return a.n > b.n; }
int main() {
  ll n, h, i;
  cin >> n >> h;
  type a[N];
  for (i = 0; i < n; i++) {
    ll x, y;
    cin >> x >> y;
    a[2 * i].n = x, a[2 * i].t = 1;
    a[2 * i + 1].n = y, a[2 * i + 1].t = 2;
  }
  sort(a, a + 2 * n, compare);
  ll cnt = 0;
  for (i = 0; i < 2 * n; i++) {
    if (a[i].t == 1) {
      if (h % a[i].n == 0)
        cnt += h / a[i].n;
      else
        cnt += (h / a[i].n + 1);
      break;
    }
    h -= a[i].n;
    cnt++;
    if (h <= 0)
      break;
  }
  cout << cnt << 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), b(N);
  int ma = 0;
  for (int i = 0; i < N; ++i) {
    cin >> a[i] >> b[i];
    ma = max(a[i], ma);
  }
  vector<int> c, d;
  for (int i = 0; i < N; ++i) {
    if (b[i] > ma) {
      c.push_back(a[i]), d.push_back(b[i]);
    }
  }
  sort(rbegin(c), rend(c));
  sort(rbegin(d), rend(d));
  N = c.size();

  int ans = 0;
  for (int i = 0; i < N && H > 0; ++i, ++ans) {
    H -= d[i];
  }
  ans += (max(0, H) + c[0] - 1) / c[0];

  cout << ans << endl;
}

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

int main() {
  int N, H;
  cin >> N >> H;
  vector<int> a(N), b(N);
  int ma = 0;
  for (int i = 0; i < N; ++i) {
    cin >> a[i] >> b[i];
    ma = max(a[i], ma);
  }
  vector<int> c, d;
  for (int i = 0; i < N; ++i) {
    if (b[i] >= ma) {
      c.push_back(a[i]), d.push_back(b[i]);
    }
  }
  sort(rbegin(c), rend(c));
  sort(rbegin(d), rend(d));
  N = c.size();

  int ans = 0;
  for (int i = 0; i < N && H > 0; ++i, ++ans) {
    H -= d[i];
  }
  ans += (max(0, H) + c[0] - 1) / c[0];

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

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

int main() {
  ll n, h, a[10050], b[10050], cnt = 0, dam = 0;
  cin >> n >> h;
  for (int i = 0; i < n; i++)
    cin >> a[i] >> b[i];
  sort(a, a + n);
  sort(b, b + n);
  for (int i = n - 1; i >= 0; i--) {
    if (b[i] < a[n - 1])
      break;
    dam += b[i], cnt++;
    if (dam >= h) {
      cout << cnt << endl;
      return 0;
    }
  }
  h -= dam;
  if (h % a[n - 1])
    cout << cnt + h / a[n - 1] + 1 << endl;
  else
    cout << cnt + h / a[n - 1] << endl;
}


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

int main() {
  ll n, h, a[100500], b[100500], cnt = 0, dam = 0;
  cin >> n >> h;
  for (int i = 0; i < n; i++)
    cin >> a[i] >> b[i];
  sort(a, a + n);
  sort(b, b + n);
  for (int i = n - 1; i >= 0; i--) {
    if (b[i] < a[n - 1])
      break;
    dam += b[i], cnt++;
    if (dam >= h) {
      cout << cnt << endl;
      return 0;
    }
  }
  h -= dam;
  if (h % a[n - 1])
    cout << cnt + h / a[n - 1] + 1 << endl;
  else
    cout << cnt + h / a[n - 1] << endl;
}
Problem p03472 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef struct sword {
  int damage, flag;
  bool operator<(const struct sword &a) const { return damage > a.damage; }
} SWORD, *PSWORD;
SWORD s[200001];
int main() {
  int N, H, i, count = 0, ans = 0;
  scanf("%d %d", &N, &H);
  // 读入
  for (i = 0; i < N; i++) {
    scanf("%d", &s[count].damage);
    s[count++].flag = 0;
    scanf("%d", &s[count].damage);
    s[count++].flag = 1;
  }
  // 排序
  sort(s, s + count);
  i = 0;
  while (H > 0) {
    H -= s[i].damage;
    ans++;
    if (s[i].flag == 1)
      i++;
  }
  printf("%d", ans);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef struct sword {
  int damage, flag;
  bool operator<(const struct sword &a) const { return damage > a.damage; }
} SWORD, *PSWORD;
SWORD s[200001];
int main() {
  int N, H, i, count = 0, ans = 0;
  scanf("%d %d", &N, &H);
  // 读入
  for (i = 0; i < N; i++) {
    scanf("%d", &s[count].damage);
    s[count++].flag = 0;
    scanf("%d", &s[count].damage);
    s[count++].flag = 1;
  }
  // 排序
  sort(s, s + count);
  i = 0;
  while (H > 0) {
    H -= s[i].damage;
    ans++;
    if (s[i].flag == 1)
      i++;
    else if (H > 0) {
      ans += H / s[i].damage;
      ans += H % s[i].damage == 0 ? 0 : 1;
      break;
    }
  }
  printf("%d", ans);
  return 0;
}
Problem p03473 (Python)

Buggy submission (status: Runtime Error):
date = input()
date = list(date)
date[3] = "8"
date = "".join(date)
print(date)


Fixed submission:
hour = int(input())

print(48 - hour)
Problem p03473 (C++)

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

int main() {
  int M;
  scanf("%d", M);
  printf("%d\n", 48 - M);
  return 0;
}

Fixed submission:
#include <stdio.h>

int main() {
  int M;
  scanf("%d", &M);
  printf("%d\n", 48 - M);
  return 0;
}
Problem p03473 (C++)

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

int M;

int main() {

  scanf("%d", M);
  printf("%d\n", 48 - M);
}

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

int M;

int main() {

  scanf("%d", &M);
  printf("%d\n", 48 - M);
}
Problem p03473 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  return 48 - n;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  cout << 48 - n << endl;
}
Problem p03473 (C++)

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

int main() {
  int anxious;
  std::cin >> anxious;
  std::cout << 24 - anxious << '\n';
  return 99;
}

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

int main() {
  int anxious;
  std::cin >> anxious;
  std::cout << 24 - anxious + 24 << '\n';
  return 0;
}
Problem p03473 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
int main(void) {
  int x;
  scanf("%d", x);
  printf("%d\n", 48 - x);
  return 0;
}

Fixed submission:
#include <stdio.h>
int main(void) {
  int x;
  scanf("%d", &x);
  printf("%d\n", 48 - x);
  return 0;
}
Problem p03473 (Python)

Buggy submission (status: Runtime Error):
m = input()
n = 48 - m
print(n)


Fixed submission:
m = int(input())
n = 48 - m
print(n)
Problem p03473 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <fstream>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define forn(i, n) for (i = 0; i < n; i++)
#define forc(i, c, n) for (i = c; i <= n; i++)
typedef list<ll> LST;
typedef vector<ll> VEC;
typedef map<ll, ll> MAP;

int main() {
  ifstream fin("Text.txt");
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  ll i, j, q;
  ll n, m, p, k, t;
  ll a, b, c, d;
  ll x, y, z, l, r;
  ll one = 1, zero = 0, ans = 0;
  ll mod = 1000000007;
  string st1, st2, st3;
  char ch1, ch2, ch3;

  cin >> m;
  return 2 * 24 - m;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <fstream>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define forn(i, n) for (i = 0; i < n; i++)
#define forc(i, c, n) for (i = c; i <= n; i++)
typedef list<ll> LST;
typedef vector<ll> VEC;
typedef map<ll, ll> MAP;

int main() {
  ifstream fin("Text.txt");
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  ll i, j, q;
  ll n, m, p, k, t;
  ll a, b, c, d;
  ll x, y, z, l, r;
  ll one = 1, zero = 0, ans = 0;
  ll mod = 1000000007;
  string st1, st2, st3;
  char ch1, ch2, ch3;

  cin >> m;
  cout << 2 * 24 - m << endl;
  return 0;
}
Problem p03474 (C++)

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

int main() {
  int a, b;
  cin >> a >> b;
  string s;
  bool ans = true;
  if (s.at(a) != '-') {
    ans = false;
  }
  for (int i = 0; i < a; i++) {
    if (s.at(i) == '-') {
      ans = false;
    }
  }
  for (int i = a + 1; i < a + b + 1; i++) {
    if (s.at(i) == '-') {
      ans = false;
    }
  }
  cout << (ans ? "Yes" : "No") << endl;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  string s;
  cin >> s;
  bool ans = true;
  if (s.at(a) != '-') {
    ans = false;
  }
  for (int i = 0; i < a; i++) {
    if (s.at(i) == '-') {
      ans = false;
    }
  }
  for (int i = a + 1; i < a + b + 1; i++) {
    if (s.at(i) == '-') {
      ans = false;
    }
  }
  cout << (ans ? "Yes" : "No") << endl;
}
Problem p03474 (C++)

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

int main() {
  int a, b;
  char s[100];
  scanf("%d %d", a, b);
  // cin >> a >> b;
  scanf("%s", &s);

  bool judge = true;
  int i = 0;
  /*for(;i<a;i++)
  {
      if(s[i]=='-'){
          judge=false;
      }
  }
  if(s[i]!='-'){
          judge=false;
      }
  for(;i<a+b+1;i++){
      if(s[i]=='-'){
          judge=false;
      }
  }
  */
  for (i = 0; i < a; i++) {
    if (s[i] == '-') {
      judge = false;
    }
  }

  if (s[a] != '-') {
    judge = false;
  }
  for (i = a + 1; i < a + b + 1; i++) {
    if (s[i] == '-') {
      judge = false;
    }
  }
  if (s[i] != '\0')
    judge = false;
  if (judge)
    printf("Yes\n");
  else
    printf("No\n");
}

Fixed submission:
#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
  int a, b;
  char s[100];
  scanf("%d %d", &a, &b);
  // cin >> a >> b;
  scanf("%s", &s);

  bool judge = true;
  int i = 0;
  /*for(;i<a;i++)
  {
      if(s[i]=='-'){
          judge=false;
      }
  }
  if(s[i]!='-'){
          judge=false;
      }
  for(;i<a+b+1;i++){
      if(s[i]=='-'){
          judge=false;
      }
  }
  */
  for (i = 0; i < a; i++) {
    if (s[i] == '-') {
      judge = false;
    }
  }

  if (s[a] != '-') {
    judge = false;
  }
  for (i = a + 1; i < a + b + 1; i++) {
    if (s[i] == '-') {
      judge = false;
    }
  }
  if (s[i] != '\0')
    judge = false;
  if (judge)
    printf("Yes\n");
  else
    printf("No\n");
}
Problem p03474 (C++)

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

bool right();

int main() {
  if (right())
    printf("Yes\n");
  else
    printf("No\n");

  return 0;
}

bool right() {
  char s[8];
  int a, b;
  scanf("%d%d%s", &a, &b, s);
  if (s[a] != '-')
    return false;
  for (int i = 0; i < a + b + 1; i++)
    if ((s[i] < '0' || s[i] > '9') && i != a)
      return false;

  return true;
}

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

bool right();

int main() {
  if (right())
    printf("Yes\n");
  else
    printf("No\n");

  return 0;
}

bool right() {
  char s[16];
  int a, b;
  scanf("%d%d%s", &a, &b, s);
  if (s[a] != '-')
    return false;
  for (int i = 0; i < a + b + 1; i++)
    if ((s[i] < '0' || s[i] > '9') && i != a)
      return false;

  return true;
}
Problem p03474 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
int main() {
  int a, b;
  char s[11];
  scanf("%d %d", &a, &b);
  scanf("%s", s);
  for (size_t i = 0; i < a + b + 1; i++) {
    if (i == a && s[i] != '-') {
      printf("No");
      return 1;
    } else if (i != a && (s[i] < '0' || s[i] > '9')) {
      printf("No");
      return 0;
    }
  }
  printf("Yes");
  return 0;
}

Fixed submission:
#include <stdio.h>
int main() {
  int a, b;
  char s[11];
  scanf("%d %d", &a, &b);
  scanf("%s", s);
  for (size_t i = 0; i < a + b + 1; i++) {
    if (i == a && s[i] != '-') {
      printf("No");
      return 0;
    } else if (i != a && (s[i] < '0' || s[i] > '9')) {
      printf("No");
      return 0;
    }
  }
  printf("Yes");
  return 0;
}
Problem p03474 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b;
  string s;
  cin >> a >> b >> s;
  for (int i = 0; i < s.size(); i++) {
    if (i = a)
      continue;
    if (s[i] == '-') {
      cout << "No" << endl;
      return 0;
    }
  }
  if (a + b + 1 == s.size() && s[a] == '-') {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b;
  string s;
  cin >> a >> b >> s;
  for (int i = 0; i < s.size(); i++) {

    if (s[i] == '-' && i != a) {
      cout << "No" << endl;
      return 0;
    }
  }
  if (a + b + 1 == s.size() && s[a] == '-') {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p03474 (C++)

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

int main(void) {
  int A, B;
  string post_number;

  cin >> A >> B;
  cin >> post_number;
  bool ok = false;
  for (int i = 0; i < post_number.length(); i++) {
    if (i != A && post_number[i] == '-') {
      cout << "No" << endl;
      exit(1);
    } else if (i == A && post_number[i] == '-') {
      ok = true;
    }
  }
  if (ok)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

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

int main(void) {
  int A, B;
  string post_number;

  cin >> A >> B;
  cin >> post_number;
  bool ok = false;
  for (int i = 0; i < post_number.length(); i++) {
    if (i != A && post_number[i] == '-') {
      ok = false;
      break;
    } else if (i == A && post_number[i] == '-') {
      ok = true;
    }
  }
  if (ok)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
Problem p03474 (C++)

Buggy submission (status: Runtime Error):
#include <ctype.h>
#include <iostream>
#include <string>

int main() {
  int a, b;
  std::string s;

  std::cin >> a;
  std::cin >> b;
  std::cin >> s;

  if (s[a] == '-' && s.length() == a + b + 1) {
    s.erase(a, 1);

    for (const auto n : s) {
      if (!isdigit(n)) {
        std::cout << "No" << std::endl;
        return -1;
      }
    }

    std::cout << "Yes" << std::endl;
  } else
    std::cout << "No" << std::endl;
}

Fixed submission:
#include <ctype.h>
#include <iostream>
#include <string>

int main() {
  int a, b;
  std::string s;

  std::cin >> a;
  std::cin >> b;
  std::cin >> s;

  if (s[a] == '-' && s.length() == a + b + 1) {
    s.erase(a, 1);

    for (const auto n : s) {
      if (!isdigit(n)) {
        std::cout << "No" << std::endl;
        return 0;
      }
    }

    std::cout << "Yes" << std::endl;
  } else
    std::cout << "No" << std::endl;
}
Problem p03474 (C++)

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

int main() {
  int A, B;
  string s;
  bool f = false;
  if (s.at(A) != '-')
    f = true;
  for (int i = 0; i < A; i++) {
    if (s.at(i) == '-') {
      f = true;
      break;
    }
  }
  for (int i = A + 1; i < s.size(); i++) {
    if (s.at(i) == '-') {
      f = true;
      break;
    }
  }
  if (f)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
}


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

int main() {
  int A, B;
  string s;
  cin >> A >> B >> s;
  bool f = false;
  if (s.at(A) != '-')
    f = true;
  for (int i = 0; i < A; i++) {
    if (s.at(i) == '-') {
      f = true;
      break;
    }
  }
  for (int i = A + 1; i < s.size(); i++) {
    if (s.at(i) == '-') {
      f = true;
      break;
    }
  }
  if (f)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
}
Problem p03474 (Python)

Buggy submission (status: Runtime Error):
def solve(string):
    a, b, s = string.split()
    a = int(a)
    return "Yes" if s[a] == "-" and (s[:a] + s[a + 1 :]).isdigit() else "No"


if __name__ == "__main__":
    print(solve(input()))


Fixed submission:
def solve(string):
    a, b, s = string.split()
    a = int(a)
    return "Yes" if s[a] == "-" and (s[:a] + s[a + 1 :]).isdigit() else "No"


if __name__ == "__main__":
    print(solve("\n".join([input(), input()])))
Problem p03474 (Python)

Buggy submission (status: Runtime Error):
a, b = map(int, input().split())
s = input()
first, second = s.split("-")
if len(first) == a and len(second) == b:
    print("Yes")
else:
    print("No")


Fixed submission:
a, b = map(int, input().split())
s = input()
try:
    first, second = s.split("-")
    if len(first) == a and len(second) == b:
        print("Yes")
    else:
        print("No")
except:
    print("No")
Problem p03474 (Python)

Buggy submission (status: Runtime Error):
a, b = list(map(int, input().slpit()))
s = input().split("-")

if len(s) != 2:
    print("No")
elif len(s[0]) == a and len(s[1]) == b:
    print("Yes")
else:
    print("No")


Fixed submission:
a, b = list(map(int, input().split()))
s = input().split("-")

if len(s) != 2:
    print("No")
elif len(s[0]) == a and len(s[1]) == b:
    print("Yes")
else:
    print("No")
Problem p03474 (Python)

Buggy submission (status: Runtime Error):
def actual(a, b, s):
    if s[a] != "-":
        return "No"

    for i in range(0, a):
        if not "0" <= s[i] <= "9":
            return "No"

    for j in range(a + 1, len(s) + 1):
        if not "0" <= s[j] <= "9":
            return "No"

    return "Yes"


a, b = map(int, input().split())
s = input()

print(actual(a, b, s))


Fixed submission:
def actual(a, b, s):
    if s[a] != "-":
        return "No"

    for i in range(0, a):
        if not "0" <= s[i] <= "9":
            return "No"

    for j in range(a + 1, len(s)):
        if not "0" <= s[j] <= "9":
            return "No"

    return "Yes"


a, b = map(int, input().split())
s = input()

print(actual(a, b, s))
Problem p03474 (Python)

Buggy submission (status: Runtime Error):
A, B = input().split()
S1, S2 = input().split("-")
print("Yes" if len(S1) == A and len(S2) == B else "No")


Fixed submission:
A, B = map(int, input().split())
S = input().split("-")
print("Yes" if len(S) == 2 and len(S[0]) == A and len(S[1]) == B else "No")
Problem p03475 (C++)

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

using namespace std;

int val[501], X[501], Y[501], Z[501];

int main(void) {
  int n;
  cin >> n;
  for (int i = 1; i < n; ++i) {
    cin >> X[i] >> Y[i] >> Z[i];
  }
  for (int i = 1; i <= n; ++i) {
    long t = Y[i] + X[i];
    for (int j = i + 1; j <= n; ++j) {
      if (t > Y[j]) {
        t -= Y[j];
        if (t % Z[j]) {
          t /= Z[j];
          t++;
          t *= Z[j];
        }
        t += Y[j];
      } else {
        t = Y[j];
      }
      t += X[j];
    }
    cout << t << "\n";
  }
}

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

using namespace std;

int val[501], X[501], Y[501], Z[501];

int main(void) {
  int n;
  cin >> n;
  for (int i = 1; i < n; ++i) {
    cin >> X[i] >> Y[i] >> Z[i];
  }
  for (int i = 1; i <= n; ++i) {
    long t = Y[i] + X[i];
    for (int j = i + 1; j < n; ++j) {
      if (t > Y[j]) {
        t -= Y[j];
        if (t % Z[j]) {
          t /= Z[j];
          t++;
          t *= Z[j];
        }
        t += Y[j];
      } else {
        t = Y[j];
      }
      t += X[j];
    }
    cout << t << "\n";
  }
}
Problem p03475 (Python)

Buggy submission (status: Time Limit Exceeded):
N = int(input())
C, S, F = [], [], []
for _ in range(N - 1):
    c, s, f = map(int, input().split())
    C.append(c)
    S.append(s)
    F.append(f)


def next_time(i, t):
    a = S[i]
    while a < t:
        a += F[i]
    return a


for i in range(N):
    time = 0
    for j in range(i, N - 1):
        time = next_time(j, time)
        time += C[j]

    print(time)


Fixed submission:
N = int(input())
C, S, F = [], [], []
for _ in range(N - 1):
    c, s, f = map(int, input().split())
    C.append(c)
    S.append(s)
    F.append(f)


def next_time(i, t):
    a = S[i]
    if t - a < 0:
        return a
    if t % F[i] == 0:
        return t
    b = (t - a + F[i] - 1) // F[i]
    # print(i, t, a, b, t + b * F[i])
    assert (a + b * F[i]) % F[i] == 0
    return a + b * F[i]


for i in range(N):
    time = 0
    for j in range(i, N - 1):
        time = next_time(j, time)
        time += C[j]

    print(time)
Problem p03475 (C++)

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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return
// a[0]<b[0];});

#define REP(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define RREP(i, n) for (ll(i) = (n)-1; (i) >= 0; (i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a, b) a = max((a), (b))
#define CHMIN(a, b) a = min((a), (b))
/*}}}*/
int main() {
  ll n;
  cin >> n;
  vl c(n - 1), s(n - 1), f(n - 2);
  REP(i, n - 1) {
    cin >> c[i];
    cin >> s[i];
    cin >> f[i];
  }
  REP(i, n - 1) {
    ll time = s[i] + c[i];
    for (ll j = i + 1; j < n - 1; j++) {
      ll start = s[j];
      if (start < time) {
        ll t = (time - start - 1) / f[j] + 1;
        start += t * f[j];
      }
      time = start + c[j];
    }
    cout << time << endl;
  }
  cout << 0 << endl;
  return 0;
}


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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return
// a[0]<b[0];});

#define REP(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define RREP(i, n) for (ll(i) = (n)-1; (i) >= 0; (i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a, b) a = max((a), (b))
#define CHMIN(a, b) a = min((a), (b))
/*}}}*/
int main() {
  ll n;
  cin >> n;
  vl c(n - 1), s(n - 1), f(n - 1);
  REP(i, n - 1) {
    cin >> c[i];
    cin >> s[i];
    cin >> f[i];
  }
  REP(i, n - 1) {
    ll time = s[i] + c[i];
    for (ll j = i + 1; j < n - 1; j++) {
      ll start = s[j];
      if (start < time) {
        ll t = (time - start - 1) / f[j] + 1;
        start += t * f[j];
      }
      time = start + c[j];
    }
    cout << time << endl;
  }
  cout << 0 << endl;
  return 0;
}
Problem p03475 (Python)

Buggy submission (status: Time Limit Exceeded):
N = int(input())
C, S, F = [0] * (N - 1), [0] * (N - 1), [0] * (N - 1)
for i in range(N - 1):
    C[i], S[i], F[i] = map(int, input().split())


def get_t(x, i):
    t = S[i]
    while x > t:
        t += F[i]
    return t


for i in range(N - 1):
    x = S[i] + C[i]
    for j in range(i + 1, N - 1):
        t = get_t(x, j)
        x = t + C[j]
    print(x)
print(0)


Fixed submission:
N = int(input())
C, S, F = [0] * (N - 1), [0] * (N - 1), [0] * (N - 1)
for i in range(N - 1):
    C[i], S[i], F[i] = map(int, input().split())

for i in range(N):
    t = 0
    for j in range(i, N - 1):
        if t < S[j]:
            t = S[j]
        elif t % F[j] == 0:
            pass
        else:
            t += F[j] - t % F[j]
        t += C[j]
    print(t)