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

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set                                                            \\
  tree<int, null_type, less<int>, rb_tree_tag,                                 \\
       tree_order_statistics_node_update>

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  long long int k;
  cin >> n >> k;
  long long int a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  long long int l = 1;
  long long int r = 1e9;
  while (l < r) {
    long long int m = (l + r) / 2;
    long long int cnt = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] > m) {
        cnt += (a[i] - 1) / m;
      }
    }
    if (cnt <= k)
      r = m;
    else
      l = m + 1;
  }
  cout << l << "\\n";
  return 0;
}

Error: 0

Fixed submission:

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set                                                            \\
  tree<int, null_type, less<int>, rb_tree_tag,                                 \\
       tree_order_statistics_node_update>

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  long long int k;
  cin >> n >> k;
  long long int a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  long long int l = 0;
  long long int r = 1e9;
  while (l < r) {
    long long int m = (l + r) / 2;
    long long int cnt = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] > m) {
        cnt += (a[i] - 1) / m;
      }
    }
    if (cnt <= k)
      r = m;
    else
      l = m + 1;
  }
  cout << l << "\\n";
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

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

ll n, k, a;
vector<ll> V;

bool solve(ll z) {
  ll cnt = 0;
  for (auto e : V) {
    cnt += ((e - 1) / z);
  }
  if (cnt <= k)
    return true;
  return false;
}

int main() {
  ll lo = 1, hi = 1000000001, mid;
  cin >> n >> k;
  for (ll i = 0; i < n; i++) {
    cin >> a;
    V.push_back(a);
  }

  while (lo < hi) {
    mid = (lo + hi) / 2;
    if (!solve(mid)) {
      lo = mid + 1;
    } else {
      hi = mid;
    }
  }

  if (solve(lo)) {
    cout << lo;
  } else {
    cout << lo + 1;
  }
  //    cout << lo << endl;
}


Error: 0

Fixed submission:

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

ll n, k, a;
vector<ll> V;

bool solve(ll z) {
  ll cnt = 0;
  for (auto e : V) {
    cnt += ((e - 1) / z);
  }
  if (cnt <= k)
    return true;
  return false;
}

