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

#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define sz(x) int(x.size())
#define bitsz(x) int(__builtin_popcount(x))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb(x) push_back(x)
#define INF 1e9
#define LINF 1e18
#define mod 1000000007
template <class T> inline bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> inline string toString(const T &a) {
  ostringstream oss;
  oss << a;
  return oss.str();
};
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
const int di[4] = {1, 0, -1, 0};
const int dj[4] = {0, 1, 0, -1};

int main() {
  int n;
  cin >> n;
  int k;
  cin >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int lb = 0, ub = INF;
  auto C = [&](int x) {
    int num = 0;
    rep(i, n) {
      int tmp = a[i] / x;
      if (a[i] % x == 0)
        tmp--;
      num += tmp;
    }
    if (num <= k)
      return true;
    else
      return false;
  };
  while (ub - lb > 1) {
    int mid = (lb + ub) / 2;
    if (C(mid))
      ub = mid;
    else
      lb = mid;
  }
  cout << ub << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define sz(x) int(x.size())
#define bitsz(x) int(__builtin_popcount(x))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb(x) push_back(x)
#define INF 1e9
#define LINF 1e18
#define mod 1000000007
template <class T> inline bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> inline string toString(const T &a) {
  ostringstream oss;
  oss << a;
  return oss.str();
};
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
const int di[4] = {1, 0, -1, 0};
const int dj[4] = {0, 1, 0, -1};

int main() {
  int n;
  cin >> n;
  int k;
  cin >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int lb = -1, ub = INF;
  auto C = [&](int x) {
    int num = 0;
    rep(i, n) {
      int tmp = a[i] / x;
      if (a[i] % x == 0)
        tmp--;
      num += tmp;
    }
    if (num <= k)
      return true;
    else
      return false;
  };
  while (ub - lb > 1) {
    int mid = (lb + ub) / 2;
    if (C(mid))
      ub = mid;
    else
      lb = mid;
  }
  cout << ub << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  int l = 1;
  // int r = -1;
  int r = 1000000000;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    // r = max(a[i],r);
  }

  while (l < r) {
    int m = l + (r - l) / 2;
    int cnt = 0;
    for (int i = 0; i < n; i++) {
      cnt += (a[i] - 1) / m;
    }
    if (cnt > k)
      l = m + 1;
    else
      r = m;
    // cout << l << " " << r << endl;
  }
  cout << r << endl;
}

Error: 0

Fixed submission:

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  int l = 0;
  // int r = -1;
  int r = 1000000000;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    // r = max(a[i],r);
  }

  while (l < r) {
    int m = l + (r - l) / 2;
    int cnt = 0;
    for (int i = 0; i < n; i++) {
      cnt += (a[i] - 1) / m;
    }
    if (cnt > k)
      l = m + 1;
    else
      r = m;
    // cout << l << " " << r << endl;
  }
  cout << r << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

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

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

#define rep(i, cc, n) for (int i = cc; i < n; ++i)
#define lrep(i, cc, n) for (long long i = cc; i < n; ++i)
#define sqrep(i, cc, n) for (long long i = cc; i * i <= n; ++i)
#define rrep(i, cc, n) for (long i = cc; i > n; --i)
#define pii pair<int, int>
#define pll pair<long long, long long>

using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const double PI = 3.1415926535;
const ll inf = 1001001001;
const ll e9 = 1000000000;
const ll mod = 1000000007;

int main() {
  int n;
  ll k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, 0, n) cin >> a[i];
  sort(a.begin(), a.end());
  // 長さを置く
  ll right = e9 + 1;
  ll left = 0;
  ll p = 0;
  if (k == 0) {
    cout << a[n - 1] << endl;
    return 0;
  }
  while (right - left > 1) {
    ll templength = (right + left) / 2;
    ll cnt = 0;
    rep(i, 0, n) {
      cnt += (a[i] + templength - 1) / templength - 1;
      if (cnt > k)
        break;
    }
    if (cnt > k) {
      // 切る回数がkより大きい＝templengthが小さすぎ
      left = templength;
    } else {
      // 切る回数がkより小さい＝templengthが大きすぎ
      right = templength;
    }
  }
  cout << right << endl;
  return 0;
  // cout << left << " " << right << endl;
}

Error: 0

Fixed submission:

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

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

#define rep(i, cc, n) for (int i = cc; i < n; ++i)
#define lrep(i, cc, n) for (long long i = cc; i < n; ++i)
#define sqrep(i, cc, n) for (long long i = cc; i * i <= n; ++i)
#define rrep(i, cc, n) for (long i = cc; i > n; --i)
#define pii pair<int, int>
#define pll pair<long long, long long>

