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

#include <bits/stdc++.h>
#define int long long
#define PI acos(-1)

using namespace std;

constexpr double EPS = 1e-8;
constexpr int MAXN = 3e5 + 5;
constexpr int INF = 0x3f3f3f3f;

array<int, MAXN> a;

int n, k;

inline bool check(int mid) {
  int cnt(0);
  for (int i = 1; i <= n; i++) {
    if (a[i] % mid == 0)
      cnt += a[i] / mid - 1;
    else
      cnt += a[i] / mid;
  }
  return cnt <= k; //
}

signed main() {
  std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  int l = 1, r = 2e9, ans = 0;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check(mid)) {
      ans = mid, r = mid - 1;
    } else
      l = mid + 1;
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define int long long
#define PI acos(-1)

using namespace std;

constexpr double EPS = 1e-8;
constexpr int MAXN = 3e5 + 5;
constexpr int INF = 0x3f3f3f3f;

array<int, MAXN> a;

int n, k;

inline bool check(int mid) {
  int cnt(0);
  for (int i = 1; i <= n; i++) {
    if (a[i] % mid == 0)
      cnt += a[i] / mid - 1;
    else
      cnt += a[i] / mid;
  }
  return cnt <= k; //
}

signed main() {
  std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  int l = 0, r = 2e9, ans = 0;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check(mid)) {
      ans = mid, r = mid - 1;
    } else
      l = mid + 1;
  }
  cout << ans << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

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

#define loop(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < n; ++i)
#define dump(a) cerr << #a << " = " << (a) << "(L:" << __LINE__ << ")" << endl

long long N;
long long K;
std::vector<long long> A;
bool ok(long long x) {
  int k = 0;
  rep(i, N) {
    if (x == 0)
      k += A[i] + 1;
    else
      k += A[i] / x - (A[i] % x == 0);
  }
  return k <= K;
}

void solve(long long N_, long long K_, std::vector<long long> A_) {
  N = N_;
  K = K_;
  A = A_;

  long long ub = 1LL << 60;
  long long lb = 1;
  long long ans = 1LL << 60;
  while (lb <= ub) {
    long long md = (ub - lb) / 2 + lb;
    if (ok(md)) {
      ub = md;
      ub--;
      ans = min(ans, md);
    } else {
      lb = md;
      lb++;
    }
  }
  cout << ans << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  long long K;
  scanf("%lld", &K);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  solve(N, K, std::move(A));
  return 0;
}


Error: 0

Fixed submission:

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

#define loop(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < n; ++i)
#define dump(a) cerr << #a << " = " << (a) << "(L:" << __LINE__ << ")" << endl

long long N;
long long K;
std::vector<long long> A;
bool ok(long long x) {
  int k = 0;
  rep(i, N) k += A[i] / x - (A[i] % x == 0);
  return k <= K;
}

