Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define int long long
#define ld long double
#define fi first
#define se second
#define vll vector<int>
#define pii pair<int, int>
#define vvll vector<vector<int>>
#define pb push_back
#define sz(v) (int)(v).size()
#define inf 1e10
#define md 1000000007
#define all(v) (v).begin(), (v).end()
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define tel(a)                                                                 \\
  { cout << a << "\\n"; }
#define tell(a, b)                                                             \\
  { cout << a << " | " << b << "\\n"; }
#define telll(a, b, c)                                                         \\
  { cout << a << " | " << b << " | " << c << "\\n"; }
#define teln(v, n)                                                             \\
  {                                                                            \\
    cout << "v- ";                                                             \\
    rep(o, 0, n) cout << v[o] << " ";                                          \\
    cout << "\\n";                                                              \\
  }
#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
using namespace std;

#define M 2010

int32_t main() {
  IOS;

  int n, k;
  cin >> n >> k;
  int a[n];
  rep(i, 0, n) cin >> a[i];
  int lo = 1, hi = inf, mid, ans;
  while (lo <= hi) {
    mid = (lo + hi) >> 1;
    int cnt = 0;
    rep(i, 0, n) cnt += (a[i] - 1) / mid;
    if (cnt <= k)
      hi = mid - 1, ans = mid;
    else
      lo = mid + 1;
  }
  cout << ans;

  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define int long long
#define ld long double
#define fi first
#define se second
#define vll vector<int>
#define pii pair<int, int>
#define vvll vector<vector<int>>
#define pb push_back
#define sz(v) (int)(v).size()
#define inf 1e10
#define md 1000000007
#define all(v) (v).begin(), (v).end()
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define tel(a)                                                                 \\
  { cout << a << "\\n"; }
#define tell(a, b)                                                             \\
  { cout << a << " | " << b << "\\n"; }
#define telll(a, b, c)                                                         \\
  { cout << a << " | " << b << " | " << c << "\\n"; }
#define teln(v, n)                                                             \\
  {                                                                            \\
    cout << "v- ";                                                             \\
    rep(o, 0, n) cout << v[o] << " ";                                          \\
    cout << "\\n";                                                              \\
  }
#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
using namespace std;

#define M 2010

int32_t main() {
  IOS;

  int n, k;
  cin >> n >> k;
  int a[n];
  rep(i, 0, n) cin >> a[i];
  int lo = 0, hi = inf, mid, ans;
  while (lo <= hi) {
    mid = (lo + hi) >> 1;
    int cnt = 0;
    rep(i, 0, n) cnt += (a[i] - 1) / mid;
    if (cnt <= k)
      hi = mid - 1, ans = mid;
    else
      lo = mid + 1;
  }
  cout << ans;

  return 0;
}