int main() {
  ll lo = 0, hi = 1000000001, mid;
  cin >> n >> k;
  for (ll i = 0; i < n; i++) {
    cin >> a;
    V.push_back(a);
  }

  while (lo < hi) {
    mid = (lo + hi) / 2;
    if (!solve(mid)) {
      lo = mid + 1;
    } else {
      hi = mid;
    }
  }

  cout << lo << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
// #define int long long int
using namespace std;
typedef long long int ll;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N, k;
  cin >> N >> k;
  vector<int> v;

  for (int i = 0; i < N; i++) {
    ll t;
    cin >> t;
    v.push_back(t);
  }
  ll min = 0;
  ll max = 1000000000;
  int ans = -1;
  while (max >= min) {
    ll mid = (min + max) / 2;
    ll cnt = 0;
    if (mid == 0) {
      ans = 1;
      break;
    }
    for (auto i : v) {
      if (i == mid)
        continue;
      cnt += i / mid;
    }
    if (cnt <= k) {
      max = mid - 1;
      int check = 0;
      if (max == 0) {
        ans = max + 1;
        break;
      }
      for (auto i : v) {
        if (i == max)
          continue;
        check += i / max;
      }
      if (check > k) {
        ans = max + 1;
        break;
      }
    } else {
      min = mid + 1;
    }
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
// #define int long long int
using namespace std;
typedef long long int ll;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N, k;
  cin >> N >> k;
  vector<int> v;

  for (int i = 0; i < N; i++) {
    ll t;
    cin >> t;
    v.push_back(t);
  }
  ll min = 0;
  ll max = 1000000000;
  int ans = -1;
  while (max >= min) {
    ll mid = (min + max) / 2;
    int cnt = 0;
    for (auto i : v) {
      if (i == mid)
        continue;
      cnt += i / mid;
    }
    if (cnt <= k) {
      max = mid - 1;
      int check = 0;
      for (auto i : v) {
        if (i == max)
          continue;
        check += i / max;
      }
      if (check > k) {
        ans = max + 1;
        break;
      }
    } else {
      min = mid + 1;
    }
  }
  cout << ans << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
const int maxn = 1e6 + 5;

int n, k;
int a[maxn];

bool check(int mid) {
  int num = 0;
  for (int i = 1; i <= n; i++) {
    num += a[i] / mid + (a[i] % mid != 0) - 1;
    if (num > k)
      return false;
  }
  return true;
}

int main() {
  int l = 1, r, mid;
  r = 0;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    r = max(r, a[i]);
  }
  while (l < r) {
    mid = l + r >> 1;
    if (check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  printf("%d\\n", l);
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
const int maxn = 1e6 + 5;

int n, k;
int a[maxn];

bool check(int mid) {
  int num = 0;
  for (int i = 1; i <= n; i++) {
    num += a[i] / mid + (a[i] % mid != 0) - 1;
    if (num > k)
      return false;
  }
  return true;
}

int main() {
  int l = 0, r, mid;
  r = 0;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    r = max(r, a[i]);
  }
  while (l < r) {
    mid = l + r >> 1;
    if (check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  printf("%d\\n", l);
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;
using ll = long long int;
using dd = long double;
int main() {
  ll N, K;
  cin >> N >> K;

  vector<ll> log(N);
  for (ll i = 0; i < N; i++) {
    cin >> log[i];
  }
  ll l = 1;
  ll r = 1e9;

  while ((r - l) > 1) {
    ll mid = (l + r) / 2;
    ll sum = 0;
    for (ll i = 0; i < N; i++) {
      if (log[i] <= mid) {
        continue;
      }
      sum += (log[i] / mid) + (log[i] % mid == 0 ? -1 : 0);
    }
    if (sum > K) {
      l = mid + 1;
    } else {
      r = mid;
    }
  }
  ll l_sum = 0;
  for (ll i = 0; i < N; i++) {
    if (log[i] <= l) {
      continue;
    }
    l_sum += (log[i] / l) + (log[i] % l == 0 ? -1 : 0);
  }

  if (l_sum <= K) {
    cout << l << endl;
  } else {
    cout << r << endl;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;
using ll = long long int;
using dd = long double;
int main() {
  ll N, K;
  cin >> N >> K;

  vector<ll> log(N);
  for (ll i = 0; i < N; i++) {
    cin >> log[i];
  }
  ll l = 0;
  ll r = 1e9;

  while ((r - l) > 1) {
    ll mid = (l + r) / 2;
    ll sum = 0;
    for (ll i = 0; i < N; i++) {
      if (log[i] <= mid) {
        continue;
      }
      sum += (log[i] / mid) + (log[i] % mid == 0 ? -1 : 0);
    }
    if (sum > K) {
      l = mid + 1;
    } else {
      r = mid;
    }
  }
  ll l_sum = 0;
  for (ll i = 0; i < N; i++) {
    if (log[i] <= l) {
      continue;
    }
    l_sum += (log[i] / l) + (log[i] % l == 0 ? -1 : 0);
  }

  if (l_sum <= K) {
    cout << l << endl;
  } else {
    cout << r << endl;
  }
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error


// E - Logs

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int N, K;
ll A[200000];

// 長さt以下にできるかどうか
bool is_ok(ll t) {
  if (t == 0)
    return false;

  ll cnt = 0;
  for (int i = 0; i < N; i++) {
    cnt += (A[i] - 1) / t; // 切る回数
  }

  return cnt <= K;
}

ll find_min_ok(ll lower, ll upper) {
  if (!is_ok(upper - 1))
    return -1; // 存在しない

  ll ok = upper - 1;
  ll ng = lower - 1;

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

    if (is_ok(trying)) {
      ok = trying;
    } else {
      ng = trying;
    }
  }

  return ok;
}

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

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

  ll ans = find_min_ok(0, 1e9 + 1);

  cout << ans << endl;

  return 0;
}

Error: 0

Fixed submission:


// E - Logs

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int N, K;
ll A[200000];

// 長さt以下にできるかどうか
bool is_ok(ll t) {
  ll cnt = 0;
  for (int i = 0; i < N; i++) {
    cnt += (A[i] - 1) / t; // 切る回数
  }

  return cnt <= K;
}

ll find_min_ok(ll lower, ll upper) {
  if (!is_ok(upper - 1))
    return -1; // 存在しない

  ll ok = upper - 1;
  ll ng = lower - 1;

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

    if (is_ok(trying)) {
      ok = trying;
    } else {
      ng = trying;
    }
  }

  return ok;
}

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

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

  ll ans = find_min_ok(0, 1e9 + 1);

  cout << ans << endl;

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

// g++  7.4.0

#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);

  int n, k;
  cin >> n >> k;
  vector<int> ar(n);
  for (int &i : ar)
    cin >> i;

  int l = 0;
  int h = *max_element(ar.begin(), ar.end());

  auto fun = [&](int x) { // want the largest length to be x , minimize x
    int cuts = 0;
    for (const int i : ar) {
      if (x >= i)
        continue;
      int rem = i - x;
      cuts++;
      if (rem > x)
        cuts += ((rem + x - 1) / x - 1);
    }
    return cuts <= k;
  };

  while (l + 1 < h) {
    int mid = (l + h) >> 1;
    if (fun(mid))
      h = mid;
    else
      l = mid;
  }
  cout << h << '\\n';

  return 0;
}


Error: 0

Fixed submission:

// g++  7.4.0

#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);

  int n, k;
  cin >> n >> k;
  vector<int> ar(n);
  for (int &i : ar)
    cin >> i;

  int l = -1;
  int h = *max_element(ar.begin(), ar.end());

  auto fun = [&](int x) { // want the largest length to be x , minimize x
    int cuts = 0;
    for (const int i : ar) {
      if (x >= i)
        continue;
      int rem = i - x;
      cuts++;
      if (rem > x)
        cuts += ((rem + x - 1) / x - 1);
    }
    return cuts <= k;
  };

  while (l + 1 < h) {
    int mid = (l + h) >> 1;
    if (fun(mid))
      h = mid;
    else
      l = mid;
  }
  cout << h << '\\n';

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

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

int n, k;
vector<double> a;

bool c(double m) {
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    cnt = cnt + (int)(a[i] / m);
    if (m * (int)(a[i] / m) == a[i]) {
      cnt--;
    }
  }
  return cnt > k;
}

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

  if (k == 0) {
    int ans = 0;
    for (int i = 0; i < n; i++)
      ans = max(ans, (int)a[i]);
    cout << ans << endl;
    return 0;
  }

  double s = 0, t = 1000000002;
  for (int i = 0; i < 1000; i++) {
    double mid = (s + t) / 2.0;

    if (c(mid))
      s = mid;
    else
      t = mid;
  }

  int ans = (int)(s);
  if (s - (double)(int)s)
    ans++;

  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

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

int n, k;
vector<double> a;

bool c(double x) {
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    cnt += a[i] / x;
    if ((int)(a[i] / x) * x == a[i])
      cnt--;
  }
  return cnt <= k;
}

int main() {
  cin >> n >> k;
  a.resize(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];

  double s = 0, t = 1e9;
  for (int i = 0; i < 10000; i++) {
    double mid = (s + t) / 2;
    if (c(mid))
      t = mid;
    else
      s = mid;
  }

  int ans = (int)s + 1;
  if (s - (double)(int)(s) == 0)
    ans--;

  cout << ans << endl;

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

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

#define mx 500008

typedef int ll;

int main() {

  ll n, k;
  cin >> n >> k;
  ll a[n + 7];
  int mn = 0;
  for (int i = 1; i <= n; i++) {

    cin >> a[i];
    mn = max(mn, a[i]);
  }
  ll ans = 0;
  ll lo = 1;
  ll hi = mn;
  while (lo <= hi) {
    ll mid = (lo + (hi - lo) / 2);
    ll tot = 0;
    for (int i = 1; i <= n; i++) {
      int u = a[i];
      if (u > mid)
        tot += (u - 1) / mid;
    }
    // cout<<mid<<" "<<tot<<endl;
    if (tot <= k) {
      ans = mid;
      hi = mid - 1;
    } else
      lo = mid + 1;
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

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

#define mx 500008

#define pii pair<int, int>
#define pi acos(-1.0)
#define pb push_back
#define ss second
#define ff first
typedef int ll;
/// adjacent move
int fx[4] = {0, +1, 0, -1};
int fy[4] = {+1, 0, -1, 0};
/// knight
ll prime[mx];

vector<pii> v[mx];

int main() {
  int t = 1;

  while (t--) {
    ll n, k;
    cin >> n >> k;
    ll a[n + 7];
    int mn = 0;
    for (int i = 1; i <= n; i++) {

      cin >> a[i];
      mn = max(mn, a[i]);
    }
    ll ans = 0;
    ll lo = 0;
    ll hi = mn;
    while (lo <= hi) {
      ll mid = (lo + (hi - lo) / 2);
      ll tot = 0;
      for (int i = 1; i <= n; i++) {
        int u = a[i];
        if (u > mid)
          tot += (u - 1) / mid;
      }
      // cout<<mid<<" "<<tot<<endl;
      if (tot <= k) {
        ans = mid;
        hi = mid - 1;
      } else
        lo = mid + 1;
    }
    cout << ans << endl;
  }
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
using namespace std;

typedef long long ll;
ll mod = 1e9 + 7;
int a[200010];
int n;
int k;
bool check(int x) {
  if (x == 0)
    return false;
  int p = 0;
  for (int i = 0; i < n; i++) {
    p += a[i] / x;
    if (a[i] % x == 0)
      p--;
    if (p > k)
      return false;
  }
  return true;
}

int main() {

  cin >> n >> k;
  for (int i = 0; i < n; i++)
    cin >> a[i];

  int l = 1, r = 1e9;
  int ans;
  while (l <= r) {
    int mid = (l + r) >> 1;
    // cout<<mid<<endl;
    if (check(mid)) {
      ans = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  cout << ans << endl;

  int ab;
  cin >> ab;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
using namespace std;

typedef long long ll;
ll mod = 1e9 + 7;
int a[200010];
int n;
int k;
bool check(int x) {
  int p = 0;
  for (int i = 0; i < n; i++) {
    p += a[i] / x;
    if (a[i] % x == 0)
      p--;
    if (p > k)
      return false;
  }
  return true;
}

int main() {

  cin >> n >> k;
  for (int i = 0; i < n; i++)
    cin >> a[i];

  int l = 0, r = 1e9;
  int ans;
  while (l <= r) {
    int mid = (l + r) >> 1;
    // cout<<mid<<endl;
    if (check(mid)) {
      ans = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  cout << ans << endl;

  int ab;
  cin >> ab;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
using namespace std;
int N_MAX = 200000;
typedef long long ll;
int main() {
  ll n, i, l, r, c, k, t, s = 0;
  ll a[N_MAX];
  cin >> n >> k;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    s += a[i];
  }
  sort(a, a + n, greater<ll>());
  l = max(s / (n + k), (ll)1);
  r = a[0];
  while (l < r) {
    c = (l + r) / 2;
    t = 0;
    for (i = 0; i < n; i++) {
      t += (a[i] + c - 1) / c - 1;
      if (t > k)
        break;
    }
    if (t > k) {
      l = c + 1;
    } else {
      r = c;
    }
  }
  cout << l << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int N_MAX = 200000;
typedef long long ll;
int main() {
  ll n, i, l, r, c, k, t, s = 0;
  ll a[N_MAX];
  cin >> n >> k;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    s += a[i];
  }
  sort(a, a + n, greater<ll>());
  l = s / (n + k);
  r = a[0];
  while (l < r) {
    c = (l + r) / 2;
    t = 0;
    for (i = 0; i < n; i++) {
      t += (a[i] + c - 1) / c - 1;
      if (t > k)
        break;
    }
    if (t > k) {
      l = c + 1;
    } else {
      r = c;
    }
  }
  cout << l << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

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

bool okay(const vector<int> &A, int K, int m) {
  ll cnt = 0;
  for (int i = 0; i < (int)A.size(); ++i) {
    cnt += (A[i] - 1) / m;
  }
  return cnt <= K;
}

void solve() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int &len : A)
    cin >> len;

  ll a = 1, b = 1e9 + 1;
  while (a < b) {
    ll m = (a + b) / 2;
    if (okay(A, K, m)) {
      b = m;
    } else {
      a = m + 1;
    }
  }
  cout << a << "\\n";
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);

  int t = 1;
  while (t--) {
    solve();
  }
}


Error: 0

Fixed submission:

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

bool okay(const vector<int> &A, int K, int m) {
  ll cnt = 0;
  for (int i = 0; i < (int)A.size(); ++i) {
    cnt += (A[i] - 1) / m;
  }
  return cnt <= K;
}

void solve() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int &len : A)
    cin >> len;

  int a = 0, b = (int)1e9 + 1;
  while (a < b) {
    int m = (a + b) / 2;
    if (okay(A, K, m)) {
      b = m;
    } else {
      a = m + 1;
    }
  }
  cout << a << "\\n";
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);

  int t = 1;
  while (t--) {
    solve();
  }
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

// #define _CRT_SECURE_NO_WARNINGS
// #include <bits/stdc++.h>
#include "bits/stdc++.h"

#define rep(i, n) for (long long(i) = 0; (i) < (long long)(n); (i)++)
#define all(x) (x).begin(), (x).end()
#define int long long

#define PI (3.14159265358979323)
#define MOD (1000000007LL)
#define INF (1LL << 60LL)
#define MAX_N (10000001)
#define MAX (1000000000000000000LL)
using namespace std;

signed main() {
  int l = 1, r = 1000000000;
  int n;
  int k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  while (l != r) {
    int m = (l + r) / 2;
    int k2 = 0;
    rep(i, n) {
      int b = a[i];
      k2 += (b / m) - 1;
      if (b % m != 0)
        k2++;
    }
    if (k2 <= k) {
      r = m;
    } else {
      l = m + 1;
    }
  }
  cout << l << endl;
}

Error: 0

Fixed submission:

// #define _CRT_SECURE_NO_WARNINGS
// #include <bits/stdc++.h>
#include "bits/stdc++.h"

#define rep(i, n) for (long long(i) = 0; (i) < (long long)(n); (i)++)
#define all(x) (x).begin(), (x).end()
#define int long long

#define PI (3.14159265358979323)
#define MOD (1000000007LL)
#define INF (1LL << 60LL)
#define MAX_N (10000001)
#define MAX (1000000000000000000LL)
using namespace std;

signed main() {
  int l = 0, r = 1000000000;
  int n;
  int k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  while (l != r) {
    int m = (l + r) / 2;
    int k2 = 0;
    rep(i, n) {
      int b = a[i];
      k2 += (b / m) - 1;
      if (b % m != 0)
        k2++;
    }
    if (k2 <= k) {
      r = m;
    } else {
      l = m + 1;
    }
  }
  cout << l << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

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

long long int Exp(long long int exp_n, long long int exp_e, long long exp_mod);

int main() {
  long long int N, K, Max_A = 0, O;
  priority_queue<long long int> q;
  cin >> N >> K;
  long long int A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    Max_A = max(Max_A, A[i]);
  }
  long long int X, top = Max_A, btm = 0;
  X = (top + btm + 1) / 2;
  while (top != X) {
    O = 0;
    for (int i = 0; i < N; i++) {
      O = O + (A[i] - 1) / X;
    }
    if (O > K) {
      btm = X;
      X = (top + btm + 1) / 2;
    } else {
      top = X;
      X = (top + btm + 1) / 2;
    }
  }

  cout << X << endl;

  return 0;
}

long long int Exp(long long int exp_n, long long int exp_e,
                  long long int exp_mod) {
  long long int exp_o = 1;
  long long int exp_x = exp_n;
  long long int exp_tmp;

  while (0 < exp_e) {
    exp_tmp = exp_e / 2;
    if (exp_e - exp_tmp * 2 == 1) {
      exp_o = exp_o * exp_x;
      if (exp_o > exp_mod) {
        exp_o = exp_o % exp_mod;
      }
    }

    exp_x = exp_x * exp_x;
    if (exp_x > exp_mod) {
      exp_x = exp_x % exp_mod;
    }
    exp_e = exp_tmp;
  }
  return exp_o;
}


Error: 0

Fixed submission:

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

long long int Exp(long long int exp_n, long long int exp_e, long long exp_mod);

int main() {
  long long int N, K, Max_A = 0, O;
  priority_queue<long long int> q;
  cin >> N >> K;
  long long int A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    Max_A = max(Max_A, A[i]);
  }
  long long int X, top = Max_A, btm = 0;
  X = (top + btm) / 2;
  while (top != X) {
    O = 0;
    for (int i = 0; i < N; i++) {
      O = O + (A[i] - 1) / X;
    }
    if (O > K) {
      btm = X;
      X = (top + btm + 1) / 2;
    } else {
      top = X;
      X = (top + btm + 1) / 2;
    }
  }

  cout << X << endl;

  return 0;
}

long long int Exp(long long int exp_n, long long int exp_e,
                  long long int exp_mod) {
  long long int exp_o = 1;
  long long int exp_x = exp_n;
  long long int exp_tmp;

  while (0 < exp_e) {
    exp_tmp = exp_e / 2;
    if (exp_e - exp_tmp * 2 == 1) {
      exp_o = exp_o * exp_x;
      if (exp_o > exp_mod) {
        exp_o = exp_o % exp_mod;
      }
    }

    exp_x = exp_x * exp_x;
    if (exp_x > exp_mod) {
      exp_x = exp_x % exp_mod;
    }
    exp_e = exp_tmp;
  }
  return exp_o;
}