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

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main(int argc, const char *argv[]) {
  ll n, k;
  cin >> n >> k;
  vector<ll> va(n);
  for (int i = 0; i < n; ++i) {
    cin >> va[i];
  }

  ll left = 1, right = *max_element(va.begin(), va.end());
  auto check = [](vector<ll> &va, ll mid, ll k) {
    ll cnt = 0;
    for (int i = 0; i < va.size(); ++i) {
      ll a = va[i];
      cnt += a / mid - (a % mid == 0);
    }

    return cnt <= k;
  };

  while (left < right) {
    ll mid = (left + right) / 2;
    if (check(va, mid, k)) {
      right = mid;
    } else {
      left = mid + 1;
    }
  }

  cout << right << '\\n';

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main(int argc, const char *argv[]) {
  ll n, k;
  cin >> n >> k;
  vector<ll> va(n);
  for (int i = 0; i < n; ++i) {
    cin >> va[i];
  }

  ll left = 0, right = *max_element(va.begin(), va.end());
  auto check = [](vector<ll> &va, ll mid, ll k) {
    ll cnt = 0;
    for (int i = 0; i < va.size(); ++i) {
      ll a = va[i];
      cnt += a / mid - (a % mid == 0);
    }

    return cnt <= k;
  };

  while (left < right) {
    ll mid = (left + right) / 2;
    if (check(va, mid, k)) {
      right = mid;
    } else {
      left = mid + 1;
    }
  }

  cout << right << '\\n';

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

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

int main() {
  long long int n, k;
  cin >> n >> k;
  long long int a[n];
  for (long int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  long long int l = 1, r = a[n - 1], ans = a[n - 1];
  while (l <= r) {
    long long int mid = (l + r) / 2, req = 0;
    for (long long int i = 0; i < n; i++) {
      req += a[i] / mid;
      if (a[i] % mid)
        req++;
      req--;
    }
    if (req > k) {
      l = mid + 1;
    } else {
      r = mid - 1;
      ans = min(ans, mid);
    }
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

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

int main() {
  long long int n, k;
  cin >> n >> k;
  long long int a[n];
  for (long int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  long long int l = 1, r = a[n - 1], ans = a[n - 1];
  while (l <= r) {
    long long int mid = (l + r) / 2, req = 0;
    for (long long int i = 0; i < n; i++) {
      req += a[i] / mid;
    }
    if (req > k) {
      l = mid + 1;
    } else {
      r = mid;
      ans = min(ans, mid);
    }
  }
  cout << ans << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int check(ll arr[], ll n, ll mid, ll k) {
  ll i, temp = 0, g;

  for (i = 0; i < n; i++) {
    g = arr[i];
    if (g > mid) {
      temp = temp + g / mid;
    }
    if (temp > k)
      return 0;
  }
  return 1;
}

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

  ll arr[n], i, s, e, mid, ans, t;
  for (i = 0; i < n; i++)
    cin >> arr[i];

  sort(arr, arr + n);

  ans = INT_MAX;

  s = 1;
  e = arr[n - 1];

  while (s <= e) {
    mid = (s + e) / 2;
    t = check(arr, n, mid, k);
    if (t == 1) {
      ans = min(ans, mid);
      e = mid - 1;
    } else
      s = mid + 1;
    //  cout<<"s:  e:  ans:  t "<<s<<" "<<e<<" "<<ans<<" "<<t<<endl;
  }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

int check(ll arr[], ll n, ll mid, ll k) {
  ll i, temp = 0, g;

  for (i = 0; i < n; i++) {
    g = arr[i];
    while (g > mid) {
      g = g - mid;
      temp++;
    }
    if (temp > k)
      return 0;
  }
  return 1;
}

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

  ll arr[n], i, s, e, mid, ans, t;
  for (i = 0; i < n; i++)
    cin >> arr[i];

  sort(arr, arr + n);

  ans = INT_MAX;

  s = 0;
  e = arr[n - 1];

  while (s <= e) {
    mid = (s + e) / 2;
    t = check(arr, n, mid, k);
    if (t == 1) {
      ans = min(ans, mid);
      e = mid - 1;
    } else
      s = mid + 1;
    //  cout<<"s:  e:  ans:  t "<<s<<" "<<e<<" "<<ans<<" "<<t<<endl;
  }
  cout << ans << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(void) {
  int n, k, ng = 0, ok = 1e9;
  cin >> n >> k;
  int a[n];
  rep(i, n) cin >> a[i];
  while (ok - ng > 1) {
    int mid = (ok + ng) / 2, cnt = 0;
    rep(i, n) cnt += (a[i] - 1) / mid;
    if (cnt <= k)
      ok = mid;
    else
      ng = mid;
  }
  cout << ok << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(void) {
  int n, k, ng = -1, ok = 1e9;
  cin >> n >> k;
  int a[n];
  rep(i, n) cin >> a[i];
  while (ok - ng > 1) {
    int mid = (ok + ng) / 2, cnt = 0;
    rep(i, n) cnt += (a[i] + mid - 1) / mid - 1;
    if (cnt <= k)
      ok = mid;
    else
      ng = mid;
  }
  cout << ok << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(), A.end()
#define RALL(A) A.rbegin(), A.rend()
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
const ll LINF = 1LL << 60;
const int INF = 1 << 30;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
ll copy(ll x) { return x; }
int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  ll r = LINF;
  ll l = 0LL;
  while (r - l > 1) {
    ll m = (r + l) / 2;
    ll ans = 0;
    for (int i = 0; i < n; i++) {
      ll x = copy(a[i]);
      ans += ((x + m - 1) / m - 1);
      if (ans > k) {
        break;
      }
    }
    if (ans <= k) {
      // out = min(out,res);
      r = m;
    } else {
      l = m;
    }
  }
  cout << r << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(), A.end()
#define RALL(A) A.rbegin(), A.rend()
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
const ll LINF = 1LL << 60;
const int INF = 1 << 30;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
ll copy(ll x) { return x; }
int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  ll r = INF;
  ll l = -1LL;
  while (r - l > 1) {
    ll m = (r + l) / 2;
    ll ans = 0;
    for (int i = 0; i < n; i++) {
      ll x = copy(a[i]);
      ans += ((x + m - 1) / m - 1);
      if (ans > k) {
        break;
      }
    }
    if (ans <= k) {
      // out = min(out,res);
      r = m;
    } else {
      l = m;
    }
  }
  cout << r << endl;

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

#include <bits/stdc++.h>
using namespace std;
// #pragma comment(linker, "/STACK:102400000,102400000")
typedef long long ll;
typedef pair<int, int> P;
#define ls(x) (x << 1)
#define rs(x) (x << 1 | 1)
#define lowbit(x) (x & -x)
const ll INF = 0x3f3f3f3f;
const double EPS = 1e-6;
const int N = 2e5 + 10;
const ll mod = 1e9 + 7;
inline ll read() {
  ll f = 1, x = 0;
  char ch = getchar();
  for (; ch > '9' || ch < '0'; ch = getchar())
    if (ch == '-')
      f = -1;
  for (; ch <= '9' && ch >= '0'; ch = getchar())
    x = x * 10 + ch - '0';
  return x * f;
}
ll n, k;
double a[N];
bool check(double mid) {
  ll cnt = 0;
  for (ll i = 1; i <= n; i++) {
    if (a[i] <= mid)
      continue;
    cnt = cnt + ceil((a[i] / mid));
    cnt--;
    if (cnt > k)
      return 0;
  }
  if (cnt > k)
    return 0;
  else
    return 1;
}
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  double l = 0.0001, r = 1e9 + 5, ans;
  while (r - l >= EPS) {
    double mid = (l + r) / 2;
    if (check(mid)) {
      r = mid;
    } else {
      l = mid;
    }
  }
  printf("%.0f\\n", max(1.0, ceil(r - 0.000001)));
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
// #pragma comment(linker, "/STACK:102400000,102400000")
typedef long long ll;
typedef pair<int, int> P;
#define ls(x) (x << 1)
#define rs(x) (x << 1 | 1)
#define lowbit(x) (x & -x)
const ll INF = 0x3f3f3f3f;
const double EPS = 1e-7;
const int N = 2e5 + 10;
const ll mod = 1e9 + 7;
inline ll read() {
  ll f = 1, x = 0;
  char ch = getchar();
  for (; ch > '9' || ch < '0'; ch = getchar())
    if (ch == '-')
      f = -1;
  for (; ch <= '9' && ch >= '0'; ch = getchar())
    x = x * 10 + ch - '0';
  return x * f;
}
ll n, k;
long double a[N];
bool check(double mid) {
  ll cnt = 0;
  for (ll i = 1; i <= n; i++) {
    if (a[i] <= mid)
      continue;
    ll now = ceil((a[i] - mid) / mid);
    if (now)
      cnt = cnt + now;
    if (cnt > k)
      return 0;
  }
  if (cnt > k)
    return 0;
  else
    return 1;
}
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  double l = 0.000001, r = 1e9 + 5, ans;
  while (r - l >= EPS) {
    long double mid = (l + r) / 2;
    if (check(mid)) {
      r = mid;
    } else {
      l = mid;
    }
  }
  printf("%.0f\\n", max(1.0, ceil(r - 0.000001)));
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e6 + 50;
ll n, k;
ll a[maxn];
inline int log_number(int x, int mid) {
  if (x % mid == 0)
    return x / mid;
  else
    return x / mid + 1;
}
bool check(int x) {
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    ans += log_number(a[i], x) - 1;
  }
  if (ans <= k)
    return true;
  else
    return false;
}
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; ++i)
    cin >> a[i];
  int l = 1, r = 1e9;
  int ans = 0;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (check(mid))
      r = mid - 1, ans = mid;
    else
      l = mid + 1;
  }
  /*if(check(l))  cout<<l<<endl;
  else cout<<r<<endl;*/
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 50;
ll n, k;
ll a[maxn];
inline int log_number(int x, int mid) {
  if (x % mid == 0)
    return x / mid;
  else
    return x / mid + 1;
}
bool check(int x) {
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    ans += log_number(a[i], x) - 1;
  }
  if (ans <= k)
    return true;
  else
    return false;
}
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; ++i)
    cin >> a[i];
  int l = 1, r = 1e9;
  int ans = 0;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (check(mid))
      r = mid - 1, ans = mid;
    else
      l = mid + 1;
  }
  /*if(check(l))  cout<<l<<endl;
  else cout<<r<<endl;*/
  cout << ans << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e6 + 50;
ll n, k;
ll a[maxn];
ll log_number(int x, int mid) {
  if (x % mid == 0)
    return x / mid;
  else
    return x / mid + 1;
}
bool check(int x) {
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    ans += log_number(a[i], x) - 1;
  }
  if (ans > 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 cnt = 0;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check(mid))
      r = mid - 1, cnt = mid;
    else
      l = mid + 1;
  }
  cout << cnt << endl;
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 50;
ll n, k;
ll a[maxn];
ll log_number(int x, int mid) {
  if (x % mid == 0)
    return x / mid;
  else
    return x / mid + 1;
}
bool check(int x) {
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    ans += log_number(a[i], x) - 1;
  }
  if (ans >= 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 cnt = 0;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check(mid))
      r = mid - 1, cnt = mid;
    else
      l = mid + 1;
  }
  cout << cnt << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <iostream>

using namespace std;

#define ll long long
#define mod 1000000007

const ll INF = 1e11;

void solve() {

  ll n, k;
  cin >> n >> k;
  ll arr[n];
  for (int i = 0; i < n; ++i)
    cin >> arr[i];
  ll l = 1, r = *max_element(arr, arr + n);
  while (l < r) {
    ll mid = l + (r - l) / 2;
    ll cuts = 0;
    for (ll i = 0; i < n; ++i)
      cuts += (arr[i] - 1) / mid;
    if (cuts > k)
      l = mid + 1;
    else
      r = mid;
  }
  cout << l << "\\n";

  return;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  // int test; cin >> test;
  // for(int t = 1; t <= test; ++t){
  solve();
  //}

  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#include <iostream>

using namespace std;

#define ll long long
#define mod 1000000007

const ll INF = 1e11;

void solve() {

  int n, k;
  cin >> n >> k;
  int arr[n];
  for (int i = 0; i < n; ++i)
    cin >> arr[i];
  int l = 0, r = *max_element(arr, arr + n);
  while (l < r) {
    int mid = l + (r - l) / 2;
    ll cuts = 0;
    for (int i = 0; i < n; ++i)
      cuts += arr[i] / mid;
    if (cuts > k)
      l = mid + 1;
    else
      r = mid;
  }
  cout << l;

  return;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  // int test; cin >> test;
  // for(int t = 1; t <= test; ++t){
  solve();
  //}

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> iint;
typedef pair<ll, ll> llll;
#define ALL(x) (x).begin(), (x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; // 10^18
const int inINF = 1000000000;       // 10^9
const ll MOD = 1000000007;          // 10^9+7
const ll MOD2 = 998244353;
void Yes() { printf("Yes\\n"); }
void No() { printf("No\\n"); }
void YES() { printf("YES\\n"); }
void NO() { printf("NO\\n"); }

ll N;
vector<ll> A;

ll f(ll x) {
  ll ret;
  ret = 0;
  for (ll i = 0; i < N; i++) {
    ret += (A[i] - 1) / x;
  }
  return ret;
}

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

  ll ng = 0;
  ll ok = 1000000005;
  ll mid;
  while (ng + 1 < ok) {
    mid = (ng + ok) / 2;
    if (f(mid) > K) {
      ng = mid;
    } else if (f(mid) < K) {
      if (mid >= 2 && f(mid - 1) > K) {
        ok = mid;
        break;
      }
      ok = mid;
    } else {
      if (mid >= 2 && f(mid - 1) > K) {
        ok = mid;
        break;
      } else {
        ok = mid;
      }
    }
  }
  printf("%lld\\n", ok);
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> iint;
typedef pair<ll, ll> llll;
#define ALL(x) (x).begin(), (x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; // 10^18
const int inINF = 1000000000;       // 10^9
const ll MOD = 1000000007;          // 10^9+7
const ll MOD2 = 998244353;
void Yes() { printf("Yes\\n"); }
void No() { printf("No\\n"); }
void YES() { printf("YES\\n"); }
void NO() { printf("NO\\n"); }

ll N;
vector<ll> A;

ll f(ll x) {
  ll ret;
  ret = 0;
  for (ll i = 0; i < N; i++) {
    ret += (A[i] - 1) / x;
  }
  return ret;
}

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

  ll ng = 0;
  ll ok = 1000000005;
  ll mid;
  while (ng + 1 < ok) {
    mid = (ng + ok) / 2;
    if (f(mid) > K) {
      ng = mid;
    } else if (f(mid) < K) {
      if (f(mid - 1) > K) {
        ok = mid;
        break;
      }
      ok = mid;
    } else {
      if (f(mid - 1) > K) {
        ok = mid;
        break;
      } else {
        ok = mid;
      }
    }
  }
  printf("%lld\\n", ok);
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

//
// Created by admin on 2020/8/2.
//
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n, k, a[5000010];
bool check(int l) {
  int cnt = 0;
  for (int i = 1; i <= n; i++)
    cnt += (a[i] - 1) / l;
  return cnt <= k;
}
signed main() {
  int tem = 0;
  scanf("%lld%lld", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    tem = max(tem, a[i]);
  }
  int l = 1, r = tem, mid;
  while (r >= l) {
    mid = (l + r) / 2;
    if (check(mid))
      r = mid - 1;
    else
      l = mid + 1;
  }
  printf("%lld\\n", l);
  return 0;
}


Error: 0

Fixed submission:

//
// Created by admin on 2020/8/2.
//
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n, k, a[5000010], sum;
bool check(int l) {
  int cnt = 0;
  for (int i = 1; i <= n; i++)
    cnt += (a[i] - 1) / l;
  return cnt <= k;
}
signed main() {
  int tem = 0;
  scanf("%lld%lld", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    tem = max(tem, a[i]);
    sum += a[i];
  }
  int l = 0, r = tem, mid;
  while (r >= l) {
    mid = (l + r) / 2;
    if (check(mid))
      r = mid - 1;
    else
      l = mid + 1;
  }
  printf("%lld\\n", l);
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  vector<int> a(n);
  int left = 1, right = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    right = max(right, a[i]);
  }

  while (left < right) {
    int mid = (left + right) >> 1;
    long long t = 0;
    for (int i = 0; i < n; i++)
      t += (a[i] - 1) / mid;
    if (t <= k)
      right = mid;
    else
      left = mid + 1;
  }

  printf("%d\\n", left);

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  vector<int> a(n);
  int left = 0, right = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    right = max(right, a[i]);
  }

  while (left < right) {
    int mid = (left + right) >> 1;
    long long t = 0;
    for (int i = 0; i < n; i++)
      t += (a[i] - 1) / mid;
    if (t <= k)
      right = mid;
    else
      left = mid + 1;
  }

  printf("%d\\n", left);

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

#include <bits/stdc++.h>
#include <random>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)

using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using ull = unsigned long long;
const ll K_MAX = 1e5 + 5;
const ll Lmax = ll(1e18);
const ll INF = 1e6;
const int Nmax = 2e5 + 1;
const int Nd = 61;

int main() {
  ll n;
  ll k;
  cin >> n >> k;
  vector<ll> a(n);
  ll maxa = 1;
  rep(i, n) {
    cin >> a[i];
    if (maxa < a[i])
      maxa = a[i];
  }

  if (k == 0) {
    cout << maxa << endl;
    return 0;
  }
  ll count = 0;

  ll imin = 1;
  bool ok = true;
  // cout<<"imin:"<<imin<<" "<<maxa<<endl;
  ll imax = maxa;
  ll now = (imax + imin) / 2;
  ll count_plus = 0;
  // cout<<"i:"<<imin<<" "<<imax<<endl;
  while (imax - imin > 1) {
    now = (imin + imax) / 2;
    // cout<<"i:"<<imin<<" "<<imax<<endl;
    count = 0;
    ok = true;
    rep(i, n) {
      count_plus = a[i] / now;
      if (a[i] % now == 0)
        count_plus = a[i] / now - 1;
      if (k < count_plus || count > k - count_plus) { // 刻み回数が多すぎる
        ok = false;
        break;
      }
      count += count_plus;
    }

    if (ok) { // now>=ans;
      imax = now;
    } else { // now<ans;
      imin = now;
    }
  }
  count = 0;
  // imax-imin<=1;

  rep(i, n) {
    count_plus = a[i] / imin;
    if (a[i] % imin == 0)
      count_plus = a[i] / imin - 1;
    if (k < count_plus ||
        count > k - count_plus) { // iminだと刻み回数が多すぎる
      cout << imax << endl;
      return 0;
    }

    count += count_plus;
  }
  // iminでカット可能．
  cout << imin << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <random>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)

using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using ull = unsigned long long;
const ll K_MAX = 1e5 + 5;
const ll Lmax = ll(1e18);
const ll INF = 1e6;
const int Nmax = 2e5 + 1;
const int Nd = 61;

int main() {
  ll n;
  ll k;
  cin >> n >> k;
  vector<ll> a(n);
  ll maxa = 1;
  rep(i, n) {
    cin >> a[i];
    // cout<<a[i]<<" ";
    if (maxa < a[i])
      maxa = a[i];
  }
  if (k == 0) {
    cout << maxa;
    return 0;
  }

  ll imin = maxa / (k + 1);
  // if(imin==0) imin=1;
  // cout<<"imin:"<<imin<<" "<<maxa<<endl;
  ll now = imin - 1;
  ll imax = maxa;
  ll count_plus = 0;
  // cout<<"i:"<<imin<<" "<<imax<<endl;
  while (imax - imin > 1) {
    now = (imin + imax) / 2;
    ll count = 0;
    bool ok = true;

    rep(i, n) {
      count_plus = a[i] / now;
      if (count > k - count_plus) { // 刻み回数が多すぎる
        ok = false;
        break;
      }
      count += count_plus;
    }

    if (ok) { // now>=ans;
      imax = now;
    } else { // now<ans;
      imin = now;
    }
  }
  ll count = 0;
  rep(i, n) {
    count_plus = a[i] / imin;
    if (count > k - count_plus) { // imaxだと刻み回数が多すぎる
      cout << imax << endl;
      return 0;
    }
    count += count_plus;
  }

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

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

int main() {
  int n, k;
  cin >> n >> k;
  vi a(n);
  rep(i, n) cin >> a.at(i);
  // 二分探索
  int l = 0, r = 1e9;
  while (r - l > 1) {
    int x = (l + r) / 2;
    auto f = [&](int x) {
      ll now = 0;
      // 丸太を切る回数を求める
      rep(i, n) now += (a.at(i) - 1) / x;
      return now <= k;
    };
    if (f(x))
      r = x;
    else
      l = x;
  }
  cout << r << endl;
  return 0;
}

Error: 0

Fixed submission:

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

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i < i##_len; ++i)
#define ll long long
static const int MAX = 10000;
static const ll INFTY = 1e12;

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

const ll MRINF = 5000000000000000;

ll N, K;
vector<ll> A;
ll f(ll k) {
  ll now = 0;
  REP(i, N) { now += (A[i] - 1) / k; }

  return now <= K;
}

int main() {

  cin >> N >> K;
  // vector<ll> A(N);
  REP(i, N) {
    ll a;
    cin >> a;
    A.push_back(a);
  }

  ll s = 0;
  ll t = 1e10;
  ll ng = s - 1, ok = t;
  while (ok - ng > 1) {
    ll mid = (ng + ok) / 2;
    if (f(mid))
      ok = mid;
    else
      ng = mid;
    // (f(A, mid) ? ok : ng) = mid;
  }

  cout << ok << endl;
}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\\  =  /O
               ____/`---'\\____
             .'  \\\\|     |//  `.
            /  \\\\|||  :  |||//  \\
           /  _||||| -:- |||||-  \\
           |   | \\\\\\  -  /// |   |
           | \\_|  ''\\---/''  |   |
           \\  .-\\__  `-`  ___/-. /
         ___`. .'  /--.--\\  `. . __
      ."" '<  `.___\\_<|>_/___.'  >'"".
     | | :  `- \\`.;`\\ _ /`;.`/ - ` : | |
     \\  \\ `-.   \\_ __\\ /__ _/   .-` /  /
======`-.____`-.___\\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/