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

#include <bits/stdc++.h>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>

using namespace std;
using namespace __gnu_pbds;

#define endl '\\n'

typedef long long ll;
typedef pair<int, int> pii;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);

  int n;
  ll k;

  cin >> n >> k;

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

  ll lo = 1, hi = 2e9, opt = -1;
  while (lo <= hi) {
    ll mid = (lo + hi) >> 1, sum = 0;

    for (int i = 0; i < n; i++)
      sum += (a[i] + mid - 1) / mid - 1;

    if (sum <= k) {
      opt = mid;
      hi = mid - 1;
    } else
      lo = mid + 1;
  }

  cout << opt << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>

using namespace std;
using namespace __gnu_pbds;

#define endl '\\n'

typedef long long ll;
typedef pair<int, int> pii;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);

  int n;
  ll k;

  cin >> n >> k;

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

  ll lo = 0, hi = 2e9, opt = -1;
  while (lo <= hi) {
    ll mid = (lo + hi) >> 1, sum = 0;

    for (int i = 0; i < n; i++)
      sum += (a[i] + mid - 1) / mid - 1;

    if (sum <= k) {
      opt = mid;
      hi = mid - 1;
    } else
      lo = mid + 1;
  }

  cout << opt << endl;

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

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

#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define ALL(c) (c).begin(), (c).end()

// 区間[a, b)の中で最初に pred(x) = true となるような x を返す。
// そのような x が存在しないときは b を返す。
template <class Pred> int64_t bin_search(int64_t a, int64_t b, Pred pred) {
  // 不変条件: i<a ⇒ pred(i) = false, i>=b ⇒ pred(i) = true
  if (a == b)
    return b;
  int64_t m = a + (b - a) / 2;
  if (pred(m))
    return bin_search(a, m, pred);
  else
    return bin_search(m + 1, b, pred);
}

inline int64_t div_ceil(int64_t a, int64_t b) noexcept {
  return (a + b - 1) / b;
}

int main() {
  int N;
  cin >> N;
  int64_t K;
  cin >> K;
  vector<int64_t> A(N);
  REP(i, N) cin >> A[i];

  int64_t S = 0;
  REP(i, N) S += A[i];

  int64_t ans = bin_search(1, S + 1, [&](int64_t L) {
    // 最大の丸太の長さが L 以下になるように切ることができるか
    int64_t k = 0;
    REP(i, N) k += div_ceil(A[i], L) - 1;
    return k <= K;
  });
  cout << ans << '\\n';
}


Error: 0

Fixed submission:

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

#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define ALL(c) (c).begin(), (c).end()

// 区間[a, b)の中で最初に pred(x) = true となるような x を返す。
// そのような x が存在しないときは b を返す。
template <class Pred> int64_t bin_search(int64_t a, int64_t b, Pred pred) {
  // 不変条件: i<a ⇒ pred(i) = false, i>=b ⇒ pred(i) = true
  if (a == b)
    return b;
  int64_t m = a + (b - a) / 2;
  if (pred(m))
    return bin_search(a, m, pred);
  else
    return bin_search(m + 1, b, pred);
}

inline int64_t div_ceil(int64_t a, int64_t b) noexcept {
  return (a + b - 1) / b;
}

int main() {
  int N;
  cin >> N;
  int64_t K;
  cin >> K;
  vector<int64_t> A(N);
  REP(i, N) cin >> A[i];

  int64_t S = 0;
  REP(i, N) S += A[i];

  int64_t ans = bin_search(0, S + 1, [&](int64_t L) {
    // 最大の丸太の長さが L 以下になるように切ることができるか
    int64_t k = 0;
    REP(i, N) k += div_ceil(A[i], L) - 1;
    return k <= K;
  });
  cout << ans << '\\n';
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

#define endl "\\n"
#define lln long long int
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);

vector<lln> logg;
int n, k;

int ok(lln i) {
  int val = 0;
  for (int j = 0; j < n; j++) {
    val += ((logg[j] / i) * (logg[j] != i));
    if (val > k)
      return 0;
  }
  return 1;
}

