Problem p02598 (C++)

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPr(i, n) for (int i = (n)-1; i >= 0; --i)
#define FORq(i, m, n) for (int i = (m); i <= (n); ++i)
#define FORqr(i, m, n) for (int i = (n); i >= (m); --i)
#define MP make_pair
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x, 0, sizeof(x))
#define FILL(x, y) memset(x, y, sizeof(x))
#define MM(x) memset(x, -1, sizeof(x))
#define ALL(x) (x).begin(), (x).end()
#define DB(x) cerr << #x << " = " << x << endl
#define DB2(x, y)                                                              \
  cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define DEBUG                                                                  \
  int x12345;                                                                  \
  cin >> x12345;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
const long long MOD = 1e9 + 7;
///////////////////////////////////////////////
// for template
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
///////////////////////////////////////////////
/// 🍈( '-' 🍈 |AC|
vector<ll> A(200002);
ll N, K;

bool check(ll value) {
  ll count = 0;
  REP(i, N) { count += ((A[i] + value - 1) / value) - 1; }

  if (count <= K)
    return true;
  else
    return false;
}

ll binary_search(ll key) {
  // lower_bound (a-1,b] (ans = [a,b])
  // <= left never satisfy
  // right <= always satisfy

  ll left = -1;
  ll right = 2 * 1e9 + 1; // index of size + 1;

  while (right - left > 1) {
    ll mid = left + (right - left) / 2;

    if (check(mid))
      right = mid;
    else
      left = mid;
  }

  // left is the maximum that don't satisfy the condition.
  // right is the minimum that satisfies the condtion.

  return right;
}

int main() {
  cin >> N >> K;
  REP(i, N) { cin >> A[i]; }

  ll ans = binary_search(100);
  cout << ans << endl;
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPr(i, n) for (int i = (n)-1; i >= 0; --i)
#define FORq(i, m, n) for (int i = (m); i <= (n); ++i)
#define FORqr(i, m, n) for (int i = (n); i >= (m); --i)
#define MP make_pair
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x, 0, sizeof(x))
#define FILL(x, y) memset(x, y, sizeof(x))
#define MM(x) memset(x, -1, sizeof(x))
#define ALL(x) (x).begin(), (x).end()
#define DB(x) cerr << #x << " = " << x << endl
#define DB2(x, y)                                                              \
  cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define DEBUG                                                                  \
  int x12345;                                                                  \
  cin >> x12345;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
const long long MOD = 1e9 + 7;
///////////////////////////////////////////////
// for template
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
///////////////////////////////////////////////
/// 🍈( '-' 🍈 |AC|
vector<ll> A(200002);
ll N, K;

bool check(ll value) {
  ll count = 0;
  REP(i, N) { count += ((A[i] + value - 1) / value) - 1; }

  if (count <= K)
    return true;
  else
    return false;
}

ll binary_search(ll key) {
  // lower_bound (a-1,b] (ans = [a,b])
  // <= left never satisfy
  // right <= always satisfy

  ll left = 0;
  ll right = 1e9 + 1; // index of size + 1;

  while (right - left > 1) {
    ll mid = left + (right - left) / 2;

    if (check(mid))
      right = mid;
    else
      left = mid;
  }

  // left is the maximum that don't satisfy the condition.
  // right is the minimum that satisfies the condtion.

  return right;
}

int main() {
  cin >> N >> K;
  REP(i, N) { cin >> A[i]; }

  ll ans = binary_search(100);
  cout << ans << endl;
}