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

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

int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];
  sort(A.begin(), A.end(), greater<ll>());
  ll l = 1, r = 1000000000;
  ll m = (l + r) / 2;
  while (r - l > 0) {
    ll Count = 0;
    rep(i, N) {
      if (A[i] > m) {
        Count += A[i] / m;
      }
    }
    if (Count <= K) {
      r = m;
      m = (l + r) / 2;
    } else {
      l = m + 1;
      m = (l + r) / 2;
    }
  }
  cout << m << endl;
}

Error: 0

Fixed submission:

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

int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];
  sort(A.begin(), A.end(), greater<ll>());
  ll l = 0, r = 1000000000;
  ll m = (l + r) / 2;
  while (r - l > 0) {
    ll Count = 0;
    rep(i, N) {
      if (A[i] > m) {
        Count += A[i] / m;
      }
    }
    if (Count <= K) {
      r = m;
      m = (l + r) / 2;
    } else {
      l = m + 1;
      m = (l + r) / 2;
    }
  }
  cout << m << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bits/stdc++.h>
#include <cstdio>
#include <iostream>
using namespace std;
int a[200005] = {0};
int n, k;
int solve(int fun) {
  int num = 0;
  for (int i = 0; i < n; i++) {
    num += (a[i] - 1) / fun;
  }
  if (num <= k)
    return 1;
  return 0;
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int l = 1, r = 1000000007;
  int ans = 0;
  while (l < r) {
    int m = (l + r) / 2;
    if (solve(m)) {
      r = m;
      ans = m;
    } else
      l = m + 1;
    // cout << l << " " << r << endl;
  }
  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <cstdio>
#include <iostream>
using namespace std;
int a[200005] = {0};
int n, k;
int solve(int fun) {
  int num = 0;
  for (int i = 0; i < n; i++) {
    num += (a[i] - 1) / fun;
  }
  if (num <= k)
    return 1;
  return 0;
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int l = 0, r = 1000000007;
  int ans = 0;
  while (l < r) {
    int m = (l + r) / 2;
    if (solve(m)) {
      r = m;
      ans = m;
    } else
      l = m + 1;
    // cout << l << " " << r << endl;
  }
  cout << ans << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
long double X[200100];
int N;
long long Count(long double len) {
  long long Ans = 0;
  for (int i = 0; i < N; i++) {
    Ans += (long long)(X[i] / len);
    // Ans+= (ceil(X[i])-1/len);
  }
  return Ans;
}
int main() {
  long long K;
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    cin >> X[i];
    // X[i]-=0.1;
  }
  long double l = 1, r = 1e9;
  // while(l<r-0.1)
  for (int i = 0; i < 300; i++)
  // while(((long long)(r)-(long long)(l)) > 1)
  // while(!((ceil(r)-ceil(l)) == 0))
  {
    // long double mid=(l+r+0.1)/2;
    long double mid = (l + r) / 2;
    //  cout<<l<<" "<<r<<" "<<mid<<endl;
    if (Count(mid) <= K)
      r = mid;
    else
      l = mid;
    // else	l=mid+0.01;
  }
  cout << (long long)(l + 0.999) << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
long double X[200100];
int N;
long long Count(long double len) {
  long long Ans = 0;
  for (int i = 0; i < N; i++) {
    Ans += (long long)(X[i] / len);
  }
  return Ans;
}
int main() {
  long long K;
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    cin >> X[i];
    X[i] -= 0.1;
  }
  long double l = 1, r = 1e9;
  while (l < r - 0.1) {
    long double mid = (l + r + 0.1) / 2;
    //  cout<<l<<" "<<r<<" "<<mid<<endl;
    if (Count(mid) <= K)
      r = mid;
    else
      l = mid + 0.01;
  }
  cout << (long long)(l + 0.999) << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
long double X[200100];
int N;
long long Count(long double len) {
  long long Ans = 0;
  for (int i = 0; i < N; i++) {
    Ans += (long long)(X[i] / len);
    // Ans+= (ceil(X[i])-1/len);
  }
  return Ans;
}
int main() {
  long long K;
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    cin >> X[i];
    // X[i]-=0.1;
  }
  long double l = 1, r = 1e9;
  // while(l<r-0.1)//なぜかOK
  // for(int i=0;i<35;i++)//OK log2(10^9)
  // while(((long long)(r)-(long long)(l)) > 1)
  // while(!((ceil(r)-ceil(l)) ==
  // 0))//https://atcoder.jp/contests/abc174/submissions/15672399
  while (!((floor(r) - floor(l)) ==
           0)) // https://atcoder.jp/contests/abc174/submissions/15672399
  {
    // long double mid=(l+r+0.1)/2;
    long double mid = (l + r) / 2;
    //  cout<<l<<" "<<r<<" "<<mid<<endl;
    if (Count(mid) <= K)
      r = mid;
    else
      l = mid;
    // else	l=mid+0.01;
  }
  cout << (long long)(l + 0.999) << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
long double X[200100];
int N;
long long Count(long double len) {
  long long Ans = 0;
  for (int i = 0; i < N; i++) {
    Ans += (long long)(X[i] / len);
    // Ans+= (ceil(X[i])-1/len);
  }
  return Ans;
}
int main() {
  long long K;
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    cin >> X[i];
    // X[i]-=0.1;
  }
  long double l = 1, r = 1e9;
  // while(l<r-0.1)
  // for(int i=0;i<300;i++)
  // while(((long long)(r)-(long long)(l)) > 1)
  while (!((ceil(r) - ceil(l)) == 0)) {
    // long double mid=(l+r+0.1)/2;
    long double mid = (l + r) / 2;
    //  cout<<l<<" "<<r<<" "<<mid<<endl;
    if (Count(mid) <= K)
      r = mid;
    else
      l = mid;
    // else	l=mid+0.01;
  }
  cout << (long long)(l + 0.999) << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
long double X[200100];
int N;
long long Count(long double len) {
  long long Ans = 0;
  for (int i = 0; i < N; i++) {
    Ans += (long long)(X[i] / len);
    // Ans+= ceil(X[i]/len)-1;
  }
  return Ans;
}

int main() {
  long long K;
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    cin >> X[i];
    // X[i]-=0.1;
  }

  long double l = 1, r = 1e9;
  // while(l<r-0.1)//解答を引っ張ってきた人の条件。なぜかOKだったが、lとｒの整数部が異なる状態でループを出ると問題になるはず
  for (
      int i = 0; i < 35;
      i++) // OK
           // log2(10^9)=30.二分探索だとこのやり方安定する。ただし、浮動小数のせいか34以上でないと通らず。
  // while(!((ceil(r)-ceil(l)) ==
  // 0))//NG:左端が初期値0のままだと、右端のceilは0にならず、無限ループ
  // while(!((floor(r)-floor(l)) ==
  // 0))//OK:右端がぴったり整数にならなければ成立.(あまりよくない)
  {
    long double mid = (l + r) / 2;
    if (Count(mid) <= K)
      r = mid;
    else
      l = mid;
  }
  cout << (long long)(l + 0.999) << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
long double X[200100];
int N;
long long Count(long double len) {
  long long Ans = 0;
  for (int i = 0; i < N; i++) {
    // Ans+=(long long)(X[i]/len);
    Ans += ceil(X[i] / len) - 1;
  }
  return Ans;
}

int main() {
  long long K;
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    cin >> X[i];
    // X[i]-=0.1;
  }

  long double l = 1, r = 1e9;
  // while(l<r-0.1)//解答を引っ張ってきた人の条件。なぜかOKだったが、lとｒの整数部が異なる状態でループを出ると問題になるはず
  // for(int i=0;i<35;i++)//OK
  // log2(10^9)=30.二分探索だとこのやり方安定する。ただし、浮動小数のせいか34以上でないと通らず。
  // while(!((ceil(r)-ceil(l)) ==
  // 0))//NG:左端が初期値0のままだと、右端のceilは0にならず、無限ループ
  while (!((floor(r) - floor(l)) ==
           0)) // OK:右端がぴったり整数にならなければ成立.(あまりよくない)
  {
    long double mid = (l + r) / 2;
    if (Count(mid) <= K)
      r = mid;
    else
      l = mid;
  }
  cout << (long long)(l + 0.999) << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
#define NMAX 200002
using namespace std;
vector<int> v;
int N, K, M = 0, m = 0, ans = 0;
bool able(int a) {
  int cou = 0;
  for (auto &&i : v) {
    int b = i;
    if (b <= a)
      break;
    if (b > a) {
      cou = cou + b / a - (b % a == 0);
    }
  }
  // cout << a << ":" << cou << endl;
  if (cou > K)
    return false;
  else
    return true;
}
int main() {
  cin >> N >> K;
  for (int i = 0; i < N; ++i) {
    int a;
    cin >> a;
    v.push_back(a);
    M = max(M, a);
  }
  sort(v.begin(), v.end(), greater<int>());
  while (M - m > 1) {
    int k = (M + m) / 2;
    if (able(k))
      M = k;
    else
      m = k;
  }
  cout << M << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
#define NMAX 200002
using namespace std;
vector<int> v;
int N, K, M = 0, m = 0, ans = 0;
bool able(int a) {
  int cou = 0;
  for (auto &&i : v) {
    int b = i;
    if (b <= a)
      break;
    while (true) {
      if (b > a) {
        b = b - a;
        cou++;
      } else {
        break;
      }
    }
  }
  // cout << a << ":" << cou << endl;
  if (cou > K)
    return false;
  else
    return true;
}
int main() {
  cin >> N >> K;
  for (int i = 0; i < N; ++i) {
    int a;
    cin >> a;
    v.push_back(a);
    M = max(M, a);
  }
  sort(v.begin(), v.end(), greater<int>());
  while (M - m > 1) {
    int k = (M + m) / 2;
    if (able(k))
      M = k;
    else
      m = k;
  }
  cout << M << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

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

bool check(int mid, vector<int> &a, int k) {
  int n = a.size();
  int cnt = 0;
  rep(i, n) cnt += (a[i] - 1) / mid;
  return (cnt <= k);
}

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  int ok = 1e9, ng = 0;
  while (abs(ok - ng) > 1) {
    int mid = (ok + ng) / 2;
    if (check(mid, a, k))
      ok = mid;
    else
      ng = mid;
  }
  cout << ok << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

bool check(int mid, vector<int> &a, int k) {
  int n = a.size();
  priority_queue<double> que;
  // bool ret = false;
  rep(i, n) que.push(a[i]);
  rep(i, k) {
    double p = que.top();
    que.pop();
    que.push(mid);
    que.push(p - mid);
  }

  return (que.top() <= mid);
}

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  int ok = 1e9, ng = 0;
  while (abs(ok - ng) > 1) {
    int mid = (ok + ng) / 2;
    if (check(mid, a, k))
      ok = mid;
    else
      ng = mid;
  }
  cout << ok << endl;

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

#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
// #define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout << x << endl;
#define repi(i, x, n) for (int i = x; i < n; i++)
#define rep(i, n) repi(i, 0, n)
#define lp(i, n) repi(i, 0, n)
#define repn(i, n) for (int i = n; i >= 0; i--)
#define int long long
#define endl "\\n"

typedef pair<int, int> PII;
typedef pair<int, string> PIS;
typedef pair<string, int> PSI;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  int a[n];
  rep(i, n) cin >> a[i];
  sort(a, a + n);
  rep(i, n) {
    // cout<<a[i]<<" ";
  }
  // cout<<endl;
  int l = 1, r = 1000000000;
  int mid = (l + r) / 2;
  while (l != r) {
    int cnt = 0;
    rep(i, n) {
      // cout<<(a[i]+mid-1)/mid<<" ";
      cnt += (a[i] + mid - 1) / mid;
      cnt--;
    }
    // cout<<endl;
    // cout<<mid<<" "<<cnt<<endl;
    if (cnt > k)
      l = mid + 1;
    else
      r = mid;
    mid = (r + l) / 2;
  }
  cout << min(mid, a[n - 1]) << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
// #define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout << x << endl;
#define repi(i, x, n) for (int i = x; i < n; i++)
#define rep(i, n) repi(i, 0, n)
#define lp(i, n) repi(i, 0, n)
#define repn(i, n) for (int i = n; i >= 0; i--)
#define int long long
#define endl "\\n"

typedef pair<int, int> PII;
typedef pair<int, string> PIS;
typedef pair<string, int> PSI;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  int a[n];
  rep(i, n) cin >> a[i];
  sort(a, a + n);
  rep(i, n) {
    // cout<<a[i]<<" ";
  }
  // cout<<endl;
  int l = 0, r = 1000000000;
  int mid = (l + r) / 2;
  while (l != r) {
    int cnt = 0;
    rep(i, n) {
      // cout<<(a[i]+mid-1)/mid<<" ";
      cnt += (a[i] + mid - 1) / mid;
      cnt--;
    }
    // cout<<endl;
    // cout<<mid<<" "<<cnt<<endl;
    if (cnt > k)
      l = mid + 1;
    else
      r = mid;
    mid = (r + l) / 2;
  }
  cout << min(mid, a[n - 1]) << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

typedef long long int lli;

lli bs(lli l, lli r, const vector<lli> &logs, const lli K) {
  if (l > r)
    return l;
  lli mid = (l + r) / 2;
  lli k = K;
  for (int i = 0; i < logs.size(); i++) {
    lli x = 0;
    if (logs[i] > mid) {
      if ((logs[i] % mid) == 0)
        x = logs[i] / mid - 1;
      else
        x = logs[i] / mid;
      k -= x;
      if (k < 0)
        return bs(mid + 1, r, logs, K);
    }
  }
  if (k >= 0)
    return bs(l, mid - 1, logs, K);
}

int main() {
  //	while(cin){

  int N = 0;
  lli K = 0;
  lli Ai = 0;
  lli sum = 0;
  lli max = 0;
  vector<lli> logs;
  cin >> N >> K;
  while (N--) {
    cin >> Ai;
    logs.push_back(Ai);
    sum += Ai;
    if (Ai > max)
      max = Ai;
  }
  N = logs.size();
  lli min_possible = 0;
  lli max_possible = 0;

  if (N > 1)
    min_possible = ceil(sum / (K + N - 1));

  else if (K > 0)
    min_possible = ceil(sum / (K + 1));

  else
    min_possible = sum;

  if (min_possible > max)
    min_possible = max;
  if (min_possible == 0)
    min_possible = 1;
  max_possible = max;
  //	cout << "sum: " << sum << "   " << "min_possible: " << min_possible << "
  //max_possible: " << max_possible << endl;

  cout << bs(min_possible, max_possible, logs, K) << endl;
  //}
  return 0;
}

Error: 0

Fixed submission:

#include <cmath>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

typedef unsigned long long int lli;

void print(const vector<lli> &v) {
  for (int i = 0; i < v.size() - 1; i++)
    cout << v[i] << " ";
  cout << v[v.size() - 1] << "\\n";
}

lli bs(lli l, lli r, const vector<lli> &logs, const long long K) {
  if (l > r)
    return l;
  lli mid = (l + r) / 2;
  long long k = K;
  for (int i = 0; i < logs.size(); i++) {
    lli x = 0;
    if (logs[i] > mid) {
      if ((logs[i] % mid) == 0)
        x = logs[i] / mid - 1;
      else
        x = logs[i] / mid;
      k -= x;
      if (k < 0)
        return bs(mid + 1, r, logs, K);
    }
  }
  if (k >= 0)
    return bs(l, mid - 1, logs, K);
}

int main() {
  //	while(cin){

  int N = 0;
  long long K = 0;
  lli Ai = 0;
  lli sum = 0;
  lli max = 0;
  vector<lli> logs;
  cin >> N >> K;
  while (N--) {
    cin >> Ai;
    logs.push_back(Ai);
    sum += Ai;
    if (Ai > max)
      max = Ai;
  }
  N = logs.size();
  lli min_possible = 0;
  lli max_possible = 0;

  if (N > 1)
    min_possible = ceil(sum / (K + N - 1));

  else if (K > 0)
    min_possible = ceil(sum / (K + 1));

  else
    min_possible = sum;

  if (min_possible > max)
    min_possible = max;
  max_possible = max;
  //	cout << "sum: " << sum << "   " << "min_possible: " << min_possible << "
  //max_possible: " << max_possible << endl;

  cout << bs(min_possible, max_possible, logs, K) << endl;
  //}
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

/**
 * @author: Mackenzie
 **/

#include <bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define pb push_back
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAX = 2e5 + 5;
int A[MAX];
int n, k;

int check(int x) {
  int cnt = 0;
  forn(i, n) {
    if (A[i] > x)
      cnt += A[i] / x;
  }
  return cnt;
}
int main() {
#ifdef LOCAL
  freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
#else
  fastIO;
#endif
  cin >> n >> k;
  forn(i, n) cin >> A[i];
  sort(A, A + n);
  int lo = 1, hi = 1e9;
  forn(it, 70) {
    int m = (lo + hi) / 2;
    // cout << m << endl;
    if (check(m) <= k)
      hi = m;
    else
      lo = m;
  }
  cout << hi << endl;
  return 0;
}


Error: 0

Fixed submission:

/**
 * @author: Mackenzie
 **/

#include <bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define pb push_back
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAX = 2e5 + 5;
int A[MAX];
int n, k;

int check(int x) {
  int cnt = 0;
  forn(i, n) {
    if (A[i] > x)
      cnt += A[i] / x;
  }
  return cnt;
}
int main() {
#ifdef LOCAL
  freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
#else
  fastIO;
#endif
  cin >> n >> k;
  forn(i, n) cin >> A[i];
  sort(A, A + n);
  int lo = 0, hi = 1e9;
  forn(it, 70) {
    int m = (lo + hi) / 2;
    // cout << m << endl;
    if (check(m) <= k)
      hi = m;
    else
      lo = m;
  }
  cout << hi << endl;
  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<int, int> pii;
typedef pair<ll, ll> pll;
ll n, k, v[200001], minim = 1e10;
bool ok(ll val) {
  ll x = val;
  ll nrop = 0;
  for (int i = 1; i <= n; i++) {
    ll bc = v[i] / x;
    if (v[i] % x)
      bc++;
    nrop += bc - 1;
  }
  return nrop <= k;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++)
    cin >> v[i];
  ll st = 1;
  ll dr = 1e9;
  while (st <= dr) {
    ll mij = (st + dr) / 2;
    if (ok(mij)) {
      minim = min(mij, minim);
      dr = mij - 1;
    } else
      st = mij + 1;
  }
  cout << minim;
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll n, k, v[200001], minim = 1e10;
bool ok(ll val) {
  ll x = val;
  ll nrop = 0;
  for (int i = 1; i <= n; i++) {
    ll bc = v[i] / x;
    if (v[i] % x)
      bc++;
    nrop += bc - 1;
  }
  return nrop <= k;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++)
    cin >> v[i];
  ll st = 0;
  ll dr = 1e9;
  while (st <= dr) {
    ll mij = (st + dr) / 2;
    if (ok(mij)) {
      minim = min(mij, minim);
      dr = mij - 1;
    } else
      st = mij + 1;
  }
  cout << minim;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
namespace mp = boost::multiprecision; // int64_tは9*10^18まで、intは2*10^9まで

#define INF (int)pow(10, 8)
typedef tuple<int, int, int> P;

int main() {
  int n, k;
  cin >> n >> k;
  int a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a + n);
  int ans = a[n - 1];
  double l = 0, r = a[n - 1], mid;
  while (r - l > 0.000005) {
    mid = (l + r) / 2;
    int tmp = 0;
    for (int i = 0; i < n; i++) {
      tmp += floor((a[i] - 1) / mid);
    }
    if (tmp <= k) {
      r = mid;
      ans = ceil(mid);
    } else {
      l = mid;
    }
  }
  cout << ans;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int n, k;
  cin >> n >> k;
  tuple<int, int, int> a;
  get<1>(a) = 0;
  priority_queue<tuple<int, int, int>> p;
  for (int i = 0; i < n; i++) {
    cin >> get<0>(a);
    get<2>(a) = get<0>(a);
    p.push(a);
  }
  for (int i = 0; i < k; i++) {
    a = p.top();
    get<1>(a)++;
    get<0>(a) = ceil(get<2>(a) / (1.0 * (1 + get<1>(a))));
    p.pop();
    p.push(a);
  }
  a = p.top();
  cout << int(ceil(get<2>(a) / (1.0 * (1 + get<1>(a)))));
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  ll N;
  cin >> N;
  ll K;
  cin >> K;
  vector<ll> A(N);
  for (ll i = 0; i < N; i++)
    cin >> A[i];

  if (K == 0) {
    ll ans = *max_element(A.begin(), A.end());
    cout << ans << '\\n';
    return 0;
  }

  double l = 0.0000005, r = 1e9 + 1.0;
  while (r - l > 0.0000005) {
    double m = (r + l) / 2.0;
    ll cnt = 0;
    for (ll i = 0; i < N; i++) {
      cnt += A[i] / m;
    }
    if (cnt <= K)
      r = m;
    else
      l = m;
  }

  ll temp = max((ll)1, (ll)ceil(l) - 10);
  ll ans = 1;
  for (ll i = temp; i < temp + 20; i++) {
    ll cnt = 0;
    for (ll j = 0; j < N; j++) {
      cnt += A[j] / i;
      if (A[j] % i == 0)
        cnt--;
    }
    if (cnt <= K) {
      ans = i;
      break;
    }
  }
  cout << ans << '\\n';
  return 0;
}

Error: TLE

Fixed submission:

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

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

  ll N;
  cin >> N;
  ll K;
  cin >> K;
  vector<ll> A(N);
  for (ll i = 0; i < N; i++)
    cin >> A[i];

  if (K == 0) {
    ll ans = *max_element(A.begin(), A.end());
    cout << ans << '\\n';
    return 0;
  }

  double l = 0.00000005, r = 1e9 + 1.0;
  while (r - l > 0.00000005) {
    double m = (r + l) / 2.0;
    ll cnt = 0;
    for (ll i = 0; i < N; i++) {
      cnt += A[i] / m;
    }
    if (cnt <= K)
      r = m;
    else
      l = m;
  }

  ll temp = max((ll)1, (ll)ceil(l) - 10);
  ll ans = 1;
  for (ll i = temp; i < temp + 20; i++) {
    ll cnt = 0;
    for (ll j = 0; j < N; j++) {
      cnt += A[j] / i;
    }
    if (cnt <= K) {
      ans = i;
      break;
    }
  }
  cout << ans << '\\n';
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#include "_DEBUG.hpp"
#endif
#define int long long
const int INF = 1LL << 60;

signed main() {

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

  auto f = [&](double x) {
    int cnt = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] % (int)(x + 0.5) == 0)
        cnt += a[i] / (int)(x + 0.5) - 1;
      else
        cnt += a[i] / (int)(x + 0.5);
    }
    return cnt;
  };

  int ans = INF;
  double left = 1, right = 1e9;
  while (right - left > 1e-2) {
    double mid = (left + right) / 2;
    int cnt = f(mid);
    (cnt <= k ? right : left) = mid;
    if (cnt <= k)
      ans = min(ans, (int)(mid + 0.5));
  }
  if (ans == INF)
    ans = 1;
  cout << ans << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#include "_DEBUG.hpp"
#endif
#define int long long
const int INF = 1LL << 60;

signed main() {

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

  auto f = [&](double x) {
    int cnt = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] % (int)(x + 0.5) == 0)
        cnt += a[i] / (int)(x + 0.5) - 1;
      else
        cnt += a[i] / (int)(x + 0.5);
    }
    return cnt;
  };

  int ans = INF;
  double left = 0, right = 1e9;
  while (right - left > 1e-2) {
    double mid = (left + right) / 2;
    int cnt = f(mid);
    (cnt <= k ? right : left) = mid;
    if (cnt <= k)
      ans = min(ans, (int)(mid + 0.5));
  }
  cout << ans << endl;

  return 0;
}