void solve(long long N_, long long K_, std::vector<long long> A_) {
  N = N_;
  K = K_;
  A = A_;

  long long ub = 1LL << 60;
  long long lb = 0;
  long long ans = 1LL << 60;
  while (lb <= ub) {
    long long md = (ub - lb) / 2 + lb;
    if (ok(md)) {
      ub = md;
      ub--;
      ans = min(ans, md);
    } else {
      lb = md;
      lb++;
    }
  }
  cout << ans << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  long long K;
  scanf("%lld", &K);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  solve(N, K, std::move(A));
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include "bits/stdc++.h"

using namespace std;
using ll = long long;

const int mx = 2e5 + 9;

int n;
ll k;
ll a[mx];

ll ceill(ll x, ll y) { return (x + y - 1) / y; }

bool ok(ll x) {
  ll ttl = 0;
  for (int i = 0; i < n; i++) {
    ttl += ceill(a[i], x);
  }

  return (ttl - n <= k);
}

int main() {
  scanf("%d %lld", &n, &k);
  for (int i = 0; i < n; i++)
    scanf("%lld", &a[i]);

  ll ans = *max_element(a, a + n);
  ll lo = 1, hi = 2e9;
  while (lo <= hi) {
    ll mid = (lo + hi) / 2;
    if (ok(mid)) {
      ans = mid;
      hi = mid - 1;
    } else {
      lo = mid + 1;
    }
  }

  printf("%lld\\n", ans);
}

Error: 0

Fixed submission:

#include "bits/stdc++.h"

using namespace std;
using ll = long long;

const int mx = 2e5 + 9;

int n;
ll k;
ll a[mx];

ll ceill(ll x, ll y) { return (x + y - 1) / y; }

bool ok(ll x) {
  ll ttl = 0;
  for (int i = 0; i < n; i++) {
    ttl += ceill(a[i], x);
  }

  return (ttl - n <= k);
}

int main() {
  scanf("%d %lld", &n, &k);
  for (int i = 0; i < n; i++)
    scanf("%lld", &a[i]);

  ll ans = 0;
  ll lo = 0, hi = 2e9;
  while (lo <= hi) {
    ll mid = (lo + hi) / 2;
    if (ok(mid)) {
      ans = mid;
      hi = mid - 1;
    } else {
      lo = mid + 1;
    }
  }

  printf("%lld\\n", ans);
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i, a, b) for (i = a; i < b; i++)
#define foe(i, a, b) for (i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector<long long int>
#define pii pair<int, int>
#define pll pair<long long int, long long int>
#define vpii vector<pair<int, int>>
#define vpll vector<pair<long long int, long long int>>
#define boost                                                                  \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;

bool chk(int arr[], int n, int mid, int k) {
  ll res = 0;
  for (int i = 0; i < n; i++)
    res += (arr[i] - 1) / mid;
  return (res <= k);
}
int main() {
  boost;
  int n, k, i;
  cin >> n >> k;
  int arr[n];
  fo(i, 0, n) cin >> arr[i];

  int f = 1, l = inf, mid, ans = inf;
  while (f <= l) {
    mid = (f + l) / 2;
    if (chk(arr, n, mid, k)) {
      ans = min(ans, mid);
      l = mid - 1;
    } else
      f = mid + 1;
  }
  cout << ans;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i, a, b) for (i = a; i < b; i++)
#define foe(i, a, b) for (i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector<long long int>
#define pii pair<int, int>
#define pll pair<long long int, long long int>
#define vpii vector<pair<int, int>>
#define vpll vector<pair<long long int, long long int>>
#define boost                                                                  \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;

bool chk(int arr[], int n, int mid, int k) {
  ll res = 0;
  for (int i = 0; i < n; i++)
    res += (arr[i] - 1) / mid;
  return (res <= k);
}
int main() {
  boost;
  int n, k, i;
  cin >> n >> k;
  int arr[n];
  fo(i, 0, n) cin >> arr[i];

  int f = 0, l = inf, mid, ans = inf;
  while (f <= l) {
    mid = (f + l) / 2;
    if (chk(arr, n, mid, k)) {
      ans = min(ans, mid);
      l = mid - 1;
    } else
      f = mid + 1;
  }
  cout << ans;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define all(X) (X).begin(), (X).end()
#define rall(X) (X).rbegin(), (X).rend()
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define P 1000000007
#define in(x, a, b) (a <= x && x < b)

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
const ll inf = 1000000001, INF = (ll)1e18 + 1;

int n, k;
vi a;

bool check(int val) {
  int total = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] <= val)
      continue;
    total += a[i] / val;
    if (a[i] % val == 0)
      total--;
  }

  return (total <= k);
}

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

  ll ans = INF;
  int l = 1, r = 1e9 + 10;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (check(mid)) {
      ans = min(ans, (ll)mid);
      r = mid - 1;
    } else
      l = mid + 1;
  }

  cout << ans << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  solve();
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define all(X) (X).begin(), (X).end()
#define rall(X) (X).rbegin(), (X).rend()
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define P 1000000007
#define in(x, a, b) (a <= x && x < b)

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
const ll inf = 1000000001, INF = (ll)1e18 + 1;

int n, k;
vi a;

