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

#include <bits/stdc++.h>
using namespace std;
#define FOR(i, o, n) for (long long i = o; i < n; i++)
#define oneforall                                                              \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);
#define all(v) (v).begin(), (v).end()
#define ini(...)                                                               \\
  int __VA_ARGS__;                                                             \\
  in(__VA_ARGS__)
#define inl(...)                                                               \\
  long long __VA_ARGS__;                                                       \\
  in(__VA_ARGS__)
#define ins(...)                                                               \\
  string __VA_ARGS__;                                                          \\
  in(__VA_ARGS__)
#define int long long
const long long inf = 1e18;
void in() {}
template <typename T, class... U> void in(T &t, U &...u) {
  cin >> t;
  in(u...);
}
void out() { cout << "\\n"; }
template <typename T, class... U> void out(const T &t, const U &...u) {
  cout << t;
  if (sizeof...(u))
    cout << " ";
  out(u...);
}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long>> vpll;
typedef vector<pair<int, int>> vpii;
#define FORR(x, arr) for (auto &x : arr)
#define ZERO(a) memset(a, 0, sizeof(a))

// 3111111111111111111111111111111

void solve() {

  ini(n);
  ini(n1);
  vi morty(n);
  FOR(i, 0, n) { in(morty[i]); }
  int tourist = *max_element(all(morty));
  int l = 0;
  int r = tourist;
  auto tmp1 = [&](int x) {
    if (x == 0) {
      return 0;
    }
    int x1 = 0;
    FOR(i, 0, n) { x1 += (morty[i] + x - 1) / x - 1; }
    if (x1 <= n1)
      return 1;
    else
      return 0;
  };
  while (l <= r) {
    int tmp = l + (r - l) / 2;
    if (tmp1(tmp))
      r = tmp - 1;
    else
      l = tmp + 1;
  }
  if (l > tourist)
    l = n1;
  out(l);
}

int32_t main() {
  oneforall oneforall oneforall oneforall oneforall oneforall oneforall
      oneforall oneforall oneforall oneforall oneforall oneforall oneforall

      solve();

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define FOR(i, o, n) for (long long i = o; i < n; i++)
#define oneforall                                                              \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);
#define all(v) (v).begin(), (v).end()
#define ini(...)                                                               \\
  int __VA_ARGS__;                                                             \\
  in(__VA_ARGS__)
#define inl(...)                                                               \\
  long long __VA_ARGS__;                                                       \\
  in(__VA_ARGS__)
#define ins(...)                                                               \\
  string __VA_ARGS__;                                                          \\
  in(__VA_ARGS__)
#define int long long
const long long inf = 1e18;
void in() {}
template <typename T, class... U> void in(T &t, U &...u) {
  cin >> t;
  in(u...);
}
void out() { cout << "\\n"; }
template <typename T, class... U> void out(const T &t, const U &...u) {
  cout << t;
  if (sizeof...(u))
    cout << " ";
  out(u...);
}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long>> vpll;
typedef vector<pair<int, int>> vpii;
#define FORR(x, arr) for (auto &x : arr)
#define ZERO(a) memset(a, 0, sizeof(a))

// 3111111111111111111111111111111

void solve() {

  ini(n);
  ini(n1);
  vi morty(n);
  FOR(i, 0, n) { in(morty[i]); }
  int tourist = *max_element(all(morty));
  int l = 0;
  int r = tourist;
  auto tmp1 = [&](int x) {
    int x1 = 0;
    FOR(i, 0, n) { x1 += (morty[i] + x - 1) / x - 1; }
    if (x1 <= n1)
      return 1;
    else
      return 0;
  };
  while (l <= r) {
    int tmp = l + (r - l) / 2;
    // out(tmp);
    if (tmp1(tmp))
      r = tmp - 1;
    else
      l = tmp + 1;
    // out(l,r);
  }
  if (l > tourist)
    l = n1;
  out(l);
}

int32_t main() {
  oneforall oneforall oneforall oneforall oneforall oneforall oneforall
      oneforall oneforall oneforall oneforall oneforall oneforall oneforall

      solve();

  return 0;
}