alexjercan/bugnet huggingface dataset:
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("unroll-loops")

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

#define ll long long
#define ld long double
#define mod 1000000007
#define pb push_back
#define inf 1000000000000000000
#define ff first
#define ss second
#define deb(x) cout << #x << " " << x << "\\n"
#define Clear(x) memset(x, 0, sizeof(x))
#define all(x) (x).begin(), (x).end()

void checkpoint1() {
  /******think more code less******/
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

bool comp(pair<ll, ll> &a, pair<ll, ll> &b) {
  if (a.ff != b.ff)
    return a.ff < b.ff;
  else {
    if (a.ss > b.ss)
      return b.ss < a.ss;
    else if (a.ss < b.ss)
      return a.ss < b.ss;
  }
  return a.ff > b.ff;
}

ll powe(ll a, ll b) {
  ll res = 1;
  while (b > 0) {
    if (b & 1) {
      res *= a;
      res %= mod;
    }
    a *= a;
    a %= mod;
    b >>= 1;
  }
  return res;
}
ll n;
vector<pair<ll, ll>> p;
bool canwe(ld m) {
  ld mini = inf, maxi = -inf;
  for (ll i = 0; i < n; i++) {
    ld op = (p[i].ff - m * p[i].ss), ok = (p[i].ff + m * p[i].ss);
    mini = min(mini, ok);
    maxi = max(maxi, op);
  }
  if (maxi <= mini)
    return 1;
  return 0;
}
int main() {
  checkpoint1();
  ll n, im;
  cin >> n >> im;
  ll a[n];
  for (ll i = 0; i < n; i++)
    cin >> a[i];
  ll l = 0, r = 1e10;
  while (r > l + 1) {
    ll m = (l + r) / 2;
    ll k = 0;
    for (ll i = 0; i < n; i++)
      k += (a[i] - 1) / m;
    if (k <= im)
      r = m;
    else
      l = m;
  }
  cout << r;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int l = 1, r = 0, n, k;
  cin >> n >> k;
  vector<int> a(n, 0);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    r = max(r, a[i]);
  }
  while (r > l) {
    int x = (l + r) / 2, c = 0;
    for (int i = 0; i < n; ++i)
      c += (a[i] / x);
    if (c <= k)
      r = x;
    else
      l = x;
  }
  cout << r;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <set>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

void slove() {
  int n, k;
  int x;
  vector<int> logs;

  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> x;
    logs.push_back(x);
  }

  if (k == 0) {
    cout << *max_element(logs.begin(), logs.end()) << endl;
    return;
  }

  int l = 1;
  int r = 1e9 + 7;
  int ans = 0;
  while (l <= r) {
    int mid = (l + r) >> 1;
    int cut = 0;
    if (mid == 0)
      break;
    for (int i = 0; i < logs.size(); ++i) {
      if (logs[i] > mid) {
        cut += (logs[i] - (logs[i] % mid)) / mid;
      }
    }

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

  cout << ans << endl;
}

int main() { slove(); }

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <set>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

void slove() {
  int n, k;
  int x;
  vector<int> logs;

  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> x;
    logs.push_back(x);
  }

  int l = 0;
  int r = 1e9 + 7;
  int ans = 0;
  while (l <= r) {
    int mid = (l + r) >> 1;
    int cut = 0;
    for (int i = 0; i < logs.size(); ++i) {
      if (logs[i] > mid) {
        cut += (logs[i] - (logs[i] % mid)) / mid;
      }
    }

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

  cout << ans << endl;
}

int main() { slove(); }
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N, K;
  scanf("%d%d", &N, &K);

  vector<int> A(N);
  for (int i = 0; i < N; ++i)
    scanf("%d", &A[i]);

  int lb = 0;
  int ub = 1 << 30;
  while (ub - lb > 1) {
    int mb = (lb + ub) / 2;
    int c = 0;
    for (int i = 0; i < N; ++i) {
      c += (A[i] + mb - 1) / mb - 1;
      if (c > K)
        break;
    }
    (c <= K ? ub : lb) = mb;
  }

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

  return 0;
}


Error: 0

Fixed submission:

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

