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

#include "bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> arr(n);
  rep(i, n) cin >> arr[i];
  int l = 0, r = 1e9;
  while (r - l > 1) {
    int m = (l + r) / 2;
    auto cut = [&](int m) {
      ll cnt = 0;
      rep(i, n) cnt += (arr[i] - 1) / m;
      return cnt <= k;
    };
    if (cut(m))
      r = m;
    else
      l = m;
  }
  cout << r << endl;
  return 0;
}


Error: WA

Fixed submission:

#include "bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> arr(n);
  rep(i, n) cin >> arr[i];
  int l = 0, r = 1e9;
  while (r - l > 1) {
    int m = (l + r) / 2;
    auto cut = [&](int m) {
      ll cnt = 0;
      rep(i, n) cnt += (arr[i] - 1) / k;
      return cnt <= k;
    };
    if (cut(m))
      r = m;
    else
      l = m;
  }
  cout << r << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
const int nax = 2e5 + 5;
int a[nax];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  int L = 0, R = 1e9 + 1, ans = a[n - 1];
  while (R - L > 1) {
    int mid = L + (R - L) / 2;
    long long reqd = 0;
    for (int i = 0; i < n; i++) {
      if (reqd > k)
        break;
      reqd += ((a[i] + mid - 1) / mid) - 1;
    }
    if (reqd <= k) {
      ans = mid;
      R = mid;
    } else {
      L = mid;
    }
  }
  cout << ans << '\\n';
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
const int nax = 2e5 + 5;
int a[nax];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  int L = 0, R = a[n - 1], ans = R;
  while (L <= R) {
    int mid = (L + R) / 2;
    int reqd = 0;
    for (int i = 0; i < n; i++) {
      reqd += ceil((a[i] - 1) / mid);
    }
    if (reqd <= k) {
      ans = mid;
      R = mid - 1;
    } else
      L = mid + 1;
  }
  cout << ans << '\\n';
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stdio.h>
#include <string>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define repn(i, n) for (int i = 1; i <= n; i++)
#define repr(e, x) for (auto &e : x)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<double, int> P;
// ll const INF=1001001001;
// ll const INF=1001001001001001001;
ll const MOD = 1000000007;

int N, K;
int A[200000];

int cut(int X) {
  int res = 0;
  rep(i, N) res += (A[i] - 1) / X;
  return res;
}

