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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pii pair<int, int>
#define pb push_back
#define fi first
#define se second
#define UP(a, b, c) for (ll(a) = (b); (a) < (c); (a)++)
#define UU(a, b, c) for (ll(a) = (b); (a) <= (c); (a)++)
#define DN(a, b, c) for (ll(a) = (b); (a) > (c); (a)--)
#define DU(a, b, c) for (ll(a) = (b); (a) >= (c); (a)--)

ll n, k;
ll arr[200005];

void reset() {}

void input() {
  cin >> n >> k;
  UU(i, 1, n) { cin >> arr[i]; }
}

bool check(ll h) {
  ll cnt = 0;
  UU(i, 1, n) {
    if (arr[i] <= h) {
      continue;
    }
    cnt += arr[i] / h;
  }

  return (cnt <= k);
}

ll binser(ll l, ll r) {
  if (l <= r) {
    ll m = l + (r - l) / 2;
    if (check(m)) {
      return min(m, binser(l, m - 1));
    } else {
      return binser(m + 1, r);
    }
  }
  return INT_MAX;
}

void solve() {
  ll ans = 0;
  UU(i, 1, n) ans = max(ans, arr[i]);
  cout << min((ll)ans, binser(1, 2e9)) << endl;
}

void LetsRock() { solve(); }

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

  input();
  reset();
  LetsRock();

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pii pair<int, int>
#define pb push_back
#define fi first
#define se second
#define UP(a, b, c) for (ll(a) = (b); (a) < (c); (a)++)
#define UU(a, b, c) for (ll(a) = (b); (a) <= (c); (a)++)
#define DN(a, b, c) for (ll(a) = (b); (a) > (c); (a)--)
#define DU(a, b, c) for (ll(a) = (b); (a) >= (c); (a)--)

ll n, k;
ll arr[200005];

void reset() {}

void input() {
  cin >> n >> k;
  UU(i, 1, n) { cin >> arr[i]; }
}

bool check(ll h) {
  ll cnt = 0;
  UU(i, 1, n) { cnt += arr[i] / h; }

  return (cnt <= k);
}

ll binser(ll l, ll r) {
  if (l <= r) {
    ll m = l + (r - l) / 2;
    if (check(m)) {
      return min(m, binser(l, m - 1));
    } else {
      return binser(m + 1, r);
    }
  }
  return INT_MAX;
}

void solve() {
  ll ans = 0;
  UU(i, 1, n) ans = max(ans, arr[i]);
  cout << min((ll)ans, binser(0, 2e9)) << endl;
}

void LetsRock() { solve(); }

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

  input();
  reset();
  LetsRock();

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

// #define _GLIBCXX_DEBUG
// #pragma GCC optimize("Ofast")
#pragma GCC diagnostic ignored "-Wsign-compare"
#include <bits/stdc++.h>
// #include <atcoder/all>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define reps(i, s, n) for (int i = s; i < (int)(n); ++i)
using namespace std;
using ll = long long;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
constexpr int INF = 1e9 + 7;
constexpr ll LINF = 1LL << 60;

bool is_ok(int L, int k, V<int> &A) {
  int need = 0;
  for (auto &&a : A) {
    need += (a - 1) / L;
  }
  return need <= k;
}

int binary_searchM(int k, V<int> &A) {
  int ng = 0;
  int ok = 1e9;
  while (abs(ok - ng) > 1) {
    int mid = (ok + ng) / 2;
    if (is_ok(mid, k, A)) {
      ok = mid;
    } else {
      ng = mid;
    }
  }
  return ok;
}

void solve() {
  int n, k;
  cin >> n >> k;
  V<int> a(n);
  rep(i, n) cin >> a[i];
  cout << binary_searchM(k, a) << "\\n";
}
int main() {
  cin.tie(nullptr);
  // ios_base::sync_with_stdio(false);
  // cout << fixed << setprecision(15);
  solve();
}

Error: 0

Fixed submission:

// #define _GLIBCXX_DEBUG
// #pragma GCC optimize("Ofast")
#pragma GCC diagnostic ignored "-Wsign-compare"
#include <bits/stdc++.h>
// #include <atcoder/all>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define reps(i, s, n) for (int i = s; i < (int)(n); ++i)
using namespace std;
using ll = long long;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
constexpr int INF = 1e9 + 7;
constexpr ll LINF = 1LL << 60;

bool is_ok(ll L, int k, V<int> &A) {
  ll need = 0;
  for (auto &&a : A) {
    need += (ll)(a - 1) / L;
  }
  return need <= k;
}