int main() {
  int N, K;
  scanf("%d%d", &N, &K);

  vector<int> A(N);
  for (int i = 0; i < N; ++i)
    scanf("%d", &A[i]);

  int lb = 0;
  int ub = 1 << 30;
  for (int _ = 0; _ < 32; ++_) {
    int mb = (lb + ub) / 2;
    int c = 0;
    for (int i = 0; i < N; ++i) {
      c += (A[i] + mb - 1) / mb - 1;
      if (c > K)
        break;
    }
    (c <= K ? ub : lb) = mb;
  }

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

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

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 10;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
int n, a[maxn], k;
bool judge(int m) {
  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    cnt += (a[i] - 1) / m;
  }
  return cnt <= k;
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; ++i)
    cin >> a[i];
  int l = 1, r = 1e9 + 10;
  while (l <= r) {
    int mid = l + r >> 1;
    if (judge(mid))
      r = mid - 1;
    else
      l = mid + 1;
  }
  cout << l << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 10;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
int n, a[maxn], k;
bool judge(int m) {
  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    cnt += (a[i] - 1) / m;
  }
  return cnt <= k;
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; ++i)
    cin >> a[i];
  int l = 0, r = 1e9 + 10;
  while (l <= r) {
    int mid = l + r >> 1;
    if (judge(mid))
      r = mid - 1;
    else
      l = mid + 1;
  }
  cout << l << 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 vi = vector<ll>;
using vvi = vector<vi>;
using pll = pair<ll, ll>;

#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair

template <typename T> using vv = vector<vector<T>>;

void solve() {
  int n;
  cin >> n;
  int k;
  cin >> k;
  vi a(n);
  for (auto &i : a)
    cin >> i, i *= 2;
  ll l = 0, r = 2e9 + 5;
  while (r - l > 1) {
    ll m = (l + r) / 2;
    ll sum = 0;
    for (auto &z : a)
      sum += max(0LL, (z + m - 1) / m - 1);
    if (sum > k)
      l = m;
    else
      r = m;
  }
  cout << (r + 1) / 2;
}

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


Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;
using vi = vector<ll>;
using vvi = vector<vi>;
using pll = pair<ll, ll>;

#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair

template <typename T> using vv = vector<vector<T>>;