int main() {
  // IOS;

  cin >> n >> k;
  lln mi = INT64_MIN;
  lln val;
  for (int i = 0; i < n; i++) {
    cin >> val;
    mi = max(val, mi);
    logg.push_back(val);
  }
  lln low = 1, high = mi;
  while (true) {
    if (low == high) {
      cout << low << endl;
      break;
    }
    lln i = (low + high) / 2;
    if (ok(i))
      high = i;
    else {
      if (low + 1 == high) {
        cout << high << endl;
        break;
      }
      low = i;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define endl "\\n"
#define lln long long int
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);

vector<int> logg;
int n, k;

int ok(int i) {
  int val = 0;
  for (int j = 0; j < n; j++) {
    val += ((logg[j] / i) * (logg[j] != i));
    if (val > k)
      return 0;
  }
  return 1;
}

int main() {
  IOS;

  cin >> n >> k;
  for (int i = 0, val; i < n; i++) {
    cin >> val;
    logg.push_back(val);
  }
  sort(logg.begin(), logg.end());
  for (int i = 1;; i++) {
    if (ok(i)) {
      cout << i << endl;
      break;
    }
  }
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

#define bug(x) cerr << #x << " = " << x << '\\n'
#define ll long long
#define maxn 200005

int n, k;
int a[maxn];

bool f(int x) {
  ll cnt = 0;
  for (int i = 1; i <= n; ++i) {
    cnt += (ll)(a[i] - 1LL) / x;
    if (cnt > k)
      return false;
  }
  return cnt <= k;
}

int main() {
  // freopen(".inp","r",stdin);

  cin >> n >> k;

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

  int lo = 0, hi = (int)1e9 + 7;

  while (hi - lo > 1) {
    int mid = (hi + lo) / 2;
    if (f(mid))
      hi = mid;
    else
      lo = mid;
  }
  cout << hi;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int fun(long long int mid, long long int k, vector<int> &arr) {
  long long int ans = 0;
  for (long long int i = 0; i < arr.size(); i++) {
    ans += ((arr[i] + mid - 1) / mid) - 1;
  }
  if (ans >= k)
    return 1;
  return 0;
}
int main() {
  int n;
  long long int k;
  cin >> n >> k;
  vector<int> arr(n);
  for (int i = 0; i < n; i++)
    cin >> arr[i];
  long long int mn = 0;
  long long int mx = 1000000007;
  while (mn <= mx) {
    long long int mid = (mn + mx) / 2;
    if (fun(mid, k, arr))
      mn = mid + 1;
    else
      mx = mid - 1;
  }
  if (fun(mn, k, arr))
    cout << mn;
  else
    cout << mn - 1;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cctype>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

int main() {
  cout << setprecision(16);
  ll n, k;
  cin >> n >> k;
  vector<double> v(n, 0);
  rep(i, n) { cin >> v[i]; }
  ll l = 1;
  ll r = 1e9;

  rep(ii, 1000) {
    ll mid = (l + r) / 2.0;
    ll sum = 0;

    rep(i, n) {
      ll c = v[i];
      if (mid != 0) {
        sum += (c / mid);
        if (c % mid == 0)
          sum--;
      }
    }
    if (sum > k) {
      l = mid;
    } else {
      r = mid;
    }
  }

  cout << r << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

int main() {
  cout << setprecision(16);
  ll n, k;
  cin >> n >> k;
  vector<double> v(n, 0);
  rep(i, n) { cin >> v[i]; }
  ll l = 0;
  ll r = 1e9 + 1;

  rep(ii, 1000) {
    ll mid = (l + r) / 2.0;
    ll sum = 0;

    rep(i, n) {
      ll c = v[i];
      sum += (c / mid);
      if (c % mid == 0)
        sum--;
    }
    if (sum > k) {
      l = mid;
    } else {
      r = mid;
    }
  }

  cout << r << endl;

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

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int n, k;
vector<int> a;

bool f(int m) {
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    cnt += (a[i] - 1) / m;
  }
  return cnt <= k;
}

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

  int ng = 0, ok = 1e9;
  while (ng + 1 < ok) {
    double m = (ng + ok) / 2;
    if (f(m))
      ok = m;
    else
      ng = m;
  }
  cout << ok << endl;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int n, k;
vector<int> a;

bool f(int m) {
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    cnt += (a[i] - 1) / m;
  }
  return cnt <= k;
}

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

  int ng = 0, ok = 1e9;
  for (int i = 0; i < 128; i++) {
    double m = (ng + ok) / 2;
    if (f(m))
      ok = m;
    else
      ng = m;
  }
  cout << ok << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, k, a[200500];

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

void solve() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  ll l = 0, r = 1e9;
  while (r - l > 1) {
    ll mid = l + (r - l) / 2;
    if (check(mid))
      r = mid;
    else
      l = mid;
  }
  cout << r;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t = 1;
  // cin >> t;
  for (int i = 1; i <= t; i++) {
    solve();
  }
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, k, a[200500];

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

void solve() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  ll l = -1, r = 1e9;
  while (r - l > 1) {
    ll mid = l + (r - l) / 2;
    if (check(mid))
      r = mid;
    else
      l = mid;
  }
  cout << r;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t = 1;
  // cin >> t;
  for (int i = 1; i <= t; i++) {
    solve();
  }
}
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 < n; i++)
#define REP(i, n) for (int i = 1; i <= n; i++)
typedef long long ll;

ll n, k;
vector<ll> a;

bool check(ll m) {
  ll count = 0;
  rep(i, n) { count += (a[i] + m - 1) / m - 1; }
  if (count > k)
    return false;
  else
    return true;
}

int main() {
  cin >> n >> k;
  a.resize(n);
  rep(i, n) cin >> a[i];
  ll r = 1e+9;
  ll l = 0;
  while (r - l > 1) {
    ll m = (r + l) / 2;
    if (check(m)) {
      r = m;
    } else {
      l = m;
    }
  }
  cout << r << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

ll n, k;
vector<ll> a;

bool check(ll m) {
  priority_queue<ll> que;
  rep(i, n) { que.push(a[i]); }
  rep(i, k) {
    ll p = que.top();
    que.pop();
    if (p > m) {
      que.push(m);
      que.push(p - m);
    }
  }
  ll max_a = que.top();
  if (max_a > m) {
    return false;
  } else {
    return true;
  }
}

int main() {
  cin >> n >> k;
  a.resize(n);
  rep(i, n) cin >> a[i];
  sort(a.rbegin(), a.rend());
  ll r = 1e+9;
  ll l = 0;
  while (r - l > 1) {
    ll m = (r + l) / 2;
    if (check(m)) {
      r = m;
    } else {
      l = m;
    }
  }
  cout << r << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <boost/dynamic_bitset.hpp>
using namespace std;
using u64 = uint64_t;
using s64 = int64_t;

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

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

  sort(A.begin(), A.end(), greater<u64>());

  u64 h = A[0];
  u64 l = 0;

  while (l + 1 < h) {
    u64 cnt = 0;
    u64 m = l + (h - l) / 2;

    for (u64 i = 0; i < N && cnt <= K; i++) {
      cnt += (A[i] + m - 1) / m - 1;
    }

    if (K >= cnt) {
      h = m;
    } else {
      l = m;
    }
  }

  cout << h << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <boost/dynamic_bitset.hpp>
using namespace std;
using u64 = uint64_t;
using s64 = int64_t;

bool cmp(const pair<u64, u64> &p0, const pair<u64, u64> &p1) {
  return p0.first * p1.second < p1.first * p0.second;
}

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

  priority_queue<pair<u64, u64>, vector<pair<u64, u64>>, decltype(&cmp)> A(
      &cmp);

  for (u64 i = 0; i < N; i++) {
    u64 a;
    cin >> a;
    A.push(make_pair(a, 1));
  }

  for (u64 i = 0; i < K; i++) {
    auto a = A.top();
    A.pop();
    a.second++;
    A.push(a);
  }

  u64 ans = (A.top().first + A.top().second - 1) / A.top().second;
  cout << ans << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <queue>
using namespace std;
// typedef pair<int,int> pii;
#define int long long

int a[200010];

int n, k;
int cal(int x) {
  if (!x)
    return 1e9 + 1;
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    ans = ans + ((a[i] - 1) / x);
  }

  return ans;
}

signed main() {
  scanf("%lld%lld", &n, &k);
  for (int i = 1; i <= n; ++i) {
    scanf("%lld", &a[i]);
  }
  int l = 1, r = 1e9 + 10, mid;
  while (l <= r) {
    mid = (l + r) / 2;
    int f = cal(mid);
    if (f > k)
      l = mid + 1;
    else
      r = mid - 1;
  }
  printf("%lld\\n", l);
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <queue>
using namespace std;
// typedef pair<int,int> pii;
#define int long long

int a[500010];

int n, k;
int cal(int x) {
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (a[i] / x > k - ans) {
      return 1e9;
    }
    ans = ans + (a[i] / x);
  }
  return ans;
}

signed main() {
  scanf("%lld%lld", &n, &k);
  for (int i = 1; i <= n; ++i) {
    scanf("%lld", &a[i]);
  }
  int l = 0, r = 1e9 + 10, mid;
  while (l <= r) {
    mid = (l + r) / 2;
    int f = cal(mid);
    if (f > k)
      l = mid + 1;
    else
      r = mid - 1;
  }
  printf("%lld\\n", l);
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  int MIN = 0, MAX = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    MAX = max(MAX, A[i]);
  }
  while (MIN < MAX) {
    int MID = ((MAX - MIN) / 2) + MIN;
    if (MID == 0)
      break;
    int num = 0;
    for (int i = 0; i < N; i++)
      num += (A[i] + MID - 1) / MID - 1;
    if (num <= K)
      MAX = MID;
    else
      MIN = MID + 1;
  }
  cout << MAX << endl;
}


Error: 0

Fixed submission:

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  int MIN = 0, MAX = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    MAX = max(MAX, A[i]);
  }
  while (MIN < MAX) {
    int MID = ((MAX - MIN) / 2) + MIN;
    int num = 0;
    for (int i = 0; i < N; i++)
      num += A[i] / MID;
    if (num <= K)
      MAX = MID;
    else
      MIN = MID + 1;
    if (MAX == 1)
      break;
  }
  cout << MAX << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

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

bool f(vector<int> &v, int x, int k) {
  lint cnt = 0;
  for (auto i : v) {
    cnt += (i + x - 1) / x - 1;
  }
  if (cnt <= k)
    return true;
  return false;
}

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int ok = *max_element(a.begin(), a.end());
  int ng = 0;
  while (abs(ok - ng) > 1) {
    int mid = (ok + ng) / 2;
    if (f(a, mid, k))
      ok = mid;
    else
      ng = mid;
  }
  cout << ok << endl;
}


Error: TLE

Fixed submission:

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

int main() {
  int n, k;
  cin >> n >> k;
  int a[200000];
  rep(i, n) cin >> a[i];
  priority_queue<tuple<int, int, int>, vector<tuple<int, int, int>>,
                 less<tuple<int, int, int>>>
      hq;
  rep(i, n) {
    tuple<int, int, int> t;
    get<0>(t) = a[i];
    get<1>(t) = 1;
    get<2>(t) = i;
    hq.push(t);
  }
  rep(i, k) {
    auto t = hq.top();
    hq.pop();
    auto ind = get<2>(t);
    get<1>(t)++;
    get<0>(t) = (a[ind] + get<1>(t) - 1) / get<1>(t);
    hq.push(t);
  }
  auto ans = hq.top();
  cout << get<0>(ans) << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
const int nax = 2e5 + 10;
int n, k;
int a[nax];

int main() {
  cin.tie(0)->sync_with_stdio(false);
  cin >> n >> k;

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

  int l = 1, r = 1e9;
  int ans = -1;

  while (l <= r) {
    int mid = l + r >> 1;
    long long tot = 0;

    for (int i = 1; i <= n; ++i) {
      tot += max(0, (a[i] - 1) / mid);
    }

    if (tot <= k) {
      ans = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }

  assert(ans != -1);
  cout << ans << '\\n';
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int nax = 2e5 + 10;
int n, k;
int a[nax];

int main() {
  cin.tie(0)->sync_with_stdio(false);
  cin >> n >> k;

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

  int l = 0, r = 1e9;
  int ans = -1;

  while (l <= r) {
    int mid = l + r >> 1;
    long long tot = 0;

    for (int i = 1; i <= n; ++i) {
      tot += max(0, (a[i] - 1) / mid);
    }

    if (tot <= k) {
      ans = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }

  assert(ans != -1);
  cout << ans << '\\n';
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for (ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
  return a > b && (a = b, true);
}
/*-------------------------------------------*/

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

bool f(ll x) {
  ll cnt = 0;
  rep(i, n) cnt += (a[i] + x - 1) / x;
  return cnt - n <= k;
}

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

  cin >> n >> k;
  rep(i, n) cin >> a[i];

  ll ng = 0, ok = 1e9 + 1;
  while (ng + 1 < ok)
    (f(ng + ok >> 1) ? ok : ng) = ng + ok >> 1;

  cout << ok << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for (ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
  return a > b && (a = b, true);
}
/*-------------------------------------------*/

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

bool f(ll x) {
  ll cnt = 0;
  rep(i, n) cnt += (a[i] + x - 1) / x;
  return cnt - n <= k;
}

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

  cin >> n >> k;
  rep(i, n) cin >> a[i];

  ll ng = 0, ok = 1e9 + 1;
  while (ng + 1 < ok)
    (f(ng + ok >> 1) ? ok : ng) = ng + ok >> 1;

  cout << ok << endl;

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

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

#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define endl "\\n"

const int N = 200001;

int n, k;
int a[N];

bool check(int x) {
  int reqd = 0;
  for (int i = 0; i + 1 <= n; i++) {
    int diff = a[i];
    reqd += (diff - 1) / x;
    if (reqd > k)
      return 0;
  }
  return 1;
}

int binsearch(int lo, int hi) {
  while (lo < hi) {
    int mid = (lo + hi) / 2;
    if (mid == 0) {
      return 0;
    }
    if (check(mid))
      hi = mid;
    else
      lo = mid + 1;
  }
  return lo;
}

int main() {
  IOS;
  int t = 1;
  int tc = 0;
  while (t--) {
    tc++;
    cin >> n >> k;
    for (int i = 0; i < n; i++)
      cin >> a[i];
    int ans = binsearch(1, 1e9);
    cout << ans;
  }
  return 0;
}

Error: WA

Fixed submission:

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

#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define endl "\\n"

const int N = 1e5 + 5;

int n, k;
int a[N];

bool check(int x) {
  int reqd = 0;
  for (int i = 0; i + 1 <= n; i++) {
    int diff = a[i];
    reqd += (diff - 1) / x;
    if (reqd > k)
      return 0;
  }
  return 1;
}

int binsearch(int lo, int hi) {
  while (lo < hi) {
    int mid = (lo + hi) / 2;
    if (mid == 0) {
      return 0;
    }
    if (check(mid))
      hi = mid;
    else
      lo = mid + 1;
  }
  return lo;
}

int main() {
  IOS;
  int t = 1;
  int tc = 0;
  while (t--) {
    tc++;
    cin >> n >> k;
    for (int i = 0; i < n; i++)
      cin >> a[i];
    int ans = binsearch(1, 1e9);
    cout << ans;
  }
  return 0;
}