alexjercan/bugnet huggingface dataset:
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;
typedef tuple<long long, long long, long long> tllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint &arg1, const pint &arg2) {
  return arg1.first > arg2.first;
}
bool compTuple(const tllint &arg1, const tllint &arg2) {
  return get<2>(arg1) > get<2>(arg2);
}
template <class T> void chmax(T &a, T b) {
  if (a < b) {
    a = b;
  }
}
template <class T> void chmin(T &a, T b) {
  if (a > b) {
    a = b;
  }
}

int main(void) {
  int n, k;
  cin >> n >> k;

  vector<int> a(n);
  int max = 0;
  for (int in = 0; in < n; in++) {
    cin >> a[in];
    if (max < a[in])
      max = a[in];
  }

  int l = 1, r = max, mid, ans = max, ktmp, times;
  while (l < r) {
    mid = l + (r - l) / 2;

    ktmp = 0;
    for (int in = 0; in < n; in++) {
      times = a[in] / mid;
      if (a[in] % mid != 0)
        times++;
      times--;
      ktmp += times;
    }
    if (ktmp <= k) {
      ans = min(ans, mid);
      r = mid;
    } else
      l = mid + 1;
  }

  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;
typedef tuple<long long, long long, long long> tllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint &arg1, const pint &arg2) {
  return arg1.first > arg2.first;
}
bool compTuple(const tllint &arg1, const tllint &arg2) {
  return get<2>(arg1) > get<2>(arg2);
}
template <class T> void chmax(T &a, T b) {
  if (a < b) {
    a = b;
  }
}
template <class T> void chmin(T &a, T b) {
  if (a > b) {
    a = b;
  }
}

int main(void) {
  int n, k;
  cin >> n >> k;

  vector<int> a(n);
  int max = 0;
  for (int in = 0; in < n; in++) {
    cin >> a[in];
    if (max < a[in])
      max = a[in];
  }

  int l = 0, r = max, mid, ans = max, ktmp, times;
  while (l < r) {
    mid = l + (r - l) / 2;

    ktmp = 0;
    for (int in = 0; in < n; in++) {
      times = a[in] / mid;
      if (a[in] % mid != 0)
        times++;
      times--;
      ktmp += times;
    }
    if (ktmp <= k) {
      ans = min(ans, mid);
      r = mid;
    } else
      l = mid + 1;
  }

  cout << ans << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

#define N 1000000007

using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  ll k;
  cin >> n >> k;
  vector<ll> a(n);
  ll sum = 0;
  ll max_a = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
    max_a = max(max_a, a[i]);
  }
  ll bound_max = max_a;
  ll bound_min = sum / (n + k);
  ll cur = (bound_max + bound_min) / 2;

  while (true) {
    if (bound_min + 1 >= bound_max)
      break;
    ll ncut = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] <= cur)
        continue;
      ll m = a[i] / cur + (a[i] % cur ? 1 : 0);
      ncut += m - 1;
    }
    if (ncut <= k) {
      bound_max = cur;
    } else {
      bound_min = cur;
    }
    cur = (bound_max + bound_min) / 2;
  }
  cout << bound_max << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

#define N 1000000007

using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  ll k;
  cin >> n >> k;
  vector<ll> a(n);
  ll sum = 0;
  ll max_a = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
    max_a = max(max_a, a[i]);
  }
  ll bound_max = max_a;
  ll bound_min = sum / (n + k);
  ll cur = (bound_max + bound_min) / 2;

  while (true) {
    if (bound_max - bound_min == 1)
      break;
    ll ncut = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] <= cur)
        continue;
      ll m = a[i] / cur + (a[i] % cur ? 1 : 0);
      ncut += m - 1;
    }
    if (ncut <= k) {
      bound_max = cur;
    } else {
      bound_min = cur;
    }
    cur = (bound_max + bound_min) / 2;
  }
  cout << bound_max << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
using namespace std;

#define LL long long

const int MAXN = 2000000 + 5;