int main() {
  cin >> N >> K;
  rep(i, N) cin >> A[i];

  int l = 0, r = 1000000000;
  while (r - l > 1) {
    int X = (l + r) / 2;
    int cnt = cut(X);
    if (cnt <= K)
      r = X;
    else
      l = X;
  }

  int ans = r;
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stdio.h>
#include <string>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define repn(i, n) for (int i = 1; i <= n; i++)
#define repr(e, x) for (auto &e : x)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<double, int> P;
// ll const INF=1001001001;
// ll const INF=1001001001001001001;
ll const MOD = 1000000007;

int N, K;
double A[200000];
int cnt[200000];

int main() {
  cin >> N >> K;
  rep(i, N) cin >> A[i];

  priority_queue<P> q;
  rep(i, N) q.push(P(A[i], i));

  rep(i, K) {
    P p = q.top();
    q.pop();
    cnt[p.second]++;
    q.push(P(A[p.second] / (cnt[p.second] + 1), p.second));
  }

  int ans = ceil(q.top().first);
  cout << ans << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#define IL inline
#define reg register
#define LL long long
#define N 500010
#define EPS 1e-5
using namespace std;

LL T, n, i, j, k, x, y, z;
LL a[N], b[N];

LL l, r, mid, ans;

IL bool Check(LL x) {
  reg LL i = 0, s = 0, p = 0;
  for (i = 1; i <= n; i++) {
    if (a[i] <= x)
      continue;
    p = (LL)(a[i] / x);
    if (a[i] > p * x)
      s += p;
    else
      s += p - 1;
  }
  if (s <= k)
    return 1;
  else
    return 0;
}

int main() {
#ifdef __Marvolo
  freopen("zht.in", "r", stdin);
  freopen("zht.out", "w", stdout);
#endif
  scanf("%lld%lld", &n, &k);
  for (i = 1; i <= n; i++)
    scanf("%lld", &a[i]);
  for (i = 1; i <= n; i++)
    a[i] *= 2;
  sort(a + 1, a + 1 + n);
  a[0] = 0;
  for (i = 1; i <= n; i++)
    a[0] += a[i];
  /*	if (a[0]<=k){
                  cout<<"0"<<endl;
                  return 0;
          }
          if (a[0]-n <=k ){
                  cout<<"1"<<endl;
                  return 0;
          }*/
  if (!k) {
    printf("%lld\\n", a[n] / 2);
    return 0;
  }
  l = 1;
  r = a[n] * 2;
  while (l <= r) {
    mid = (l + r) >> 1;
    if (Check(mid))
      ans = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  while (ans > 1 && Check(ans - 1))
    ans--;
  while (!Check(ans))
    ans++;
  if (ans & 1)
    cout << (ans + 1) / 2 << endl;
  else
    cout << ans / 2 << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#define IL inline
#define reg register
#define LL long long
#define N 500010
#define EPS 1e-5
using namespace std;

LL T, n, i, j, k, x, y, z;
LL a[N], b[N];

LL l, r, mid, ans;

IL bool Check(LL x) {
  reg LL i = 0, s = 0, p = 0;
  for (i = 1; i <= n; i++) {
    if (a[i] <= x)
      continue;
    p = (LL)(a[i] / x);
    if (a[i] > p * x)
      s += p;
    else
      s += p - 1;
  }
  if (s <= k)
    return 1;
  else
    return 0;
}

int main() {
#ifdef __Marvolo
  freopen("zht.in", "r", stdin);
  freopen("zht.out", "w", stdout);
#endif
  scanf("%lld%lld", &n, &k);
  for (i = 1; i <= n; i++)
    scanf("%lld", &a[i]);
  sort(a + 1, a + 1 + n);
  for (i = 1; i <= n; i++)
    a[i] *= 2;
  if (!k) {
    cout << a[n] / 2 << endl;
    return 0;
  }
  l = 0;
  r = a[n] * 2;
  while (l <= r) {
    mid = (l + r) >> 1;
    if (Check(mid))
      ans = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  while (ans > 1 && Check(ans - 1))
    ans--;
  while (!Check(ans))
    ans++;
  if (ans & 1)
    cout << (ans + 1) / 2 << endl;
  else
    cout << ans / 2 << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using pll = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(i) begin(i), end(i)

const int INF = 0x3fffffff;
const ll MINF = 0x7fffffffffff;
const ld DINF = numeric_limits<ld>::infinity();
const int MOD = 1000000007;
const int MODD = 998244353;
const ld EPS = 1e-9;
const ld PI = 3.1415926535897932;

template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  } else
    return 0;
}
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  } else
    return 0;
}
template <class T> auto min(const T &a) { return *min_element(all(a)); }
template <class T> auto max(const T &a) { return *max_element(all(a)); }

ll gcd(ll a, ll b) {
  while (b) {
    ll c = b;
    b = a % b;
    a = c;
  }
  return a;
}
ll lcm(ll a, ll b) {
  if (!a || !b)
    return 0;
  return a * b / gcd(a, b);
}
ll pow_mod(ll n, ll k, ll m) {
  ll r = 1;
  for (; k > 0; k >>= 1) {
    if (k & 1)
      r = (r * n) % m;
    n = (n * n) % m;
  }
  return r;
}

// ここから。
int main() {
  ll n, k;
  cin >> n >> k;
  ll a[n];
  rep(i, n) cin >> a[i];

  ll ok = 1e9; // 解が存在する値
  ll ng = 0;   // 解が存在しない値

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

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using pll = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(i) begin(i), end(i)

const int INF = 0x3fffffff;
const ll MINF = 0x7fffffffffff;
const ld DINF = numeric_limits<ld>::infinity();
const int MOD = 1000000007;
const int MODD = 998244353;
const ld EPS = 1e-9;
const ld PI = 3.1415926535897932;

template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  } else
    return 0;
}
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  } else
    return 0;
}
template <class T> auto min(const T &a) { return *min_element(all(a)); }
template <class T> auto max(const T &a) { return *max_element(all(a)); }

