Problem p03702 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <assert.h>
#include <cassert>
#include <ccomplex>
#include <chrono>
#include <clocale>
#include <cmath>
#include <complex>
#include <ctype.h>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <locale>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <utility>
#include <valarray>
#include <vector>
#include <wchar.h>

using namespace std;
typedef long long int LL;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(), (c).end())
#define BACKSORT(c) sort((c).begin(), (c).end(), std::greater<LL>())
#define FOR(i, a, b) for (LL i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

int xcomp(vector<LL> &a, vector<LL> &b) { return a[0] < b[0]; }

#define XSORT(c) sort((c).begin(), (c).end(), xcomp)

#define ALL(x) (x).begin(), (x).end()
LL mod = 1000000007;

LL N, A, B;
vector<LL> v(0);

LL ultrasuperfunction(LL v, LL A) {
  if (v <= 0) {
    return 0;
  } else {
    if (v % A == 0) {
      return v / A;
    } else {
      return v / A + 1;
    }
  }
}

bool hypergreatfunction(LL i) {
  LL sum = 0;
  REP(j, v.size()) { sum += ultrasuperfunction(v[j] - B * i, A); }
  if (sum <= i) {
    return true;
  } else {
    return false;
  }
}

int main() {
  cin >> N >> A >> B;
  A = A - B;
  REP(i, N) {
    LL a;
    cin >> a;
    v.push_back(a);
  }
  SORT(v);
  LL ans = 0;
  for (LL i = 0; i <= 1000000000; i += 1000000) {
    if (hypergreatfunction(ans + i)) {
      ans += i - 1000000;
      break;
    }
  }
  for (LL i = 0; i <= 1000000; i += 1000) {
    if (hypergreatfunction(ans + i)) {
      ans += i - 1000;
      break;
    }
  }
  for (LL i = 0; i <= 1000; i += 1) {
    if (hypergreatfunction(ans + i)) {
      ans += i - 1;
      break;
    }
  }
  cout << ans + 1 << endl;
}

Fixed submission:
#include <algorithm>
#include <assert.h>
#include <cassert>
#include <ccomplex>
#include <chrono>
#include <clocale>
#include <cmath>
#include <complex>
#include <ctype.h>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <locale>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <utility>
#include <valarray>
#include <vector>
#include <wchar.h>

using namespace std;
typedef long long int LL;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(), (c).end())
#define BACKSORT(c) sort((c).begin(), (c).end(), std::greater<LL>())
#define FOR(i, a, b) for (LL i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

int xcomp(vector<LL> &a, vector<LL> &b) { return a[0] < b[0]; }

#define XSORT(c) sort((c).begin(), (c).end(), xcomp)

#define ALL(x) (x).begin(), (x).end()
LL mod = 1000000007;

LL N, A, B;
vector<LL> v(0);

LL ultrasuperfunction(LL v, LL A) {
  if (v <= 0) {
    return 0;
  } else {
    if (v % A == 0) {
      return v / A;
    } else {
      return v / A + 1;
    }
  }
}

bool hypergreatfunction(LL i) {
  LL sum = 0;
  REP(j, v.size()) { sum += ultrasuperfunction(v[j] - B * i, A); }
  if (sum <= i) {
    return true;
  } else {
    return false;
  }
}

int main() {
  cin >> N >> A >> B;
  A = A - B;
  REP(i, N) {
    LL a;
    cin >> a;
    v.push_back(a);
  }
  SORT(v);
  LL ans = 0;
  for (LL j = 1000000000; j >= 10; j /= 10) {
    for (LL i = 0; i <= j; i += j / 10) {
      if (hypergreatfunction(ans + i)) {
        ans += i - j / 10;
        break;
      }
    }
  }
  cout << ans + 1 << endl;
}