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

#include <bits/stdc++.h>
#pragma GCC optimize(2)
#define ll long long
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define per(i, n, a) for (int i = n; i >= a; i--)
#define endl '\\n'
#define eps 0.000000001
#define pb push_back
#define mem(a, b) memset(a, b, sizeof(a))
#define IO                                                                     \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);
using namespace std;
const int INF = 0x3f3f3f3f;
const ll inf = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 5;
int n, k, a[maxn];
bool check(int x) {
  int ok = 0;
  rep(i, 1, n) { ok += (a[i] - 1) / x; }
  return ok <= k;
}
int main() {
  cin >> n >> k;
  rep(i, 1, n) cin >> a[i];
  int l = 1, r = 1e9;
  while (l < r) {
    int mid = (l + r) >> 1;
    if (check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  cout << l << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#pragma GCC optimize(2)
#define ll long long
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define per(i, n, a) for (int i = n; i >= a; i--)
#define endl '\\n'
#define eps 0.000000001
#define pb push_back
#define mem(a, b) memset(a, b, sizeof(a))
#define IO                                                                     \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);
using namespace std;
const int INF = 0x3f3f3f3f;
const ll inf = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 5;
int n, k, a[maxn];
bool check(int x) {
  int ok = 0;
  rep(i, 1, n) { ok += (a[i] - 1) / x; }
  return ok <= k;
}
int main() {
  cin >> n >> k;
  rep(i, 1, n) cin >> a[i];
  int l = 0, r = 1000000000;
  while (l < r) {
    int mid = (l + r) >> 1;
    if (check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  cout << l << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;
#define X first;
#define Y second;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const ll INF = 2e18;
const int inf = 1e9 + 10;
const int maxN = 2e5 + 10;
const int maxK = 1e4 + 10;
const int maxD = 15;
const int maxH = 100;
const int MOD = 1e9 + 7;

ll n, k;
ll a[maxN];
bool check(ll x) {
  ll cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] >= x) {
      cnt += ((a[i] / x) - (a[i] % x == 0));
    }
  }
  if (cnt <= k) {
    return true;
  } else {
    return false;
  }
}
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
  }
  ll L = 1, R = 1e9;
  ll ans = R;
  while (L <= R) {
    ll mid = (L + R) / 2;
    if (check(mid)) {
      ans = mid;
      R = mid - 1;
    } else {
      L = mid + 1;
    }
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;
#define X first;
#define Y second;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const ll INF = 2e18;
const int inf = 1e9 + 10;
const int maxN = 2e5 + 10;
const int maxK = 1e4 + 10;
const int maxD = 15;
const int maxH = 100;
const int MOD = 1e9 + 7;

ll n, k;
ll a[maxN];
bool check(ll x) {
  ll cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] >= x) {
      cnt += ((a[i] / x) - (a[i] % x == 0));
    }
  }
  if (cnt <= k) {
    return true;
  } else {
    return false;
  }
}
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
  }
  ll L = 0, R = 1e9;
  ll ans = R;
  while (L <= R) {
    ll mid = (L + R) / 2;
    if (check(mid)) {
      ans = mid;
      R = mid - 1;
    } else {
      L = mid + 1;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

/************
 * 	@Just Another Source code by: ankit.sangwan1999
 *	@created on: 10 Sept 2020
 */
#include <bits/stdc++.h>
using namespace std;
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL) //;cout.tie(NULL)
#define ll long long
const int mod = 1e9 + 7;
const long double pie = 3.14159265358979323846;
#define endl '\\n'
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
gp_hash_table<int, ll> ma; // orderd_map using pb_ds

bool fun(int *arr, int n, int k, int mid) {
  int ops = 0;
  for (int i = 0; i < n; i++) {
    ops += (arr[i] - 1) / mid;
    if (ops > k)
      return 0;
  }
  return 1;
}

void solve() {

  int n, k;
  cin >> n >> k;
  int ma = INT_MIN;
  int arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    ma = max(ma, arr[i]);
  }

  int high = ma;
  int low = 1;
  int mid = (low + high) / 2;
  int ans;
  while (low <= high) {

    if (fun(arr, n, k, mid)) {
      ans = mid;
      high = mid - 1;
    } else {
      low = mid + 1;
    }
    mid = (low + high) / 2;
  }

  cout << ans << endl;
}

