Problem p03702 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef tuple<int, int> tii;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(), (a).end()
#define FST first
#define SEC second
const int INF = (INT_MAX / 2);
const ll LLINF = (LLONG_MAX / 2);
const double eps = 1e-5;
const double PI = M_PI;
#define DEB cerr << "!" << endl
#define SHOW(a, b) cerr << (a) << " " << (b) << endl
#define SHOWARRAY(ar, i, j)                                                    \
  REP(a, i)                                                                    \
      REP(b, j) cerr << ar[a][b]                                               \
                     << ((b == j - 1) ? ((a == i - 1) ? ("\n\n") : ("\n"))     \
                                      : (" "))
#define DIV int(1e9 + 7)
inline ll pow(ll x, ll n, ll m) {
  ll r = 1;
  while (n > 0) {
    if ((n & 1) == 1)
      r = r * x % m;
    x = x * x % m;
    n >>= 1;
  }
  return r % m;
}

/* Coding Space*/
vector<ll> table;
ll a, b;

bool check(ll t) {
  vector<ll> h = table;
  ll times = t;
  rep(i, h.size()) {
    ll nowh = h[i] - t * b;
    if (nowh > 0) {
      ll d = (nowh + (a - b - 1)) / (a - b);
      times -= d;
      if (times < 0)
        return 0;
    }
  }
  return 1;
}

int main() {
  ll n;
  cin >> n >> a >> b;
  rep(i, n) {
    ll in;
    cin >> in;
    table.pb(in);
  }
  ll bottom = 0;
  ll top = INF;
  int times = 1000;
  while (check(top)) {
    ll middle = (bottom + top) / 2;
    if (check(middle))
      top = middle;
    else
      bottom = middle;
    times--;
    if (times == 0)
      top--;
  }
  cout << top + 1 << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef tuple<int, int> tii;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(), (a).end()
#define FST first
#define SEC second
const int INF = (INT_MAX / 2);
const ll LLINF = (LLONG_MAX / 2);
const double eps = 1e-5;
const double PI = M_PI;
#define DEB cerr << "!" << endl
#define SHOW(a, b) cerr << (a) << " " << (b) << endl
#define SHOWARRAY(ar, i, j)                                                    \
  REP(a, i)                                                                    \
      REP(b, j) cerr << ar[a][b]                                               \
                     << ((b == j - 1) ? ((a == i - 1) ? ("\n\n") : ("\n"))     \
                                      : (" "))
#define DIV int(1e9 + 7)
inline ll pow(ll x, ll n, ll m) {
  ll r = 1;
  while (n > 0) {
    if ((n & 1) == 1)
      r = r * x % m;
    x = x * x % m;
    n >>= 1;
  }
  return r % m;
}

/* Coding Space*/
vector<ll> table;
ll a, b;

bool check(ll t) {
  vector<ll> h = table;
  ll times = t;
  rep(i, h.size()) {
    ll nowh = h[i] - t * b;
    if (nowh > 0) {
      ll d = (nowh + (a - b - 1)) / (a - b);
      times -= d;
      if (times < 0)
        return 0;
    }
  }
  return 1;
}

int main() {
  ll n;
  cin >> n >> a >> b;
  rep(i, n) {
    ll in;
    cin >> in;
    table.pb(in);
  }
  ll bottom = 0;
  ll top = INF;
  int times = 50;
  while (check(top)) {
    ll middle = (bottom + top) / 2;
    if (check(middle))
      top = middle;
    else
      bottom = middle;
    times--;
    if (times == 0)
      top--;
  }
  cout << top + 1 << endl;
  return 0;
}