ll gcd(ll a, ll b) {
  while (b) {
    ll c = b;
    b = a % b;
    a = c;
  }
  return a;
}
ll lcm(ll a, ll b) {
  if (!a || !b)
    return 0;
  return a * b / gcd(a, b);
}
ll pow_mod(ll n, ll k, ll m) {
  ll r = 1;
  for (; k > 0; k >>= 1) {
    if (k & 1)
      r = (r * n) % m;
    n = (n * n) % m;
  }
  return r;
}

// ここから。
int main() {
  int n, k;
  cin >> n >> k;
  int a[n];
  rep(i, n) cin >> a[i];

  int ok = 1e9; // 解が存在する値
  int ng = -1;  // 解が存在しない値

  while (abs(ok - ng) > 1) {
    int mid = (ok + ng) / 2;
    ll 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

// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() { cout << endl; }
template <typename First, typename... Rest>
void print(const First &first, const Rest &...rest) {
  cout << first << ' ';
  print(rest...);
}

template <typename T> void print(const vector<T> &v) {
  for (auto e : v)
    cout << e << ' ';
  cout << endl;
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

long long N, K;
vector<long long> A;

bool isOK(long long mid) {
  long long k = 0;
  for (int i = 0; i < N; i++) {
    k += (A[i] - 1) / mid;
  }
  if (k <= K)
    return true;
  else
    return false;
}

void solve() {
  cin >> N >> K;
  A.resize(N);
  long long ma = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    ma = max(ma, A[i]);
  }

  long long ok = ma;
  long long ng = 0;

  while (abs(ok - ng) > 1) {
    long long mid = (ok + ng) / 2;
    if (isOK(mid))
      ok = mid;
    else
      ng = mid;
  }

  cout << ok << '\\n';
}

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

  solve();

  return 0;
}

Error: 0

Fixed submission:

// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() { cout << endl; }
template <typename First, typename... Rest>
void print(const First &first, const Rest &...rest) {
  cout << first << ' ';
  print(rest...);
}

template <typename T> void print(const vector<T> &v) {
  for (auto e : v)
    cout << e << ' ';
  cout << endl;
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

long long N, K;
vector<long long> A;

bool isOK(long long mid) {
  long long k = 0;
  for (int i = 0; i < N; i++) {
    k += (A[i] - 1) / mid;
  }
  if (k <= K)
    return true;
  else
    return false;
}

void solve() {
  cin >> N >> K;
  A.resize(N);
  long long ma = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    ma = max(ma, A[i]);
  }

  long long ok = ma;
  long long ng = -1;

  while (abs(ok - ng) > 1) {
    long long mid = (ok + ng) / 2;
    if (isOK(mid))
      ok = mid;
    else
      ng = mid;
  }

  cout << ok << '\\n';
}

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

  solve();

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

#include <bits/stdc++.h>
#include <chrono>
#include <math.h>
using namespace std;
using ll = long long;
using ld = long double;
using namespace std::chrono;
#define fo(i, z, n) for (int i = z; i < n; i++)
#define Fo(i, z, n) for (ll i = z; i < n; i++)
#define INT_BITS 32
#define mod 1000000007
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define pb push_back
#define f first
// #define s second
#define int long long
#define all(c) (c).begin(), (c).end()
#define endl '\\n'
// auto start = high_resolution_clock::now();
// auto stop = high_resolution_clock::now();
// auto duration = duration_cast<microseconds>(stop - start);

// cout << duration.count() << endl;

bool check(int *arr, int mid, int k, int n) {
  int r = 0;
  fo(i, 0, n) {
    r += (arr[i] + mid - 1) / mid;
    r--;
  }
  if (r <= k)
    return true;
  else
    return false;
}

int32_t main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);
  // int t;
  // cin >> t;

  // while(t--){

  // }

  int n, k;
  cin >> n >> k;
  int arr[n];
  fo(i, 0, n) cin >> arr[i];
  sort(arr, arr + n);

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

  cout << ans << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <chrono>