using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const double PI = 3.1415926535;
const ll inf = 1001001001;
const ll e9 = 1000000000;
const ll mod = 1000000007;

int main() {
  int n;
  ll k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, 0, n) cin >> a[i];
  sort(a.begin(), a.end());
  // 長さを置く
  ll right = a[n - 1] + 1;
  ll left = -1;
  ll p = 0;
  if (k == 0) {
    cout << a[n - 1] << endl;
    return 0;
  }
  while (right - left > 1) {
    ll templength = (right + left) / 2;
    ll cnt = 0;
    rep(i, 0, n) {
      cnt += (a[i] + templength - 1) / templength - 1;
      if (cnt > k)
        break;
    }
    if (cnt > k) {
      // 切る回数がkより大きい＝templengthが小さすぎ
      left = templength;
    } else {
      // 切る回数がkより小さい＝templengthが大きすぎ
      right = templength;
    }
  }
  cout << right << endl;
  return 0;
  // cout << left << " " << right << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define rep(i, n) FOR(i, 0, n)
#define ROF(i, a, b) for (ll i = a; i >= b; i--)
#define per(i, a) ROF(i, a, 0)
#define pb push_back
using namespace std;
using ll = long long;
using ld = long double;
using ch = char;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ld PI = acos(-1);
const ll INF = 1e18;
struct edge {
  ll to, cost;
};
struct edge2 {
  ll from, to, cost;
};

template <typename T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template <typename T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

ll N, K;
vl A;

ll num(ll x) {
  ll res = 0;
  rep(i, N) { res += (A[i] - 1) / x; }
  return res;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> N >> K;
  A.resize(N);
  rep(i, N) { cin >> A[i]; }
  ll ok = 1e9 + 1, ng = 0;
  while (abs(ok - ng) > 1) {
    ll mid = (ok + ng) / 2;
    if (num(mid) <= K) {
      ok = mid;
    } else {
      ng = mid;
    }
  }
  cout << ok << endl;
}

Error: 0

Fixed submission:

// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define rep(i, n) FOR(i, 0, n)
#define ROF(i, a, b) for (ll i = a; i >= b; i--)
#define per(i, a) ROF(i, a, 0)
#define pb push_back
using namespace std;
using ll = long long;
using ld = long double;
using ch = char;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ld PI = acos(-1);
const ll INF = 1e18;
struct edge {
  ll to, cost;
};
struct edge2 {
  ll from, to, cost;
};

template <typename T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template <typename T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

ll N, K;
vl A;