int binary_searchM(int k, V<int> &A) {
  ll ng = -1;
  ll ok = 1e9;
  while (abs(ok - ng) > 1) {
    ll mid = (ok + ng) / 2;
    if (is_ok(mid, k, A)) {
      ok = mid;
    } else {
      ng = mid;
    }
  }
  return (int)ok;
}

void solve() {
  int n, k;
  cin >> n >> k;
  V<int> a(n);
  rep(i, n) cin >> a[i];
  cout << binary_searchM(k, a) << "\\n";
}
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>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
const int INF32 = 1 << 30;
const ll INF64 = 1LL << 60;

void solve() {
  int n, k;
  cin >> n >> k;
  int a[n], ans, l = 1, r = 1;
  for (auto &i : a) {
    cin >> i;
    r = max(r, i);
  }
  while (l <= r) {
    int m = (l + r) / 2, cnt = 0;
    for (auto i : a)
      cnt += (i - 1) / m;
    if (cnt > k)
      l = m + 1;
    else {
      ans = m;
      r = m - 1;
    }
  }
  cout << ans;
}

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

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
const int INF32 = 1 << 30;
const ll INF64 = 1LL << 60;

void solve() {
  int n, k;
  cin >> n >> k;
  int a[n], ans;
  for (auto &i : a)
    cin >> i;
  int l = 0, r = MOD;
  while (l <= r) {
    int m = (l + r) / 2, cnt = 0;
    for (auto i : a)
      cnt += (i - 1) / m;
    if (cnt > k)
      l = m + 1;
    else {
      ans = m;
      r = m - 1;
    }
  }
  cout << ans;
}

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

#define _CRT_SECURE_NO_WARNINGS 1

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define LL long long
#define pii pair<int, int>
#define sd(x) scanf("%d", &x)
#define slld(x) scanf("%lld", &x)
#define pd(x) printf("%d\\n", x)
#define plld(x) printf("%lld\\n", x)
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define mem(a) memset(a, 0, sizeof(a))
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
#define fast_io ios::sync_with_stdio(false)

const int INF = 1e9;
const LL mod = 1e9 + 7;
const int maxn = 2e5 + 7;

int a[maxn];
int n, k;

bool check(int mid) {
  int res = 0;
  rep(i, 1, n) {
    if (a[i] <= mid)
      continue;
    res += a[i] / mid;
  }
  return res <= k;
}