signed main() {

#ifndef ONLINE_JUDGE
  freopen("/mnt/DATA/D_Drive/CP/input.txt", "r", stdin);
  freopen("/mnt/DATA/D_Drive/CP/output.txt", "w", stdout);
#endif

  fastio;
  int t = 1;
  // cin>>t;

  while (--t >= 0) {
    solve();
  }

  return 0;
}

Error: TLE

Fixed submission:

/************
 * 	@Just Another Source code by: ankit.sangwan1999
 *	@created on: 10 Sept 2020
 */
#include <bits/stdc++.h>
using namespace std;
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL) //;cout.tie(NULL)
#define ll long long
const int mod = 1e9 + 7;
const long double pie = 3.14159265358979323846;
#define endl '\\n'
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
gp_hash_table<int, ll> ma; // orderd_map using pb_ds

bool fun(int *arr, int n, int k, int mid) {

  priority_queue<int, vector<int>> pq;
  for (int i = 0; i < n; i++) {
    pq.push(arr[i]);
  }

  for (int i = 0; i < k; i++) {
    int top = pq.top();
    if (top <= mid)
      return 1;
    pq.pop();
    pq.push(mid);
    pq.push(top - mid);
  }

  int top = pq.top();
  if (top <= mid) {
    return 1;
  }
  return 0;
}

void solve() {

  int n, k;
  cin >> n >> k;
  int ma = INT_MIN;
  int arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    ma = max(ma, arr[i]);
  }

  int high = ma;
  int low = 1;
  int mid = (low + high) / 2;
  int ans;
  while (low <= high) {

    if (fun(arr, n, k, mid)) {
      ans = mid;
      high = mid - 1;
    } else {
      low = mid + 1;
    }
    mid = (low + high) / 2;
  }

  cout << ans << endl;
}