#include <math.h>
using namespace std;
using ll = long long;
using ld = long double;
using namespace std::chrono;
#define fo(i, z, n) for (int i = z; i < n; i++)
#define Fo(i, z, n) for (ll i = z; i < n; i++)
#define INT_BITS 32
#define mod 1000000007
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define pb push_back
#define f first
// #define s second
#define int long long
#define all(c) (c).begin(), (c).end()
#define endl '\\n'
// auto start = high_resolution_clock::now();
// auto stop = high_resolution_clock::now();
// auto duration = duration_cast<microseconds>(stop - start);

// cout << duration.count() << endl;
int ceil(int a, int b) {
  if (a % b == 0)
    return a / b;
  else
    return a / b + 1;
}

bool check(int *arr, int mid, int k, int n) {
  int r = 0;
  fo(i, 0, n) { r += ceil(arr[i], mid) - 1; }
  if (r <= k)
    return true;
  else
    return false;
}

int32_t main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);
  // int t;
  // cin >> t;

  // while(t--){

  // }

  int n, k;
  cin >> n >> k;
  int arr[n];
  fo(i, 0, n) cin >> arr[i];
  sort(arr, arr + n);

  int l = 0;
  int r = mod;
  int ans = -1;
  while (l < r) {
    int mid = (l + r) / 2;
    // cout << mid << endl;
    if (check(arr, mid, k, n)) {
      ans = mid;
      r = mid;
    } else
      l = mid + 1;
  }

  cout << ans << endl;

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

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
using namespace std;

typedef long long ll;
typedef double db;
typedef long double ldb;

template <class T> inline void checkmin(T &a, const T &b) {
  if (b < a)
    a = b;
}
template <class T> inline void checkmax(T &a, const T &b) {
  if (b > a)
    a = b;
}

const int inf = 1e9 + 10;
const int maxn = 2e5 + 10;

ll n, k;
ll a[maxn];

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

int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int low = 1, high = inf;
  while (low < high) {
    int mid = (low + high) >> 1;
    if (check(mid) > k)
      low = mid + 1;
    else
      high = mid;
  }
  printf("%d\\n", high);
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
using namespace std;

typedef long long ll;
typedef double db;
typedef long double ldb;

template <class T> inline void checkmin(T &a, const T &b) {
  if (b < a)
    a = b;
}
template <class T> inline void checkmax(T &a, const T &b) {
  if (b > a)
    a = b;
}

const int inf = 1e9 + 10;
const int maxn = 2e5 + 10;

ll n, k;
ll a[maxn];

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

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


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mod 1000000007
#define all(v) v.begin(), v.end()
#define pb push_back
#define size(v) (int)v.size()
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
ll power_mod(ll a, ll x) {
  if (x == 0)
    return 1;
  ll y = power_mod(a, x / 2);
  ll ans = (y * y) % mod;
  if (x % 2)
    ans = (ans * a) % mod;
  return ans;
}
ll inv(ll a) { return power_mod(a, mod - 2); }
ll power(ll a, ll x) {
  if (x == 0)
    return 1;
  ll y = power(a, x / 2);
  ll ans = (y * y);
  if (x % 2)
    ans *= a;
  return ans;
}

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

  vector<ll> a(n, 0);

  for (ll i = 0; i < n; i++) {
    cin >> a[i];
  }

  ll lo = 0, hi = 1000000000;
  ll ans = hi;

  while (lo <= hi) {
    ll mid = (lo + hi) / 2;
    if (mid == 0) {
      if (lo == hi) {
        break;
      }
      mid = 1;
    }
    ll cut_req = 0;
    for (auto i : a) {
      ll curr = i;
      if (curr < mid)
        continue;
      cut_req += ((curr - 1) / mid);
    }
    // printf("%0.9lf ",mid);
    // cout << cut_req << endl;
    if (cut_req > k) {
      lo = mid + 1;
    } else {
      ans = min(ans, mid);
      hi = mid - 1;
    }
  }
  ll res = ans;
  // printf("%0.9lf\\n",ans);
  cout << res << endl;
}

Error: 0