int main() {
  sd(n), sd(k);
  rep(i, 1, n) sd(a[i]);
  int l = 1, r = INF;
  int ans = 0;
  while (l <= r) {
    int mid = (l + r + 1) >> 1;
    // cout << "mid = " << mid << endl;
    if (check(mid)) {
      ans = mid;
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  pd(ans);
  return 0;
}

Error: 0

Fixed submission:

#define _CRT_SECURE_NO_WARNINGS 1

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define LL long long
#define pii pair<int, int>
#define sd(x) scanf("%d", &x)
#define slld(x) scanf("%lld", &x)
#define pd(x) printf("%d\\n", x)
#define plld(x) printf("%lld\\n", x)
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define mem(a) memset(a, 0, sizeof(a))
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
#define fast_io ios::sync_with_stdio(false)

const int INF = 1e9;
const LL mod = 1e9 + 7;
const int maxn = 2e5 + 7;

int a[maxn];
int n, k;

bool check(int mid) {
  int res = 0;
  rep(i, 1, n) {
    if (a[i] <= mid)
      continue;
    res += a[i] / mid;
  }
  return res <= k;
}

int main() {
  sd(n), sd(k);
  rep(i, 1, n) sd(a[i]);
  int l = 0, r = INF;
  int ans = 0;
  while (l <= r) {
    int mid = (l + r + 1) >> 1;
    // cout << "mid = " << mid << endl;
    if (check(mid)) {
      ans = mid;
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  pd(ans);
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define LOCAL 1

#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define dbg(...)                                                               \\
  cout << #__VA_ARGS__ ": [";                                                  \\
  for (auto e : __VA_ARGS__) {                                                 \\
    cout << e << ", ";                                                         \\
  }                                                                            \\
  cout << "]\\n"
#define dbg1(...) cout << #__VA_ARGS__ " " << __VA_ARGS__
#else
#define dbg(...) 1;
#define dbg1(...) 1;
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
constexpr ll R = 2e5 + 69, INF = 2e9 + 6969;

ll l, r, n, k, a[R], ans;

int main() {
  scanf("%lld%lld", &n, &k);
  for (int i = 0; i < n; ++i)
    scanf("%lld", &a[i]);
  ans = INF;
  l = 1;
  r = INF;
  //  #warning change here :)
  while (l < r) {
    ll s = (l + r) / 2;
    //  printf("%lld\\n", s);
    ll licz = 0;
    for (int i = 0; i < n; ++i)
      licz += ((s - 1 + a[i]) / s - 1);
    if (k >= licz) {
      ans = s;
      r = s;
    } else
      l = s + 1;
  }
  printf("%lld\\n", ans);
  return 0;
}


Error: 0

Fixed submission:

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define LOCAL 1

#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define dbg(...)                                                               \\
  cout << #__VA_ARGS__ ": [";                                                  \\
  for (auto e : __VA_ARGS__) {                                                 \\
    cout << e << ", ";                                                         \\
  }                                                                            \\
  cout << "]\\n"
#define dbg1(...) cout << #__VA_ARGS__ " " << __VA_ARGS__
#else
#define dbg(...) 1;
#define dbg1(...) 1;
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
constexpr ll R = 2e5 + 69, INF = 2e9 + 6969;

ll l, r, n, k, a[R], ans;

int main() {
  scanf("%lld%lld", &n, &k);
  for (int i = 0; i < n; ++i)
    scanf("%lld", &a[i]);
  ans = INF;
  l = 0;
  r = INF;
  //  #warning change here :)
  while (l < r) {
    ll s = (l + r) / 2;
    //  printf("%lld\\n", s);
    ll licz = 0;
    for (int i = 0; i < n; ++i)
      licz += ((s - 1 + a[i]) / s - 1);
    if (k >= licz) {
      ans = s;
      r = s - 1;
    } else
      l = s + 1;
  }
  printf("%lld\\n", ans);
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

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

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
using ll = long long;
string char_to_string(char val) { return string(1, val); }
int char_to_int(char val) { return val - '0'; }
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;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance(vec.begin(), itr);
  if (index != vec.size()) { // 発見できたとき
    return 1;
  } else { // 発見できなかったとき
    return 0;
  }
}
struct edge {
  ll to, cost;
};

int main() {
  int N;
  ll K;
  cin >> N >> K;
  vector<ll> A(N);
  REP(i, N) cin >> A[i];
  ll ng = 0;
  ll ok = *max_element(all(A));
  while (abs(ok - ng) > 1) {
    ll mid = (ok + ng) / 2;
    ll tmp = 0;
    REP(i, N) { tmp += (A[i] - 1) / mid; }
    if (K >= tmp)
      ok = mid;
    else
      ng = mid;
  }
  cout << ok << endl;
}

Error: 0

Fixed submission:

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

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
using ll = long long;
string char_to_string(char val) { return string(1, val); }
int char_to_int(char val) { return val - '0'; }
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;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance(vec.begin(), itr);
  if (index != vec.size()) { // 発見できたとき
    return 1;
  } else { // 発見できなかったとき
    return 0;
  }
}
struct edge {
  ll to, cost;
};

int N;
ll K;

int main() {
  cin >> N >> K;
  vector<ll> A(N);
  REP(i, N) cin >> A[i];
  sort(all(A));
  ll ng = -1;
  ll ok = *max_element(all(A));
  while (abs(ok - ng) > 1) {
    ll mid = (ok + ng) / 2;
    ll tmp = 0;
    REP(i, N) { tmp += (A[i] - 1) / mid; }
    if (K >= tmp)
      ok = mid;
    else
      ng = mid;
  }
  cout << ok << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bits/stdc++.h>
#include <vector>
using namespace std;
using UL = unsigned int;
using ULL = unsigned long long;
using LL = long long;

#define rep(i, n) for (int i = 0; i < (n); i++)
LL floor_usr(LL a, int b) { return (a + (b - 1)) / b; }
const int maxN = 200001;
// 当分割するのが最適なメソッド。
// 各丸太についてn[i]回切るとすると、最大n[i]+1で割った値になる。
// n[i](sum(n[i])=K)を最適に分配するという問題に帰着する。
// O(nlog(K))かO(Klog(n))ぐらいならいけそう。後者はソートか？
// 基本、数値に比例した(n+1)を当てれば全ての丸太は均一な大きさになる。
// その和をKに合わせればそもそも計算がいらないか。A[i]=min*(n[i]+1)
int main() {
  int N, K;
  scanf("%d %d", &N, &K);

  LL A[maxN];

  LL sumA = 0;
  vector<vector<LL>> dn;
  rep(i, N) scanf("%ld", &A[i]);
  sort(A, A + N);
  rep(i, N) sumA += A[i];
  int n;
  int sumn = 0;
  rep(i, N) {
    if (sumA != 0)
      n = K * A[i] / sumA;
    else
      n = 0;
    sumn += n;
    dn.push_back({floor_usr(A[i], (n + 1)), A[i], n});
  }

  vector<LL> B;
  sort(dn.begin(), dn.begin() + N, greater<vector<LL>>());
  rep(i, K - sumn) {
    dn[i % N][2]++;
    dn[i % N][0] = floor_usr(dn[i % N][1], dn[i % N][2] + 1);
  }
  sort(dn.begin(), dn.begin() + N, greater<vector<LL>>());
  printf("%ld", dn[0][0]);
  // 真の値より一回小さいnが得られているので、追加するiを選んで最小値を求める
  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <vector>
using namespace std;
using UL = unsigned int;
using ULL = unsigned long long;
using LL = long long;

#define rep(i, n) for (int i = 0; i < (n); i++)
LL floor_usr(LL a, int b) { return (a + (b - 1)) / b; }
const int maxN = 20;
// 当分割するのが最適なメソッド。
// 各丸太についてn[i]回切るとすると、最大n[i]+1で割った値になる。
// n[i](sum(n[i])=K)を最適に分配するという問題に帰着する。
// O(nlog(K))かO(Klog(n))ぐらいならいけそう。後者はソートか？
// 基本、数値に比例した(n+1)を当てれば全ての丸太は均一な大きさになる。
// その和をKに合わせればそもそも計算がいらないか。A[i]=min*(n[i]+1)
int main() {
  int N, K;
  scanf("%d %d", &N, &K);

  LL A[maxN];

  LL sumA = 0;
  vector<vector<LL>> dn;
  rep(i, N) scanf("%ld", &A[i]);
  sort(A, A + N);
  rep(i, N) sumA += A[i];
  int n;
  int sumn = 0;
  rep(i, N) {
    if (sumA != 0)
      n = K * A[i] / sumA;
    else
      n = 0;
    sumn += n;
    dn.push_back({floor_usr(A[i], (n + 1)), A[i], n});
  }

  vector<LL> B;
  sort(dn.begin(), dn.begin() + N, greater<vector<LL>>());
  rep(i, K - sumn) {
    dn[i % N][2]++;
    dn[i % N][0] = floor_usr(dn[i % N][1], dn[i % N][2] + 1);
  }
  sort(dn.begin(), dn.begin() + N, greater<vector<LL>>());
  printf("%ld", dn[0][0]);
  // 真の値より一回小さいnが得られているので、追加するiを選んで最小値を求める
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define LL long long

const int N = 2e5 + 5;

int n, k, a[N], l = 1, r, ans;

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

int32_t main() {
  std::cin >> n >> k;
  for (int i = 1; i <= n; ++i) {
    std::cin >> a[i];
    r = std::max(r, a[i]);
  }
  while (l <= r) {
    int mid = l + r + 1 >> 1;
    if (check(mid)) {
      ans = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  printf("%d", ans);
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define LL long long

const int N = 2e5 + 5;

int n, k, a[N], l, r, ans;

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

int32_t main() {
  std::cin >> n >> k;
  for (int i = 1; i <= n; ++i) {
    std::cin >> a[i];
    r = std::max(r, a[i]);
  }
  while (l <= r) {
    int mid = l + r + 1 >> 1;
    if (check(mid)) {
      ans = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  printf("%d", ans);
  return 0;
}
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++)
#define Rep(i, s, n) for (int i = s; i < n; i++)
#define per(i, s, n) for (int i = n - 1; i >= s; i--)
#define fi first
#define se second
#define all(c) c.begin(), c.end()
typedef long long int ll;
typedef long double ld;
typedef pair<ld, ll> P;

void Ans(bool x) {
  if (x)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

const ll INF = 1001000000;
const ll mod = 1000000007;

int main() {
  ll n, k;
  cin >> n >> k;
  ll a[n];
  ll m = 0;
  ll now = 0;
  rep(i, n) {
    cin >> a[i];
    now += a[i];
    m = max(m, a[i]);
  }

  ll nl, nh;
  nl = 1;
  nh = m;
  ll nm;

  while (nh - nl > 0) {
    nm = nl + (nh - nl) / 2;
    ll cnt = 0;
    rep(i, n) {
      if (a[i] % nm == 0) {
        cnt += a[i] / nm;
        cnt--;
      } else {
        cnt += a[i] / nm;
      }
    }
    if (cnt > k) {
      nl = nm + 1;
    } else {
      nh = nm;
    }
  }
  cout << nh << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, s, n) for (int i = s; i < n; i++)
#define per(i, s, n) for (int i = n - 1; i >= s; i--)
#define fi first
#define se second
#define all(c) c.begin(), c.end()
typedef long long int ll;
typedef long double ld;
typedef pair<ld, ll> P;

void Ans(bool x) {
  if (x)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

const ll INF = 10010000;
const ll mod = 1000000007;

int main() {
  ll n, k;
  cin >> n >> k;
  ll a[n];
  ll now = 0;
  rep(i, n) {
    cin >> a[i];
    now += a[i];
  }

  now /= (n + k);

  ll cnt = k + 1;
  while (cnt > k) {
    cnt = 0;
    rep(i, n) {
      if (a[i] % now == 0) {
        cnt += a[i] / now;
        cnt--;
      } else {
        cnt += a[i] / now;
      }
    }
    now++;
  }
  cout << now - 1 << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

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

#define rep(i, n) for (int i = 0; i < (n); ++i)

const int MAXN = 2e5 + 1;
ll N, K;
ll A[MAXN];

bool chk(ll l) {
  ll totalCut = 0;
  rep(i, N) { totalCut += (A[i] + l - 1) / l - 1; }
  return totalCut <= K;
}

int main() {
  cin >> N >> K;
  rep(i, N) cin >> A[i];
  ll ans = -1;
  ll lo = 1, hi = 1e9;
  while (lo <= hi) {
    ll mid = (lo + hi) / 2;
    if (chk(mid)) {
      ans = mid;
      hi = mid - 1;
    } else {
      lo = mid + 1;
    }
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

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

#define rep(i, n) for (int i = 0; i < (n); ++i)

const int MAXN = 2e5 + 1;
ll N, K;
ll A[MAXN];

bool chk(ll l) {
  ll totalCut = 0;
  rep(i, N) { totalCut += (A[i] + l - 1) / l - 1; }
  return totalCut <= K;
}

int main() {
  cin >> N >> K;
  rep(i, N) cin >> A[i];
  ll ans = -1;
  ll lo = 0, hi = 1e9;
  while (lo <= hi) {
    ll mid = (lo + hi) / 2;
    if (chk(mid)) {
      ans = mid;
      hi = mid - 1;
    } else {
      lo = mid + 1;
    }
  }
  cout << ans << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 10;
ll a[maxn], k, n;
bool check(ll x) {
  ll c = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] % x != 0)
      c += a[i] / x;
    else
      c += a[i] / x - 1;
  }
  if (c <= k)
    return true;
  return false;
}

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

Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
using namespace std;
typedef long long ll;
const int maxn = 5e5 + 10;
ll a[maxn], k, n;
bool check(ll x) {
  ll c = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] % x != 0)
      c += a[i] / x;
    else
      c += a[i] / x - 1;
  }
  if (c <= k)
    return true;
  return false;
}

int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  ll l = 0, r = 1e9, ans;
  while (l <= r) {
    ll mid = (l + r) >> 1;
    if (check(mid)) {
      r = mid - 1;
      ans = mid;
    } else
      l = mid + 1;
  }
  cout << ans;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define io std::ios::sync_with_stdio(false)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int P = 1e9 + 7, INF = 0x3f3f3f3f;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int qpow(int a, int n) {
  int r = 1 % P;
  for (a %= P; n; a = a * a % P, n >>= 1)
    if (n & 1)
      r = r * a % P;
  return r;
}
const int maxn = 2e5 + 50;

int a[maxn];
int n, k;
int check(int x) {
  int kk = 0;
  for (int i = 1; i <= n; i++) {
    kk += (a[i] - 1) / x;
  }
  if (kk > k)
    return 0;
  else
    return 1;
}
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  int l = 1, r = 1e9;
  int ans = 0;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (check(mid)) {
      r = mid - 1;
      ans = mid;
    } else {
      l = mid + 1;
    }
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define io std::ios::sync_with_stdio(false)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int P = 1e9 + 7, INF = 0x3f3f3f3f;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int qpow(int a, int n) {
  int r = 1 % P;
  for (a %= P; n; a = a * a % P, n >>= 1)
    if (n & 1)
      r = r * a % P;
  return r;
}
const int maxn = 1e5 + 10;

int a[maxn];
int n, k;
int check(int x) {
  int kk = 0;
  for (int i = 1; i <= n; i++) {
    kk += (a[i] - 1) / x;
  }
  if (kk > k)
    return 0;
  else
    return 1;
}
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  int l = 1, r = 1e9;
  int ans = 0;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (check(mid)) {
      r = mid - 1;
      ans = mid;
    } else {
      l = mid + 1;
    }
  }
  cout << ans << endl;
}