signed main() {

#ifndef ONLINE_JUDGE
  freopen("/mnt/DATA/D_Drive/CP/input.txt", "r", stdin);
  freopen("/mnt/DATA/D_Drive/CP/output.txt", "w", stdout);
#endif

  fastio;
  int t = 1;
  // cin>>t;

  while (--t >= 0) {
    solve();
  }

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

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

typedef long long int ll;
using ii = pair<ll, ll>;
#define all(o) (o).begin(), (o).end()
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define ld long double
#define eps 0.00000000001

class prioritize {
public:
  bool operator()(ii &p1, ii &p2) { return p1.F < p2.F; }
};

int main() {

#ifndef ONLINE_JUDGE
  freopen("input1.txt", "r", stdin);
  freopen("output1.txt", "w", stdout);
#endif

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  ll n, k;
  cin >> n >> k;

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

  sort(arr, arr + n);
  ll left = 1;
  ll right = 1e9;
  ll mid = 0;
  ll ans = 1e9;

  while (left <= right) {
    mid = left + (right - left) / 2;

    ll count = 0;

    for (ll i = 0; i < n; i++) {
      ll x = floor((arr[i] - 1) / mid);
      count += x;
    }

    if (count <= k) {
      right = mid - 1;
      ans = min(ans, mid);
    } else
      left = mid + 1;
  }

  if (k == 0 || ans == 1e9)
    cout << arr[n - 1] << "\\n";
  else
    cout << ans << "\\n";
}

Error: -11

Fixed submission:

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

typedef long long int ll;
using ii = pair<ll, ll>;
#define all(o) (o).begin(), (o).end()
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define ld long double
#define eps 0.00000000001

class prioritize {
public:
  bool operator()(ii &p1, ii &p2) { return p1.F < p2.F; }
};

int main() {

#ifndef ONLINE_JUDGE
  freopen("input1.txt", "r", stdin);
  freopen("output1.txt", "w", stdout);
#endif

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  ll n, k;
  cin >> n >> k;

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

  sort(arr, arr + n);
  ll left = 0;
  ll right = 1e9;
  ll mid = 0;
  ll ans = 1e9;

  while (left <= right) {
    mid = left + (right - left) / 2;

    ll count = 0;

    for (ll i = 0; i < n; i++) {
      ll x = floor((arr[i] - 1) / mid);
      count += x;
    }

    if (count <= k) {
      right = mid - 1;
      ans = min(ans, mid);
    } else
      left = mid + 1;
  }

  if (k == 0 || ans == 1e9)
    cout << arr[n - 1] << "\\n";
  else
    cout << ans << "\\n";
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i, m, n) for (int(i) = (m); (i) < (n); ++(i))
#define rREP(i, m, n) for (int(i) = (n)-1; (i) >= (m); --(i))
#define all(x) (x).begin(), (x).end()
#define out(y, x, h, w) (y) < 0 || (x) < 0 || (y) >= (h) || (x) >= (w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
inline void init() {
  cin.tie(nullptr);
  cout.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  rep(i, 0, N) cin >> A[i];
  ll l = 0, r = 1e9 + 7;
  while (r - l > 1) {
    ll mid = (l + r) / 2;
    ll cnt = 0;
    if (mid == 0)
      break;
    rep(i, 0, N) {
      if (A[i] <= mid)
        continue;
      cnt += A[i] / mid;
    }
    if (cnt <= K)
      r = mid;
    else
      l = mid;
  }
  cout << r << "\\n";

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i, m, n) for (int(i) = (m); (i) < (n); ++(i))
#define rREP(i, m, n) for (int(i) = (n)-1; (i) >= (m); --(i))
#define all(x) (x).begin(), (x).end()
#define out(y, x, h, w) (y) < 0 || (x) < 0 || (y) >= (h) || (x) >= (w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
inline void init() {
  cin.tie(nullptr);
  cout.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  rep(i, 0, N) cin >> A[i];
  if (K == 0) {
    sort(all(A));
    cout << A[N - 1] << "\\n";
    return 0;
  }
  ll l = -1, r = 1e9 + 7;
  while (r - l > 1) {
    ll mid = (l + r) / 2;
    ll cnt = 0;
    rep(i, 0, N) {
      if (A[i] <= mid)
        continue;
      cnt += A[i] / mid;
    }
    if (cnt <= K)
      r = mid;
    else
      l = mid;
  }
  cout << r << "\\n";

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

#include <bits/stdc++.h>
#define lowbit(i) ((i) & (-i))
#define ls (p << 1)
#define rs (p << 1 | 1)
using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int MAXN = 2 * 1e5 + 15;
int n, k;
int len[MAXN];
bool check(int x) {
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    cnt += len[i] / x - 1 + (len[i] % x ? 1 : 0);
    if (cnt > k)
      return false;
  }
  return true;
}
int main() {
#ifdef CitricAcid
  freopen("input.txt", "rt", stdin);
#endif

  int l = 1, r = 0;
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &len[i]);
    r = max(r, len[i]);
  }
  int res;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (check(mid)) {
      res = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  printf("%d\\n", res);

#ifdef CitricAcid
  cerr << "\\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\\n";
#endif
  return 0;
}
/*
# author : CitricAcid
# date : 2020/08/03
*/

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int a[200100];
int n, k;

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