ll num(ll x) {
  ll res = 0;
  rep(i, N) { res += (A[i] - 1) / x; }
  return res;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> N >> K;
  A.resize(N);
  rep(i, N) { cin >> A[i]; }
  ll ok = 1e9 + 1, ng = -1;
  while (abs(ok - ng) > 1) {
    ll mid = (ok + ng) / 2;
    if (num(mid) <= K) {
      ok = mid;
    } else {
      ng = mid;
    }
  }
  cout << ok << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  int arr[n];
  for (int i = 0; i < n; i++)
    cin >> arr[i];
  int ans = -1, l = 1, r = (int)1e9 + 7;
  auto possible = [&](int x) {
    int cnt = 0;
    for (int len : arr) {
      cnt += (len - 1) / x;
    }
    return cnt <= k;
  };
  while (l <= r) {
    int mid = l + (r - l) / 2;
    if (possible(mid)) {
      ans = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  cout << ans;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  int arr[n];
  for (int i = 0; i < n; i++)
    cin >> arr[i];
  int ans = -1, l = 0, r = (int)1e9;
  auto possible = [&](int x) {
    int cnt = 0;
    for (int len : arr) {
      cnt += (len - 1) / x;
    }
    return cnt <= k;
  };
  while (l <= r) {
    int mid = l + (r - l) / 2;
    if (possible(mid)) {
      ans = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  cout << ans;
}
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)
using ll = long long;
using P = pair<double, int>;

int n, k;
double divi;
double x, modify, sum;
P a;
priority_queue<P> que;

int main() {
  cin >> n >> k;
  vector<double> v(n);
  rep(i, n) { cin >> v[i]; }
  sum = 0;
  rep(i, n) { sum += v[i]; }
  rep(i, n) {
    divi = (k * v[i]) / sum;
    divi = floor(1 + divi);
    que.push(make_pair(v[i] / divi, (int)divi));
    modify += divi - 1;
  }
  k -= modify;
  rep(i, k) {
    a = que.top();
    que.pop();
    a.first *= a.second;
    a.second++;
    a.first /= a.second;
    que.push(a);
  }
  a = que.top();
  cout << (int)ceil(a.first) << 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)
using ll = long long;
using P = pair<double, int>;

int n, k;
double divi;
double x;
double sum;
P a;
priority_queue<P> que;

int main() {
  cin >> n >> k;
  vector<double> v(n);
  rep(i, n) { cin >> v[i]; }
  sum = 0;
  rep(i, n) { sum += v[i]; }
  rep(i, n) {
    divi = (k * v[i]) / sum;
    divi = floor(1 + divi);
    que.push(make_pair(v[i] / divi, (int)divi));
    k -= divi - 1;
  }
  rep(i, k) {
    a = que.top();
    que.pop();
    a.first *= a.second;
    a.second++;
    a.first /= a.second;
    que.push(a);
  }
  a = que.top();
  cout << (int)ceil(a.first) << endl;
  return 0;
}
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 < (int)n; i++)

int main() {
  int N, K;
  cin >> N >> K;
  vector<double> Ain(N);
  REP(i, N) { cin >> Ain[i]; }

  long ok = 1e9 + 1;
  long ng = 0;
  vector<double> A(N);
  while (abs(ok - ng) > 1) {

    REP(i, N) { A[i] = Ain[i]; }

    long mid = (ok + ng) / 2;
    bool flag = true;
    long count = 0;
    REP(i, N) {
      if (A[i] > mid) {
        count += floor(A[i] / mid);
        A[i] /= ceil(A[i] / mid);
      }
      if (count > K) {
        flag = false;
        break;
      }
    }
    if (flag)
      ok = mid;
    else
      ng = mid;
  }
  cout << ok << "\\n";
  return 0;
}

Error: TLE

Fixed submission:

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

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

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

  priority_queue<pair<double, int>, vector<pair<double, int>>> que;

  REP(i, N) {
    double x;
    cin >> x;
    pair<double, int> p = make_pair(x, 1);
    que.push(p);
  }
  REP(i, K) {
    pair<double, int> p = que.top();
    p.first *= p.second;
    p.second++;
    p.first /= p.second;
    que.pop();
    que.push(p);
  }

  cout << (int)ceil(que.top().first) << "\\n";

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

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

const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MX = 0; // 最大値

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define MAX(x) *max_element(ALL(x))
#define PB push_back
#define F first
#define S second

ll n, k;
vector<ll> A;

ll cut(ll mid) {
  ll res = 0;
  rep(i, n) res += ((A[i] - 1) / mid);
  return res;
}

int main() {
  cin >> n >> k;
  A.resize(n);
  rep(i, n) cin >> A[i];

  ll left = 1, right = *max_element(ALL(A));
  while (right != left) {
    ll mid = (right + left) / 2;
    if (cut(mid) > k)
      left = mid + 1;
    else
      right = mid;
  }

  cout << left << endl;

  return 0;
}

Error: WA

Fixed submission:

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

const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MX = 0; // 最大値

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define MAX(x) *max_element(ALL(x))
#define PB push_back
#define F first
#define S second

int main() {
  ll n;
  cin >> n;
  string s;
  cin >> s;
  vector<ll> w, r;

  rep(i, n) {
    if (s[i] == 'W') {
      w.PB(i);
    } else {
      r.PB(i);
    }
  }
  ll ans = 0, cnt_w = 0, cnt_r = 0, cnt = 0, lim = r.size();

  if (w.size() == n || lim == n) {
    cout << 0;
    return 0;
  }

  while (true) {
    if (cnt_r + cnt == lim)
      break;

    if (r[cnt_r] < w[cnt_w])
      cnt_r++;
    else {
      cnt_w++;
      cnt++;
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
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 = 1e9;
  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 <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 (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: Runtime Error

#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int N = 2e5 + 5;

int n, k;
int a[N];

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

void run() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int l = 1, r = INF, mid;
  while (l < r) {
    mid = (l + r) >> 1;
    if (chk(mid)) {
      r = mid;
    } else {
      l = mid + 1;
    }
  }
  cout << r << '\\n';
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  run();
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
int n, dau = 1, cuoi, K, giua, k;
int a[10000001];
bool check(int M) {
  int sl = 0;
  for (int i = 1; i <= n; i++) {
    sl += a[i] / M;
    if (a[i] % M == 0) {
      sl--;
    }
  }
  if (sl <= K) {
    return true;
  }
}

int main() {
  // freopen("test.inp","r",stdin);
  cin >> n >> K;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  dau = 1, cuoi = a[n];
  while (dau <= cuoi) {
    giua = (dau + cuoi) / 2;
    if (check(giua) == true) {
      k = giua;
      cuoi = giua - 1;
    } else {
      dau = giua + 1;
    }
  }
  cout << k << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n;
  ll k;
  cin >> n >> k;
  ll vec[n];
  ll sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> vec[i];
    sum += vec[i];
  }
  if (sum <= k) {
    cout << 1 << endl;
    return 0;
  }
  ll ng = 1, ok = 1e10, check;
  for (int q = 0; q < 40; q++) {
    if (ok - ng == 1) {
      break;
    }
    ll count = 0;
    check = (ng + ok) / 2;
    for (int i = 0; i < n; i++) {
      count += (vec[i] - 1) / check;
      if (count > k) {
        break;
      }
    }
    if (count <= k) {
      ok = check;
    } else {
      ng = check;
    }
  }
  cout << ok << endl;
}

Error: 0

Fixed submission:

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

int main() {
  int n;
  ll k;
  cin >> n >> k;
  ll vec[n];
  for (int i = 0; i < n; i++) {
    cin >> vec[i];
  }
  ll ng = 0, ok = 1e10, check;
  for (int q = 0; q < 40; q++) {
    ll count = 0;
    check = (ng + ok) / 2;
    for (int i = 0; i < n; i++) {
      count += (vec[i] - 1) / check;
      if (count > k) {
        break;
      }
    }
    if (count <= k) {
      ok = check;
    } else {
      ng = check;
    }
  }
  cout << ok << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

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

#define debug(x) cerr << x << " = "(x) << endl;
#define ll long long
#define rep(i, x, y) for (int i = x; i < y; i++)
#define rel(i, x, y) for (int i = x - 1; i >= y; i--)
#define all(x) x.begin(), x.end()

int n;
bool calc(int c, int cnt, vector<int> a) {
  rel(i, n, 0) {
    if (a[i] < c)
      return true;
    cnt -= (a[i] + c - 1) / c - 1;
    if (cnt < 0)
      return false;
  }
  return true;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int k;
  cin >> n >> k;
  vector<int> a;
  ll l = 0, r = 1e9 + 1;
  rep(i, 0, n) {
    int tmp;
    cin >> tmp;
    a.push_back(tmp);
  }
  sort(all(a));
  while (l < r - 1) {
    ll c = (r + l) / 2;
    if (calc(c, k, a)) {
      r = c;
    } else {
      l = c;
    }
    // cout << l << " " << r << endl;
  }
  cout << r << endl;
}

Error: 0

Fixed submission:

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

#define debug(x) cerr << x << " = "(x) << endl;
#define ll long long
#define rep(i, x, y) for (int i = x; i < y; i++)
#define rel(i, x, y) for (int i = x - 1; i >= y; i--)
#define all(x) x.begin(), x.end()

int n;
vector<int> a;
bool calc(int c, int cnt) {
  rel(i, n, 0) {
    if (a[i] < c)
      return true;
    cnt -= (a[i] + c - 1) / c - 1;
    if (cnt < 0)
      return false;
  }
  return true;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int k;
  cin >> n >> k;
  ll l = -1, r = 1e9 + 1;
  rep(i, 0, n) {
    int tmp;
    cin >> tmp;
    a.push_back(tmp);
  }
  sort(all(a));
  while (l < r - 1) {
    ll c = (r + l) / 2;
    if (calc(c, k)) {
      r = c;
    } else {
      l = c;
    }
    // cout << l << " " << r << endl;
  }
  cout << r << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using pll = pair<long long, long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
int n;
ll k;
vector<ll> a(n);

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

int main() {
  cin >> n >> k;
  a.resize(n);
  rep(i, n) cin >> a[i];

  ll left = -1, right = INF + 100;
  while (right - left > 1LL) {
    ll mid = (right + left) / 2;
    if (ok(mid))
      right = mid;
    else
      left = mid;
  }
  cout << right << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using pll = pair<long long, long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
ll n;
ll k;
vector<ll> a(n);

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

int main() {
  cin >> n >> k;
  a.resize(n);
  rep(i, n) cin >> a[i];

  ll left = -1, right = INF + 100;
  while (right - left > 1LL) {
    ll mid = (right + left) / 2;
    if (ok(mid))
      right = mid;
    else
      left = mid;
  }
  cout << right << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)
const long long INF = 1LL << 60;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  rep(i, N) cin >> A[i];
  int left = 0;
  int right = 1e9;
  while (right - left > 1) {
    int c = (left + right) / 2;
    ll sum = 0;
    rep(i, N) { sum += ((A[i] - 1) / c); }
    if (sum <= K)
      right = c;
    else
      left = c;
  }
  cout << right << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
const long long INF = 1LL << 60;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(K);
  rep(i, N) cin >> A[i];
  int left = 0;
  int right = 1e9;
  while (right - left > 1) {
    int c = (left + right) / 2;
    ll sum = 0;
    rep(i, N) { sum += ((A[i] - 1) / c); }
    if (sum <= K)
      right = c;
    else
      left = c;
  }
  cout << right << endl;

  return 0;
}