Fixed submission:


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mod 1000000007
#define all(v) v.begin(), v.end()
#define pb push_back
#define size(v) (int)v.size()
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
ll power_mod(ll a, ll x) {
  if (x == 0)
    return 1;
  ll y = power_mod(a, x / 2);
  ll ans = (y * y) % mod;
  if (x % 2)
    ans = (ans * a) % mod;
  return ans;
}
ll inv(ll a) { return power_mod(a, mod - 2); }
ll power(ll a, ll x) {
  if (x == 0)
    return 1;
  ll y = power(a, x / 2);
  ll ans = (y * y);
  if (x % 2)
    ans *= a;
  return ans;
}

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

  vector<ll> a(n, 0);

  for (ll i = 0; i < n; i++) {
    cin >> a[i];
  }

  ll lo = 0, hi = 1000000000;
  ll ans = hi;

  while (lo <= hi) {
    ll mid = (lo + hi) / 2;
    if (mid == 0) {
      if (lo == hi) {
        break;
      }
      lo = 1;
    }
    ll cut_req = 0;
    for (auto i : a) {
      ll curr = i;
      if (curr < mid)
        continue;
      cut_req += ((curr - 1) / mid);
    }
    // printf("%0.9lf ",mid);
    // cout << cut_req << endl;
    if (cut_req > k) {
      lo = mid + 1;
    } else {
      ans = min(ans, mid);
      hi = mid - 1;
    }
  }
  ll res = ans;
  // printf("%0.9lf\\n",ans);
  cout << res << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;

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

  int left = 0;
  int right = INF;

  while (right - left > 1) {
    int mid = (right + left) / 2;

    ll num = 0;
    for (int i = 0; i < n; ++i) {
      if (a[i] % mid == 0)
        num += a[i] / mid - 1;
      else
        num += a[i] / mid;
    }
    if (num <= k)
      right = mid;
    else
      left = mid;
  }
  cout << right << endl;
}

Error: 0

Fixed submission:

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;

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

  int left = -1;
  int right = INF;

  while (right - left > 1) {
    int mid = (right + left) / 2;

    ll num = 0;
    for (int i = 0; i < n; ++i) {
      if (a[i] % mid == 0)
        num += a[i] / mid - 1;
      else
        num += a[i] / mid;
    }
    if (num <= k)
      right = mid;
    else
      left = mid;
  }
  cout << right << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define N (1000000000 + 7)
// #define N 998244353
#define INF 1e16
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> Q;

const int inf = (int)1e9;

ll gcd(ll a, ll b) {
  if (b > a) {
    ll tmp = b;
    b = a;
    a = tmp;
  }
  if (a % b == 0)
    return b;
  else
    return gcd(b, a % b);
}

ll n, k;
vector<ll> a(n);

bool check(ll x) {
  ll t = 0;
  if (x == 0) {
    return false;
  }
  for (int i = 0; i < n; i++) {
    if (a[i] % x == 0)
      t += a[i] / x - 1;
    else
      t += a[i] / x;
  }
  return (t <= k);
}

int main(void) {
  n, k;
  cin >> n >> k;
  a.resize(n);
  ll ng = -1, ok = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    ok = max(ok, a[i]);
  }
  while (ok - ng > 1) {
    ll mid = (ok + ng) / 2;
    if (check(mid))
      ok = mid;
    else
      ng = mid;
  }
  cout << ok << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define N (1000000000 + 7)
// #define N 998244353
#define INF 1e16
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> Q;

const int inf = (int)1e9;

ll gcd(ll a, ll b) {
  if (b > a) {
    ll tmp = b;
    b = a;
    a = tmp;
  }
  if (a % b == 0)
    return b;
  else
    return gcd(b, a % b);
}

ll n, k;
vector<ll> a(n);

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

int main(void) {
  n, k;
  cin >> n >> k;
  a.resize(n);
  ll ng = -1, ok = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    ok = max(ok, a[i]);
  }
  while (ok - ng > 1) {
    ll mid = (ok + ng) / 2;
    if (check(mid))
      ok = mid;
    else
      ng = mid;
  }
  cout << ok << endl;
  return 0;
}