int main() {
  scanf("%d%d", &n, &k);
  int l = 0, r = 0;
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    r = max(r, a[i]);
    ans = r;
  }

  while (l < r) {
    int mid = l + r >> 1;
    if (check(mid)) {
      ans = mid;
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
int a[200005], n, k;
bool check(int x) {
  int now = 0;
  for (int i = 0; i < n; i++) {
    now += (a[i] - 1) / x;
  }
  return now <= k;
}
int main() {
  cin >> n >> k;
  int maxn = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if (a[i] > maxn)
      maxn = a[i];
  }
  int l = 0, r = maxn; // 答案上下界
  while (r - l > 1) {
    int mid = (l + r) >> 1;
    if (check(mid))
      r = mid;
    else
      l = mid;
  }
  cout << r << endl;
  return 0;
}

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) {
      return 1e9;
    }
    ans = ans + (a[i] / x);
    if (ans > k) {
      return 1e9;
    }
  }
  if (ans < 0) {
    return 1e9;
  }
  return ans;
}

signed main() {
  scanf("%lld%lld", &n, &k);
  for (int i = 1; i <= n; ++i) {
    scanf("%lld", &a[i]);
  }
  int l = 0, r = 1e10, 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: Time Limit Exceeded

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

int main() {
  long long N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  int upper = 1000000001, lower = 1;
  int result;
  while (upper != lower) {
    result = (upper + lower) / 2;
    long long count = 0;
    for (int i = 0; i < N; i++) {
      count += ((A[i] + result - 1) / result - 1);
    }
    if (K < count) {
      if (lower == result) {
        result++;
        break;
      } else {
        lower = result;
      }
    } else {
      if (upper == result) {
        break;
      } else {
        upper = result;
      }
    }
  }
  cout << result << endl;
}

Error: TLE

Fixed submission:

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

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

  auto compare = [](pair<long long, long long> a,
                    pair<long long, long long> b) {
    long long x = a.first * b.second;
    long long y = b.first * a.second;
    return x < y;
  };

  priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,
                 decltype(compare)>
      A{compare};
  for (int i = 0; i < N; i++) {
    long long x;
    cin >> x;
    A.emplace(x, 1);
  }

  for (int i = 0; i < K; i++) {
    auto t = A.top();
    A.pop();
    t.second++;
    A.push(t);
  }
  auto t = A.top();
  cout << (t.second + t.first - 1) / t.second << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5 + 10;
int n, k, a[N];
int check(int x) {
  int ans = 0;
  for (int i = 1; i <= n; i++)
    ans += (a[i] + x - 1) / x - 1;
  return ans <= k;
}
signed main() {
  scanf("%lld%lld", &n, &k);
  for (int i = 1; i <= n; i++)
    scanf("%lld", &a[i]);
  int l = 1, r = 2e9;
  while (l < r) {
    int mid = (l + r) >> 1;
    if (check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  cout << l << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5 + 10;
int n, k, a[N];
int check(int x) {
  int ans = 0;
  for (int i = 1; i <= n; i++)
    ans += (a[i] + x - 1) / x - 1;
  return ans <= k;
}
signed main() {
  scanf("%lld%lld", &n, &k);
  for (int i = 1; i <= n; i++)
    scanf("%lld", &a[i]);
  int l = 0, r = 2e9;
  while (l < r) {
    int mid = (l + r) >> 1;
    if (check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  cout << l << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define all(x) begin(x), end(x)

using i64 = int_fast64_t;
using u64 = uint_fast64_t;
using f64 = double;
using p64 = pair<i64, i64>;

constexpr i64 INF = INT_FAST64_MAX / 2;

void solve() {
  i64 n, k;
  cin >> n >> k;
  vector<i64> a(n);
  for (auto &e : a)
    cin >> e;
  i64 asum = reduce(all(a));
  vector<i64> c(n);
  for (i64 i = 0; i < n; i++)
    c[i] = k * a[i] / asum;
  k -= reduce(all(c));

  auto f = [](p64 x, p64 y) { return x.first * y.second < y.first * x.second; };
  priority_queue<p64, vector<p64>, decltype(f)> q(f);
  for (i64 i = 0; i < n; i++)
    q.emplace(a[i], c[i] + 1);
  for (i64 i = 0; i < k; i++) {
    p64 t = q.top();
    q.pop();
    t.second++;
    q.push(t);
  }

  auto &[ansl, ansc] = q.top();
  cout << (ansl + ansc - 1) / ansc << endl;
}

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  solve();
}


Error: TLE

Fixed submission:

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

#define all(x) begin(x), end(x)

using i64 = int_fast64_t;
using u64 = uint_fast64_t;
using f64 = double;
using p64 = pair<i64, i64>;

constexpr i64 INF = INT_FAST64_MAX / 2;

void solve() {
  i64 n, k;
  cin >> n >> k;
  auto f = [](p64 x, p64 y) { return x.first * y.second < y.first * x.second; };
  priority_queue<p64, vector<p64>, decltype(f)> q(f);
  for (i64 i = 0; i < n; i++) {
    i64 a;
    cin >> a;
    q.emplace(a, 1);
  }
  for (i64 i = 0; i < k; i++) {
    p64 t = q.top();
    q.pop();
    t.second++;
    q.push(t);
  }

  auto &[l, c] = q.top();
  cout << (l + c - 1) / c << endl;
}

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  solve();
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> vec(n);
  rep(i, n) cin >> vec[i];
  ll ok = 10000000000, ng = 0;
  while (ok - ng > 1) {
    int cnt = 0;
    int a = (ok + ng) / 2;
    if (a <= 0) {
      cout << 1 << endl;
      return 0;
    }
    rep(i, n) {
      int x = vec[i];
      cnt += x / a;
      if (x % a == 0)
        cnt--;
    }
    if (cnt <= k) {
      ok = a;
    } else
      ng = a;
  }
  cout << ok << endl;
}

Error: 0

Fixed submission:

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

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> vec(n);
  rep(i, n) cin >> vec[i];
  ll ok = 10000000000, ng = -1;
  while (ok - ng > 1) {
    int cnt = 0;
    int a = (ok + ng) / 2;
    rep(i, n) {
      int x = vec[i];
      cnt += x / a;
      if (x % a == 0)
        cnt--;
    }
    if (cnt <= k) {
      ok = a;
    } else
      ng = a;
  }
  cout << ok << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

#define ff first
#define ss second

using namespace std;
using pii = pair<int, int>;
using ll = long long;

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

  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  ll maxa = *max_element(a.begin(), a.end());
  ll lo = 0, hi = maxa;

  while (lo < hi) {
    ll mid = (lo + hi) / 2;
    ll m = maxa - mid;
    ll cnt = 0;
    for (int i = 0; i < n; i++) {
      cnt += a[i] / m;
      if (a[i] % m == 0)
        cnt -= 1;
    }
    if (cnt <= k)
      lo = mid + 1;
    else
      hi = mid;
  }
  cout << maxa - lo + 1;

  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

#define ff first
#define ss second

using namespace std;
using pii = pair<int, int>;
using ll = long long;

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

  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  ll maxa = *max_element(a.begin(), a.end());
  ll lo = 0, hi = maxa + 1;

  while (lo < hi) {
    ll mid = (lo + hi) / 2;
    ll m = maxa - mid;
    ll cnt = 0;
    for (int i = 0; i < n; i++) {
      cnt += a[i] / m;
      if (a[i] % m == 0)
        cnt -= 1;
    }
    if (cnt <= k)
      lo = mid + 1;
    else
      hi = mid;
  }
  cout << maxa - lo + 1;

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

#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] - 1) / x;
    if (c <= k)
      r = x;
    else
      l = x + 1;
  }
  cout << r;
  return 0;
}


Error: WA

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 (1) {
    int x = (l + r) / 2, c = 0;
    for (int i = 0; i < n; ++i)
      c += (a[i] + x - 1) / x - 1;
    if (r == l)
      break;
    else if (c <= k)
      r = x - 1;
    else
      l = x + 1;
  }
  cout << r;
  return 0;
}