Problem p03702 (C++)

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

#define For(i, l, r)                                                           \
  for (register int i = (l), i##end = (int)(r); i <= i##end; ++i)
#define Fordown(i, r, l)                                                       \
  for (register int i = (r), i##end = (int)(l); i >= i##end; --i)
#define Rep(i, r) for (register int i = (0), i##end = (int)(r); i < i##end; ++i)
#define Set(a, v) memset(a, v, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define debug(x) cout << #x << ": " << (x) << endl

using namespace std;

template <typename T> inline bool chkmin(T &a, T b) {
  return b < a ? a = b, 1 : 0;
}
template <typename T> inline bool chkmax(T &a, T b) {
  return b > a ? a = b, 1 : 0;
}

inline int read() {
  int x(0), sgn(1);
  char ch(getchar());
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-')
      sgn = -1;
  for (; isdigit(ch); ch = getchar())
    x = (x * 10) + (ch ^ 48);
  return x * sgn;
}

void File() {
#ifdef zjp_shadow
  freopen("D.in", "r", stdin);
  freopen("D.out", "w", stdout);
#endif
}

typedef long long ll;

const int N = 1e5 + 1e3;

int n, h[N], A, B;

inline bool check(ll times) {
  ll cur = 0;
  For(i, 1, n) {
    ll tmp = h[i] - B * times;
    if (tmp > 0)
      cur += tmp / (A - B) + (tmp % (A - B) ? 1 : 0);
  }
  return cur <= times;
}

int main() {

  File();

  n = read(), A = read(), B = read();

  ll l = 0, r = 0, res = 0;
  For(i, 1, n) r += (h[i] = read()) / A + 1;

  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check(mid))
      res = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  printf("%lld\n", res);

  return 0;
}

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

#define For(i, l, r)                                                           \
  for (register int i = (l), i##end = (int)(r); i <= i##end; ++i)
#define Fordown(i, r, l)                                                       \
  for (register int i = (r), i##end = (int)(l); i >= i##end; --i)
#define Rep(i, r) for (register int i = (0), i##end = (int)(r); i < i##end; ++i)
#define Set(a, v) memset(a, v, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define debug(x) cout << #x << ": " << (x) << endl

using namespace std;

template <typename T> inline bool chkmin(T &a, T b) {
  return b < a ? a = b, 1 : 0;
}
template <typename T> inline bool chkmax(T &a, T b) {
  return b > a ? a = b, 1 : 0;
}

inline int read() {
  int x(0), sgn(1);
  char ch(getchar());
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-')
      sgn = -1;
  for (; isdigit(ch); ch = getchar())
    x = (x * 10) + (ch ^ 48);
  return x * sgn;
}

void File() {
#ifdef zjp_shadow
  freopen("D.in", "r", stdin);
  freopen("D.out", "w", stdout);
#endif
}

typedef long long ll;

const int N = 1e5 + 1e3;

int n, h[N], A, B;

inline bool check(ll times) {
  ll cur = 0;
  For(i, 1, n) {
    ll tmp = h[i] - B * times;
    if (tmp > 0)
      cur += tmp / (A - B) + (tmp % (A - B) ? 1 : 0);
  }
  return cur <= times;
}

int main() {

  File();

  n = read(), A = read(), B = read();

  ll l = 0, r = 0, res = 0;
  For(i, 1, n) r += (h[i] = read()) / A + 1;

  while (l <= r) {
    ll mid = (l + r) >> 1;
    if (check(mid))
      res = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  printf("%lld\n", res);

  return 0;
}