int a[MAXN];

bool ok(int N, int v, int K) {
  int i;
  for (i = 0; i < N; i++) {
    if (a[i] > v) {
      int t = a[i] / v;
      if (a[i] % v > 0) {
        t++;
      }
      K -= t - 1;
      if (K < 0) {
        return false;
      }
    }
  }
  return true;
}

int solve(int N, int high, int K) {
  int low, mid;
  int i, ret = high;
  low = 1;
  while (low <= high) {
    mid = (low + high) / 2;
    if (ok(N, mid, K)) {
      ret = mid;
      high = mid - 1;
    } else {
      low = mid + 1;
    }
  }
  return ret;
}

int main() {
  int N, i, j, K, high;
  cin >> N >> K;
  high = 0;
  for (i = 0; i < N; i++) {
    cin >> a[i];
    if (a[i] > high) {
      high = a[i];
    }
  }
  cout << solve(N, high, K);
  system("pause");
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
using namespace std;

#define LL long long

const int MAXN = 2000000 + 5;

int a[MAXN];

bool ok(int N, int v, int K) {
  int i;
  for (i = 0; i < N; i++) {
    if (a[i] > v) {
      int t = a[i] / v;
      if (a[i] % v > 0) {
        t++;
      }
      K -= t - 1;
      if (K < 0) {
        return false;
      }
    }
  }
  return true;
}

int solve(int N, int upbound, int K) {
  int low, high, mid;
  int i, ret = upbound;
  low = 0;
  high = upbound;
  for (i = 0; i < 100; i++) {
    mid = (low + high) / 2;
    if (ok(N, mid, K)) {
      ret = mid;
      high = mid - 1;
    } else {
      low = mid + 1;
    }
  }
  return ret;
}

int main() {
  int N, i, j, K, maxa;
  cin >> N >> K;
  maxa = 0;
  for (i = 0; i < N; i++) {
    cin >> a[i];
    if (a[i] > maxa) {
      maxa = a[i];
    }
  }
  cout << solve(N, maxa, K);
  system("pause");
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <climits>
#include <cmath>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;
typedef long long ll;

ll N, K;
ll A[200200];

bool IsCuttable(ll len) {
  ll count = 0;
  for (int i = 0; i < N; i++) {
    ll count_ = A[i] / len;
    if (A[i] % len != 0 && A[i] > len) {
      count_++;
    }
    if (count_ > 0) {
      count_--;
    }
    count += count_;
  }
  if (count <= K) {
    return true;
  } else {
    return false;
  }
}

int main() {
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  ll min = 1;
  ll max = 1000000000;
  while (max - min > 0) {
    ll mid = min + (max - min) / 2;
    // cout << mid << endl;
    if (IsCuttable(mid)) {
      max = mid;
    } else {
      min = mid + 1;
    }
  }
  cout << min << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <climits>
#include <cmath>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;
typedef long long ll;

ll N, K;
ll A[200200];

bool IsCuttable(ll len) {
  ll count = 0;
  for (int i = 0; i < N; i++) {
    ll count_ = A[i] / len;
    if (A[i] % len != 0 && A[i] > len) {
      count_++;
    }
    if (count_ > 0) {
      count_--;
    }
    count += count_;
  }
  if (count <= K) {
    return true;
  } else {
    return false;
  }
}

int main() {
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  ll min = 0;
  ll max = 1000000000;
  while (max - min > 0) {
    ll mid = min + (max - min) / 2;
    // cout << mid << endl;
    if (IsCuttable(mid)) {
      max = mid;
    } else {
      min = mid + 1;
    }
  }
  cout << min << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

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

typedef long long ll;
int n, k;
vector<ll> v;
int min1 = 1e9;
ll func(ll key) {
  ll k = 0;
  for (int i = 0; i < n; i++) {
    k += ceil((double)v[i] / key) - 1;
  }
  return k;
}

ll binary_search() {
  ll left = 0;
  ll right = 1e9;
  while (right - left > 1) {
    ll mid = (left + right) >> 1;
    if (func(mid) <= k)
      right = mid;
    else
      left = mid;
  }
  return right;
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    ll tmp;
    scanf("%lld", &tmp);
    v.push_back(tmp);
  }
  cout << binary_search() << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int n, k;

int func(double n) {
  if (n - (int)n > 0) {
    return (int)n + 1;
  }
  return (int)n;
}
struct Node {
  int parent;
  int cut;
  double val;
};
struct compare1 {
  bool operator()(Node node1, Node node2) { return node1.val < node2.val; }
};
Node node[200010];
vector<int> res;
int max1 = -1;
int main() {
  cin >> n >> k;
  priority_queue<Node, vector<Node>, compare1> q;
  for (int i = 0; i < n; i++) {
    cin >> node[i].parent;
    max1 = max(max1, node[i].parent);
    node[i].cut = 1;
    node[i].val = node[i].parent;
    q.push(node[i]);
  }
  if (k == 0) {
    cout << max1 << endl;
    return 0;
  }
  if (k == 1) {
    cout << (int)ceil((double)max1 / 2) << endl;
    return 0;
  }
  int cnt = 0;
  while (cnt < k) {
    Node tmp1 = q.top();
    q.pop();
    double value = 0;
    value = (double)tmp1.parent / (tmp1.cut + 1);
    Node tmp2;
    tmp2.val = value;
    tmp2.parent = tmp1.parent;
    tmp2.cut = tmp1.cut + 1;
    q.push(tmp2);
    cnt++;
  }
  cout << (int)ceil(q.top().val) << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int mod = (1 ? 1e9 + 7 : 998244353);
const int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
ll a, b, c, d, e, f, n, T;

double z[200005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> a >> b;
  double maxx = 0;
  for (int i = 0; i < a; i++)
    cin >> z[i], maxx = max(maxx, z[i]);
  double minn = 0;
  double mid;
  while (maxx - minn > 1e-6) {
    mid = (maxx + minn) / 2;
    c = 0;
    for (int i = 0; i < a; i++)
      c += ceil(z[i] / mid - 1);
    if (c > b)
      minn = mid;
    else
      maxx = mid;
  }
  cout << (ll)ceil(maxx) << endl;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int mod = (1 ? 1e9 + 7 : 998244353);
const int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
ll a, b, c, d, e, f, n, T;

double z[200005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> a >> b;
  double maxx = 0;
  for (int i = 0; i < a; i++)
    cin >> z[i], maxx = max(maxx, z[i]);
  double minn = 0;
  double mid;
  while (maxx - minn > 1e-7) {
    mid = (maxx + minn) / 2;
    c = 0;
    for (int i = 0; i < a; i++)
      c += ceil(z[i] / mid - 1);
    if (c > b)
      minn = mid;
    else
      maxx = mid;
  }
  cout << (ll)ceil(maxx) << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
#define MOD 1000000007

int main() {
  int n, k;
  cin >> n >> k;
  vll a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  ll ng = 0, ok = 1e10, mid;
  ll cnt;
  while (abs(ok - ng) > 1) {
    mid = (ok + ng) / 2;
    cnt = 0;
    for (int i = 0; i < n; i++) {
      cnt += (a[i] + mid - 1) / mid;
      cnt--;
    }
    if (cnt <= k)
      ok = mid;
    else
      ng = mid;
  }
  cout << ok << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
#define MOD 1000000007

int main() {
  int n, k;
  cin >> n >> k;
  vll a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  ll ng = -1, ok = 1e10, mid;
  ll cnt;
  while (abs(ok - ng) > 1) {
    mid = (ok + ng) / 2;
    cnt = 0;
    for (int i = 0; i < n; i++) {
      cnt += (a[i] + mid - 1) / mid;
      cnt--;
    }
    if (cnt <= k)
      ok = mid;
    else
      ng = mid;
  }
  cout << ok << endl;

  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
struct fastio {
  fastio() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
  }
} _fast_io_;
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

constexpr long long INF = (1 << 30);

int main() {
  std::size_t n;
  long long k;
  std::cin >> n >> k;
  std::vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    std::cin >> a[i];
  }

  auto f = [&](long long x) -> bool {
    long long cnt = 0;
    for (const int &e : a) {
      if (e <= x)
        continue;
      cnt += e / x;
    }
    return (cnt <= k);
  };

  long long ng = 0, ok = INF;
  while (std::abs(ok - ng) > 1) {
    long long mid = (ok + ng) >> 1;
    if (f(mid))
      ok = mid;
    else
      ng = mid;
  }

  std::cout << ok << '\\n';

  return 0;
}

Error: -8

Fixed submission:

#include <bits/stdc++.h>
struct fastio {
  fastio() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
  }
} _fast_io_;
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

using data = std::tuple<long long, long long>;

int main() {
  int n;
  long long k;
  std::cin >> n >> k;
  std::vector<long long> a(n);
  for (auto &e : a)
    std::cin >> e;

  std::priority_queue<data> que;
  for (auto &e : a)
    que.emplace(e, 1);
  que.emplace(0, 0);

  while (k) {
    auto [val, cnt] = que.top();
    if (cnt <= k) {
      que.pop();
      auto [next, _bag] = que.top();
      long long c = 0;
      while ((next << 1) < val and (c + 1) * cnt <= k) {
        next <<= 1;
        c++;
      }
      k -= (c * cnt);
      val /= c;
      que.emplace(val, cnt * (c + 1));
    } else {
      break;
    }
  }

  auto [val, cnt] = que.top();
  que.pop();
  std::cout << val << '\\n';
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

vector<ll> A;
ll N, K;
ll maxA;

bool isOK(ll len) {
  ll res = 0LL;
  if (len == 0)
    return false;
  for (ll a : A) {
    res += ((a % len == 0) ? a / len - 1 : a / len);
  }
  // cout << "len: " << len << "\\t" << ((res<=K) ? "ok" : "ng") << endl;
  return res <= K;
}

ll binary_search() {
  ll ng = 0LL;
  ll ok = maxA + 1;

  while (abs(ok - ng) > 1) {
    ll mid = (ok + ng) / 2;

    if (isOK(mid))
      ok = mid;
    else
      ng = mid;
  }

  return ok;
}

int main() {
  cin >> N >> K;

  A = vector<ll>(N);
  maxA = 0LL;
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    maxA = max(maxA, A.at(i));
  }

  ll res = binary_search();

  cout << res << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
using P = pair<int, int>;

vector<int> A;
int N, K;
int maxA;

bool isOK(int len) {
  int res = 0;
  for (int a : A) {
    res += ((a % len == 0) ? a / len - 1 : a / len);
  }
  // cout << "len: " << len << "\\t" << ((res<=K) ? "ok" : "ng") << endl;
  return res <= K;
}

int binary_search() {
  int ng = -1;
  int ok = maxA;

  while (abs(ok - ng) > 1) {
    int mid = (ok + ng) / 2;

    if (isOK(mid))
      ok = mid;
    else
      ng = mid;
  }

  return ok;
}

int main() {
  cin >> N >> K;

  A = vector<int>(N);
  maxA = 0;
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    maxA = max(maxA, A.at(i));
  }

  int res = binary_search();

  cout << res << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64, i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

int n, k, a[202020];
int dp[202020];
void solve() {
  cin >> n >> k;
  i64 sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  sort(a, a + n);

  int l = 0, r = a[n - 1];
  while (r - l > 1) {
    int c = (l + r) / 2;
    int cnt = 0;
    int ma = 0;
    for (int i = 0; i < n; i++) {
      cnt += (a[i] + c - 1) / c - 1;
    }
    if (cnt <= k) {
      r = c;
    } else {
      l = c;
    }
  }
  cout << r << endl;
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  int t = 1;
  // cin >> t;
  while (t--) {
    solve();
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64, i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

int n, k, a[202020];
void solve() {
  cin >> n >> k;
  priority_queue<pair<int, P>> pq;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    pq.push({a[i], {a[i], 1}});
  }

  for (int i = 0; i < k; i++) {
    auto p = pq.top();
    pq.pop();
    int x = p.first, y = p.second.first, z = p.second.second;
    pq.push({(y + z) / (z + 1), {y, z + 1}});
  }
  cout << pq.top().first << endl;
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  int t = 1;
  // cin >> t;
  while (t--) {
    solve();
  }

  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <iomanip>
#define fast                                                                   \\
  {                                                                            \\
    ios_base::sync_with_stdio(false);                                          \\
    cin.tie(NULL);                                                             \\
  }
#define mxn 1000005
#define mod 1000000007
#define ld long double
#define pb push_back
#define inf 1e18
#define fi first
#define se second
typedef long long int ll;
using namespace std;
int main(void) {
  fast;
  ll n, k, i, ma = -inf;
  cin >> n >> k;
  ll a[n];
  for (i = 0; i < n; i++) {
    cin >> a[i];
    ma = max(ma, a[i]);
  }
  ll lo = 0, hi = ma;
  while (lo < hi) {
    ll mid = (lo + hi) / 2;
    ll c = 0;
    if (mid == 0LL)
      break;
    for (i = 0; i < n; i++)
      c += (a[i] - 1) / mid;
    if (c > k)
      lo = mid + 1;
    else
      hi = mid;
  }
  cout << max(lo, 1LL);
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#include <iomanip>
#define fast                                                                   \\
  {                                                                            \\
    ios_base::sync_with_stdio(false);                                          \\
    cin.tie(NULL);                                                             \\
  }
#define mxn 1000005
#define mod 1000000007
#define ld long double
#define pb push_back
#define inf 1e18
#define fi first
#define se second
typedef long long int ll;
using namespace std;
int main(void) {
  fast;
  ll n, k, i, ma = -inf;
  cin >> n >> k;
  ll a[n];
  for (i = 0; i < n; i++) {
    cin >> a[i];
    ma = max(ma, a[i]);
  }
  ll lo = 0, hi = ma;
  while (lo < hi) {
    ll mid = (lo + hi) / 2;
    ll c = 0;
    for (i = 0; i < n; i++)
      c += (a[i] - 1) / mid;
    if (c > k)
      lo = mid + 1;
    else
      hi = mid;
  }
  cout << lo;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<ll, ll>;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
ll bpow(ll b, ll p, ll m = 1000000007LL) {
  ll rt = 1;
  for (; p; p >>= 1, b = b * b % m)
    if (p & 1)
      rt = rt * b % m;
  return rt;
}
ll n, k;
ll a[200005];
bool check(ll mi) {
  ll cnt = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] > mi)
      cnt += a[i] / mi;
  }
  return cnt <= k;
}
int main() {
  IOS;
  cin >> n >> k;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  ll lo = 1, hi = 1000000000;
  while (lo <= hi) {
    ll mi = lo + hi >> 1;
    if (check(mi))
      hi = mi - 1;
    else
      lo = mi + 1;
  }
  cout << lo << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<ll, ll>;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
ll bpow(ll b, ll p, ll m = 1000000007LL) {
  ll rt = 1;
  for (; p; p >>= 1, b = b * b % m)
    if (p & 1)
      rt = rt * b % m;
  return rt;
}
ll n, k;
ll a[200005];
bool check(ll mi) {
  ll cnt = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] > mi)
      cnt += a[i] / mi;
  }
  return cnt <= k;
}
int main() {
  IOS;
  cin >> n >> k;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  ll lo = 0, hi = 1000000000;
  while (lo <= hi) {
    ll mi = lo + hi >> 1;
    if (check(mi))
      hi = mi - 1;
    else
      lo = mi + 1;
  }
  cout << lo << endl;
}