void solve() {
  int n;
  cin >> n;
  int k;
  cin >> k;
  vi a(n);
  for (auto &i : a)
    cin >> i, i *= 2;
  int l = -1, r = 1e9 + 5;
  while (r - l > 1) {
    int m = (l + r) / 2;
    ll sum = 0;
    for (auto &z : a)
      sum += (z + m - 1) / m - 1;
    if (sum > k)
      l = m;
    else
      r = m;
  }
  cout << (r + 1) / 2;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define FAST_INPUT                                                             \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define ll long long
using namespace std;

int n, k;
vector<int> nums;

bool ok(int max_size) {
  ll total_cuts = 0;
  for (int i = 0; i < n; i++) {
    int val = nums[i];
    total_cuts += (val / max_size + (val % max_size != 0) - 1);
  }
  return total_cuts <= k;
}

void solve() {
  cin >> n >> k;
  nums = vector<int>(n);
  int mx = 0;
  for (int i = 0; i < n; i++) {
    cin >> nums[i];
    mx = max(mx, nums[i]);
  }

  int l = 1, r = mx;
  int ans = INT_MAX;
  while (l <= r) {
    int mid = l + (r - l) / 2;

    if (ok(mid)) {
      ans = min(ans, mid);
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }

  cout << ans << endl;
}

int main() {
  FAST_INPUT;

  solve();

  return 0;
}


Error: 0

Fixed submission:

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

#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
  const char *comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << "\\t|";
  __f(comma + 1, args...);
}

#define print(x)                                                               \\
  for (auto it : x)                                                            \\
    cout << it << ' ';                                                         \\
  cout << '\\n';
typedef long long ll;
typedef unsigned long long ull;
#define mem1(a) memset(a, -1, sizeof(a))
#define mem0(a) memset(a, 0, sizeof(a))

int n, k;
vector<int> a(200006);

bool valid(int size) {
  int cur = 0;
  for (int i = 0; i < n; i++) {
    int needed = a[i] / size;
    if (cur + needed > k)
      return false;
    cur += needed;
  }
  return true;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  a.clear();
  a.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int mx = *max_element(a.begin(), a.end());
  int lo = 0, hi = mx;
  int ans = mx;
  while (lo < hi) {
    int mid = (lo + hi) / 2;
    if (valid(mid)) {
      ans = mid;
      hi = mid;
    } else {
      lo = mid + 1;
    }
  }
  cout << lo << '\\n';
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define sz(v) ((int)(v).size())
#define all(v) ((v).begin()), ((v).end())
#define allr(v) ((v).rbegin()), ((v).rend())
#define pb push_back
#define mp make_pair
#define clr(v, d) memset(v, d, sizeof(v))
#define PI acos(-1)
typedef long long ll;
typedef unsigned long long ull;
const double eps = (1e-9);
using namespace std;
int dcmp(long double a, long double b) {
  return fabsl(a - b) <= eps ? 0 : (a > b) ? 1 : -1;
}
int getBit(ll num, int idx) { return ((num >> idx) & 1ll) == 1; }
int setBit1(int num, int idx) { return num | (1 << idx); }
ll setBit0(ll num, int idx) { return num & ~(1ll << idx); }
ll flipBit(ll num, int idx) { return num ^ (1ll << idx); }
void GO() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int countNumBit1(int mask) {
  int ret = 0;
  while (mask) {
    mask &= (mask - 1);
    ++ret;
  }
  return ret;
}
const int N = 200000 + 5;
int n, k, a[N];
bool check(int val) {
  ll tot = 0;
  for (int i = 0; i < n; i++) {
    int len = a[i];
    int F = (len / val + (len % val != 0)) - 1;
    if (tot + F > k)
      return 0;
    tot += F;
  }
  return (tot <= k);
}
int BS(int l, int r) {
  int res = 0;
  while (l <= r) {
    ll mid = (l + r) / 2;
    if (check(mid)) {
      r = mid - 1;
      res = mid;
    } else {
      l = mid + 1;
    }
  }
  return res;
}
int main() {
  GO();

  int T;
  T = 1;
  // cin>>T;
  while (T--) {

    cin >> n >> k;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    cout << BS(1, 1000000000) << "\\n";
  }
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define sz(v) ((int)(v).size())
#define all(v) ((v).begin()), ((v).end())
#define allr(v) ((v).rbegin()), ((v).rend())
#define pb push_back
#define mp make_pair
#define clr(v, d) memset(v, d, sizeof(v))
#define PI acos(-1)
typedef long long ll;
typedef unsigned long long ull;
const double eps = (1e-9);
using namespace std;
int dcmp(long double a, long double b) {
  return fabsl(a - b) <= eps ? 0 : (a > b) ? 1 : -1;
}
int getBit(ll num, int idx) { return ((num >> idx) & 1ll) == 1; }
int setBit1(int num, int idx) { return num | (1 << idx); }
ll setBit0(ll num, int idx) { return num & ~(1ll << idx); }
ll flipBit(ll num, int idx) { return num ^ (1ll << idx); }
void GO() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int countNumBit1(int mask) {
  int ret = 0;
  while (mask) {
    mask &= (mask - 1);
    ++ret;
  }
  return ret;
}
const int N = 1000 + 5;
vector<int> v[2];
int n, k, a[N];
bool check(int val) {
  ll tot = 0;
  for (int i = 0; i < n; i++) {
    int len = a[i];
    int F = (len / val + (len % val != 0)) - 1;
    if (tot + F > k)
      return 0;
    tot += F;
  }
  return (tot <= k);
}
int BS(int l, int r) {
  int res = 0;
  while (l <= r) {
    ll mid = (l + r) / 2;
    if (check(mid)) {
      r = mid - 1;
      res = mid;
    } else {
      l = mid + 1;
    }
  }
  return res;
}
int main() {
  GO();

  int T;
  T = 1;
  // cin>>T;
  while (T--) {

    cin >> n >> k;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    cout << BS(1, 1000000000) << "\\n";
  }
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

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

#define pb push_back
#define sf(x) scanf("%d", &x)
#define sfl(x) scanf("%lld", &x)
#define pf(x) printf("%d\\n", x)
#define pfl(x) printf("%lld\\n", x)
#define endl '\\n'
#define pii pair<int, int>
#define mapii map<int, int>
#define mapll map<ll, ll>
#define mapci map<char, int>
#define mapcl map<char, ll>
#define mapsi map<string, int>
#define mapsl map<string, ll>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vd vector<double, double>
#define all(c) c.begin(), c.end()
#define F first
#define S second
#define mp make_pair
#define ftc(x) cerr << #x << ": " << x << " " << endl;
#define PI acos(-1)
#define lcm(a, b) ((a * b) / __gcd(a, b))
#define optimize                                                               \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define sqr(a) ((a) * (a))

int main() {
  ll i, j, k, l, m, n, l1, l2, l3;

  cin >> n >> k;

  ll ar[n + 10], cnt;

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

  ll low = 1, high = 1e10, mid;

  while (low <= high) {
    mid = (low + high) / 2;
    cnt = 0;

    for (i = 0; i < n; i++) {
      cnt += (ar[i] - 1) / mid;
    }

    // cout << mid << " " << cnt << endl;

    if (cnt <= k) {
      // cout << mid << endl;
      l1 = mid;
      high = mid - 1;
    } else
      low = mid + 1;
  }

  cout << l1 << endl;
}


Error: 0

Fixed submission:

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

#define pb push_back
#define sf(x) scanf("%d", &x)
#define sfl(x) scanf("%lld", &x)
#define pf(x) printf("%d\\n", x)
#define pfl(x) printf("%lld\\n", x)
#define endl '\\n'
#define pii pair<int, int>
#define mapii map<int, int>
#define mapll map<ll, ll>
#define mapci map<char, int>
#define mapcl map<char, ll>
#define mapsi map<string, int>
#define mapsl map<string, ll>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vd vector<double, double>
#define all(c) c.begin(), c.end()
#define F first
#define S second
#define mp make_pair
#define ftc(x) cerr << #x << ": " << x << " " << endl;
#define PI acos(-1)
#define lcm(a, b) ((a * b) / __gcd(a, b))
#define optimize                                                               \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define sqr(a) ((a) * (a))

int main() {
  ll i, j, k, l, m, n, l1, l2, l3;

  cin >> n >> k;

  ll ar[n + 10], cnt;

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

  ll low = 0, high = 1e10, mid;

  while (low <= high) {
    mid = (low + high) / 2;
    cnt = 0;

    for (i = 0; i < n; i++) {
      cnt += (ar[i] - 1) / mid;
    }

    // cout << mid << " " << cnt << endl;

    if (cnt <= k) {
      // cout << mid << endl;
      l1 = mid;
      high = mid - 1;
    } else
      low = mid + 1;
  }

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

#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
  int N, K, a = 0;
  cin >> N >> K;
  vector<int> A(N);
  for (int &i : A) {
    cin >> i;
    a = max(a, i);
  }
  int mn = 0, mx = a;
  while (mx - mn > 1) {
    int n = (mn + mx) / 2, sum = 0;
    if (n == 0)
      break;
    for (int i = 0; i < N; i++)
      sum += (A[i] + n - 1) / n - 1;
    if (sum <= K)
      mx = n;
    else
      mn = n;
  }
  int sum = 0;
  if (mn == 0) {
    cout << mx << endl;
    return 0;
  }
  for (int i = 0; i < N; i++)
    sum += (A[i] + mn - 1) / mn - 1;
  if (sum <= K)
    cout << mn << endl;
  else
    cout << mx << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
  int N, K, a = 0;
  cin >> N >> K;
  vector<int> A(N);
  for (int &i : A) {
    cin >> i;
    a = max(a, i);
  }
  int mn = 0, mx = a;
  while (mx - mn > 1) {
    int n = (mn + mx) / 2, sum = 0;
    for (int i = 0; i < N; i++)
      sum += (A[i] + n - 1) / n - 1;
    if (sum <= K)
      mx = n;
    else
      mn = n;
  }
  int sum = 0;
  for (int i = 0; i < N; i++)
    sum += (A[i] + mn - 1) / mn - 1;
  if (sum <= K)
    cout << mn << endl;
  else
    cout << mx << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error


// Problem : E - Logs
// Contest : AtCoder - AtCoder Beginner Contest 174
// URL : https://atcoder.jp/contests/abc174/tasks/abc174_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl '\\n'
bool check(ll ar[], ll n, ll x, ll k) {
  ll ctr = 0;
  for (ll i = 0; i < n; i++) {
    if (x == 0) {
      ctr += ar[i] * 2;
      continue;
    }
    ctr += ar[i] / x;
    if (ar[i] % x == 0)
      ctr--;
  }
  //	cout<<x<<" "<<ctr<<' '<<k<<endl;
  if (ctr <= k)
    return true;
  else
    return false;
}
int main() {
  ll i, j, k, m, n, t;
  cin >> n >> k;
  ll ar[n];
  for (i = 0; i < n; i++)
    cin >> ar[i];
  ll ans = 0;
  for (i = 0; i < n; i++)
    ans = max(ans, ar[i]);
  ll l = 1, r = ans;
  while (l <= r) {
    ll mid = (l + r) / 2;
    if (check(ar, n, mid, k)) {
      ans = min(ans, mid);
      r = mid - 1;
    } else
      l = mid + 1;
  }
  cout << ans;
}

Error: WA

Fixed submission:


// Problem : E - Logs
// Contest : AtCoder - AtCoder Beginner Contest 174
// URL : https://atcoder.jp/contests/abc174/tasks/abc174_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl '\\n'
bool check(ll ar[], ll n, ll x, ll k) {
  ll ctr = 0;
  for (ll i = 0; i < n; i++) {
    ctr += ar[i] / x;
    if (ar[i] % x == 0)
      ctr--;
  }
  //	cout<<x<<" "<<ctr<<' '<<k<<endl;
  if (ctr <= k)
    return true;
  else
    return false;
}
int main() {
  ll i, j, k, m, n, t;
  cin >> n >> k;
  ll ar[n];
  for (i = 0; i < n; i++)
    cin >> ar[i];
  ll ans = 0;
  for (i = 0; i < n; i++)
    ans = max(ans, ar[i]);
  ll l = 0, r = ans;
  while (l <= r) {
    ll mid = (l + r) / 2;
    if (check(ar, n, mid, k)) {
      ans = min(ans, mid);
      r = mid - 1;
    } else
      l = mid + 1;
  }
  cout << ans;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i <= n; ++i)
#define ALL(x) x.begin(), x.end()
using P = pair<int, int>;
using lint = long long;
using ll = long long;
const lint inf = 1e18 + 7;
const int MOD = 1000000007;
bool judge(vector<int> const &a, int key, int k) {
  int n = a.size();
  lint sm = 0;
  if (key == 0)
    return false;
  rep(i, n) {
    int buf = (a[i] - 1) / key;
    sm += buf;
    // cout<<sm<<"\\n";
  }
  // if(sm>0)cout<<sm<<"\\n";
  return sm <= k;
}
signed main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int low = 0;
  int up = inf;
  while (up - low > 1) {
    int mid = (up + low) / 2;
    if (judge(a, mid, k)) {
      up = mid;
    } else
      low = mid;
  }
  cout << up << "\\n";
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i <= n; ++i)
#define ALL(x) x.begin(), x.end()
using P = pair<int, int>;
using lint = long long;
using ll = long long;
const lint inf = 1e18 + 7;
const int MOD = 1000000007;
bool judge(vector<int> const &a, int key, int k) {
  int n = a.size();
  lint sm = 0;
  rep(i, n) {
    int buf = (a[i] - 1) / key;
    sm += buf;
    // cout<<sm<<"\\n";
  }
  // if(sm>0)cout<<sm<<"\\n";
  return sm <= k;
}
signed main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int low = 0;
  int up = inf;
  rep(xx, 200) {
    int mid = (up + low) / 2;
    if (judge(a, mid, k)) {
      up = mid;
    } else
      low = mid;
  }
  cout << up << "\\n";
  // judge(a,4,k);
  return 0;
}