bool check(int val) {
  int total = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] <= val)
      continue;
    total += a[i] / val;
    if (a[i] % val == 0)
      total--;
  }

  return (total <= k);
}

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

  ll ans = INF;
  int l = 0, r = 1e9 + 10;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (check(mid)) {
      ans = min(ans, (ll)mid);
      r = mid - 1;
    } else
      l = mid + 1;
  }

  cout << ans << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  solve();
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int n, k;
long long a[200010];
int check(long long logg) {
  int cnt = 0;
  if (!logg)
    return cnt;
  for (int i = 0; i < n; i++) {
    if (a[i] % logg == 0) {
      cnt += a[i] / logg - 1;
    } else
      cnt += a[i] / logg;
  }
  return cnt;
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  double l = 0, r = 2147483647;
  while (l < r - 1) {
    double mid = (l + r) / 2;
    if (check(mid) <= k)
      r = mid;
    else
      l = mid;
  }
  //	cout<<l<<' '<<r<<endl;
  cout << (int)(l + 0.9999999999999999999999999) << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int n, k;
long long a[200010];
int check(long long logg) {
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] % logg == 0) {
      cnt += a[i] / logg - 1;
    } else
      cnt += a[i] / logg;
  }
  return cnt;
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long double l = 0, r = 2147483646;
  while (l < r - 1) {
    long double mid = (l + r) / 2;
    if (check(mid) <= k)
      r = mid;
    else
      l = mid;
  }
  //	cout<<l<<' '<<r<<endl;
  cout << (int)(l + 0.9) << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long
#define db double
using namespace std;
const int M = 2e5 + 10;
int a[M], n, k;
bool check(int x) {
  int cnt = 0;
  for (int i = 0; i < n; i++)
    cnt += (a[i] - 1) / x;
  // printf("%d %d\\n",x,cnt);
  return cnt <= k;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]);
  sort(a, a + n);
  int l = 1, r = 1e9 + 10, ans = 0;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check(mid))
      ans = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  printf("%d\\n", ans);
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define db double
using namespace std;
const int M = 2e5 + 10;
int a[M], n, k;
bool check(int x) {
  int cnt = 0;
  for (int i = 0; i < n; i++)
    cnt += (a[i] - 1) / x;
  // printf("%d %d\\n",x,cnt);
  return cnt <= k;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]);
  sort(a, a + n);
  int l = 0, r = 1e9 + 10, ans = 0;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check(mid))
      ans = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  printf("%d\\n", ans);
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  long N, K;
  cin >> N >> K;
  vector<long> A(N);
  for (int i = 0; i < N; i++)
    cin >> A.at(i);
  sort(A.begin(), A.end());
  long count;
  long left = 1;
  long right = A.at(N - 1);
  while (left < right) {
    count = 0;
    long X = (left + right) / 2;
    for (int i = 0; i < N; i++) {
      /*count += ceil(A.at(i)/X);
      if(ceil(A.at(i)/X)*X==A.at(i)) count--;*/
      count += A.at(i) / X;
      if (A.at(i) % X == 0)
        count--;
    }
    if (count > K)
      left = X + 1;
    else
      right = X;
  }
  cout << right << endl;
}


Error: 0

Fixed submission:

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

int main() {
  long N, K;
  cin >> N >> K;
  vector<long> A(N);
  for (int i = 0; i < N; i++)
    cin >> A.at(i);
  sort(A.begin(), A.end());
  long count;
  long left = 0;
  long right = A.at(N - 1);
  while (left < right) {
    count = 0;
    long X = (left + right) / 2;
    for (int i = 0; i < N; i++) {
      /*count += ceil(A.at(i)/X);
      if(ceil(A.at(i)/X)*X==A.at(i)) count--;*/
      count += A.at(i) / X;
      if (A.at(i) % X == 0)
        count--;
    }
    if (count > K)
      left = X + 1;
    else
      right = X;
  }
  cout << left << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define trav(a, x) for (auto &a : x)
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;

int n, k;
vi a;

bool test(int m) {
  int cuts = 0;
  rep(i, 0, n) { cuts += (a[i] - 1) / m; }
  return cuts <= k;
}

int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin.exceptions(cin.failbit);

  cin >> n >> k;
  a = vi(n);
  rep(i, 0, n) { cin >> a[i]; }

  int lo = 0;
  int hi = 1e9 + 1;
  int mi;
  while (lo + 1 < hi) {
    mi = (lo + hi) / 2;
    if (test(mi)) {
      hi = mi;
    } else {
      lo = mi;
    }
  }
  cout << hi << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define trav(a, x) for (auto &a : x)
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;

int n, k;
vi a;

bool test(int m) {
  int cuts = 0;
  rep(i, 0, n) { cuts += (a[i] - 1) / m; }
  return cuts <= k;
}

int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin.exceptions(cin.failbit);

  cin >> n >> k;
  a = vi(n);
  rep(i, 0, n) { cin >> a[i]; }

  int lo = -1;
  int hi = 1e9 + 1;
  int mi;
  while (lo + 1 < hi) {
    mi = (lo + hi) / 2;
    if (test(mi)) {
      hi = mi;
    } else {
      lo = mi;
    }
  }
  cout << hi << endl;

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

#include <bits/stdc++.h>

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define fst first
#define snd second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define EPS (1e-9)
#define equals(a, b) (fabs((a) - (b)) < EPS)

using namespace std;

bool LT(double a, double b) { return !equals(a, b) && a < b; }
bool LTE(double a, double b) { return equals(a, b) || a < b; }

const string YES = "";
const string NO = "";

typedef long long ll;
typedef pair<int, int> ii;

int counter(ll v, ll x) {
  int cnt = v / x;
  if (v % x == 0)
    --cnt;
  return cnt;
}

int N, K;
vector<ll> A;
bool check(ll x) {
  if (x == 0)
    return false;
  int rem = K;
  rep(i, N) {
    int tmp = counter(A[i], x);
    rem -= tmp;
    if (rem < 0)
      return false;
  }
  return rem >= 0;
}

int main() {
  cin >> N >> K;
  A.resize(N);
  ll maxi = 0;
  rep(i, N) {
    cin >> A[i];
    maxi = max(maxi, A[i]);
  }
  ll L = 0, R = maxi + 10LL;
  while (L + 1LL < R) {
    ll M = (L + R) / 2LL;
    if (check(M))
      R = M;
    else
      L = M;
  }
  if (check(L))
    printf("%lld\\n", L);
  else if (check((L + R) / 2))
    printf("%lld\\n", (L + R) / 2);
  else
    printf("%lld\\n", R);

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define fst first
#define snd second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define EPS (1e-9)
#define equals(a, b) (fabs((a) - (b)) < EPS)

using namespace std;

bool LT(double a, double b) { return !equals(a, b) && a < b; }
bool LTE(double a, double b) { return equals(a, b) || a < b; }

const string YES = "";
const string NO = "";

typedef long long ll;
typedef pair<int, int> ii;

int counter(ll v, ll x) {
  int cnt = v / x;
  if (v % x == 0)
    --cnt;
  return cnt;
}

int N, K;
vector<ll> A;
bool check(ll x) {
  // if( x == 0 ) return false;
  int rem = K;
  rep(i, N) {
    int tmp = counter(A[i], x);
    rem -= tmp;
    if (rem < 0)
      return false;
  }
  return rem >= 0;
}

int main() {

  if (0) {
    N = 200000;
    cout << N << " " << 1000000000 << endl;
    rep(i, N) cout << rand() % 1000000000 + 1 << " ";
    puts("");
    return 0;
  }

  cin >> N >> K;
  A.resize(N);
  ll maxi = 0;
  rep(i, N) {
    cin >> A[i];
    maxi = max(maxi, A[i]);
  }
  ll L = 0, R = maxi + 10LL;
  while (L + 1LL < R) {
    ll M = (L + R) / 2LL;
    if (check(M))
      R = M;
    else
      L = M;
  }
  if (check(L))
    printf("%lld\\n", L);
  else if (check((L + R) / 2))
    printf("%lld\\n", (L + R) / 2);
  else
    printf("%lld\\n", R);

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

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

typedef pair<ll, pair<ll, ll>> p;

#define MOD 1000000007

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

  ll N, K;
  cin >> N >> K;

  vector<ll> A(N);

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

  ll x = *max_element(A.begin(), A.end());

  ll front = 1LL;
  ll back = x;

  ll mid = (front + back) / 2LL;

  ll ans = x;

  if (K == 0) {
    cout << x << endl;
    return 0;
  }

  while (front < back) {
    ll count = 0LL;
    for (int i = 0; i < N; i++) {
      if (A[i] <= mid)
        continue;
      ll t = A[i] / mid;
      if (t * mid < A[i]) {
        t++;
      }
      count += t - 1LL;
    }

    if (count <= K) {
      ans = mid;
      back = mid;
    } else {
      front = mid + 1LL;
    }
    mid = (front + back) / 2LL;
  }

  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

typedef pair<ll, pair<ll, ll>> p;

#define MOD 1000000007

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

  ll N, K;
  cin >> N >> K;

  vector<ll> A(N);

  ll x = 0LL;

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

  ll front = 0LL;
  ll back = x;

  ll mid = (front + back) / 2LL;

  ll ans = x;

  while (front < back) {
    ll count = 0LL;
    for (int i = 0; i < N; i++) {
      ll t = A[i] / mid;
      if (t * mid < A[i]) {
        t++;
      }
      count += t - 1LL;
    }

    if (count <= K) {
      ans = mid;
      back = mid;
    } else {
      front = mid + 1LL;
    }
    mid = (front + back) / 2LL;
  }

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

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

typedef long long int ll;
ll n, k, a[200007];

bool check(ll x) {
  ll cuts = 0;
  for (ll i = 0; i < n; ++i) {
    cuts += (a[i] + x - 1) / x - 1;
  }

  return cuts <= k;
}

int main() {
  scanf("%lld %lld", &n, &k);
  for (ll i = 0; i < n; ++i) {
    scanf("%lld", &a[i]);
  }

  sort(a, a + n);

  ll l = 1, r = a[n - 1];
  while (l < r) {
    ll mid = (l + r) / 2;
    if (check(mid)) {
      r = mid;
    } else
      l = mid + 1;
  }

  printf("%lld\\n", l);
  return 0;
}

Error: TLE

Fixed submission:

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

typedef long long int ll;
ll n, k;
priority_queue<ll> q;

bool check(ll x) {
  priority_queue<ll> t = q;

  for (ll i = 0; i < k; ++i) {
    ll h = t.top();
    if (h <= x)
      return 1;
    t.pop();
    t.push(x);
    t.push(h - x);
  }

  if (t.top() > x)
    return 0;
  return 1;
}

int main() {
  scanf("%lld %lld", &n, &k);
  for (ll i = 0; i < n; ++i) {
    ll temp;
    scanf("%lld", &temp);
    q.push(temp);
  }

  ll l = 1, r = q.top();
  while (l < r) {
    ll mid = (l + r) / 2;
    if (check(mid)) {
      r = mid;
    } else
      l = mid + 1;
  }

  printf("%lld\\n", l);
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define FASTIO                                                                 \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
using namespace std;
using ll = long long;
#define double ll

int main() {
  FASTIO
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  for (auto &i : a) {
    cin >> i;
  }

  auto f = [&](double m) -> bool {
    if (m == 0) {
      ll u = 0;
      for (int i = 0; i < 1; i++) {
        double x = a[i];
        ll r = 1;
        ll e = 0;
        while (x >= 1) {
          //					clog << x << ' ' << e << ' ' << r <<
          //endl;
          e += r;
          //					clog << x << ' ' << e << ' ' << r <<
          //endl;
          r <<= 1;
          x /= 2;
        }
        u += e;
      }
      return u <= k;
    }
    ll u = 0;
    for (int i = 0; i < n; i++) {
      u += ((a[i] - 1) / m);
    }
    return u <= k;
  };
  double lo = 1, hi = 1e9;
  for (auto _ = 0; _ < 100; _++) {
    double mid = lo + (hi - lo) / 2;
    if (f(mid)) {
      hi = mid;
    } else {
      lo = mid;
    }
  }
  cout << hi << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

#define FASTIO                                                                 \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
using namespace std;
using ll = long long;
#define double ll

int main() {
  FASTIO
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  for (auto &i : a) {
    cin >> i;
  }

  auto f = [&](double m) -> bool {
    ll u = 0;
    for (int i = 0; i < n; i++) {
      u += (a[i] - 1) / m;
    }
    return u <= k;
  };
  double lo = 0, hi = 1e9;
  for (auto _ = 0; _ < 100; _++) {
    double mid = lo + (hi - lo) / 2;
    if (f(mid)) {
      hi = mid;
    } else {
      lo = mid;
    }
  }
  cout << hi << endl;
}