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

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define dup(x, y) (((x) + (y)-1) / (y))
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const double EPS = 1e-10;
const int INF = 1e9;
const ll LINF = 1e15;
const int MOD = 1e9 + 7;
const double PI = acos(-1);
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
typedef pair<ll, ll> pll;
long long n, k;
long long a[200005];

bool check(int x) {
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    cnt += (a[i] - 1) / x;
  }
  if (cnt <= k)
    return true;
  else
    return false;
}

int main() {

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

  long long left = 0;
  long long right = INF;

  while (right - left > 1) {

    long long mid = (left + right) / 2;

    if (check(mid))
      right = mid;
    else
      left = mid;
    // cout << left << " " << right << endl;
  }
  cout << right << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define dup(x, y) (((x) + (y)-1) / (y))
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const double EPS = 1e-10;
const int INF = 1e9;
const ll LINF = 1e15;
const int MOD = 1e9 + 7;
const double PI = acos(-1);
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
typedef pair<ll, ll> pll;
long long n, k;
long long a[200005];

bool check(int x) {
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    cnt += (a[i] - 1) / x;
  }
  if (cnt <= k)
    return true;
  else
    return false;
}

int main() {

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

  long long left = -1;
  long long right = INF;

  while (right - left > 1) {

    long long mid = (left + right) / 2;

    if (check(mid))
      right = mid;
    else
      left = mid;
    // cout << left << " " << right << endl;
  }
  cout << right << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll LINF = 1001002003004005006LL;
const int INF = 1001001001;

const int mod = 1000000007;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int l = 0;
  int r = 1e9;
  auto f = [&](int x) {
    int tmp = 0;
    rep(i, n) { tmp += (a[i] - 1) / x; }
    return tmp <= k;
  };
  while (r - l > 1) {
    int c = (l + r) / 2;
    if (f(c))
      r = c;
    else
      l = c;
  }
  cout << r << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll LINF = 1001002003004005006LL;
const int INF = 1001001001;

const int mod = 1000000007;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int mx = -1;
  rep(i, n) mx = max(mx, a[i]);
  if (k == 0) {
    cout << mx << endl;
    return 0;
  }
  double lb = 0;
  double ub = mx;

  auto check = [&](int m) {
    int num = 0;
    rep(i, n) {
      num += (int)(a[i] / m);
      // cout << "i: " << i << " num: " << (int)(a[i]/m) << endl;
    }
    if (num > k)
      return false;
    else
      return true;
  };

  for (int i = 0; i < 100; ++i) {
    double mid = (ub + lb) / 2;
    // cout <<  "lb: " << lb << " ub: " << ub << endl;
    if (check(mid))
      ub = mid;
    else
      lb = mid;
  }
  cout << (int)ceil(ub) << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

vector<int> v;
int k;

bool can(int len) {
  if (len == 0)
    return false;
  int cnt = k;
  for (int i = v.size() - 1; i >= 0; i--) {
    if (v[i] > len)
      cnt -= (v[i] / len);
    if (cnt < 0)
      return false;
  }
  return true;
}
int main() {
  int n;
  cin >> n >> k;
  v.resize(n);
  rep(i, n) cin >> v[i];
  int l = 0, r = 1e9 + 1;
  for (int i = 0; i < 100; i++) {
    int mid = (l + r) / 2;
    if (can(mid))
      r = mid;
    else
      l = mid;
  }
  cout << r << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

vector<int> v;
int k;

bool can(int len) {
  int cnt = k;
  for (int i = v.size() - 1; i >= 0; i--) {
    if (v[i] > len)
      cnt -= (v[i] / len);
    if (cnt < 0)
      return false;
  }
  return true;
}
int main() {
  int n;
  cin >> n >> k;
  v.resize(n);
  rep(i, n) cin >> v[i];
  int l = 0, r = 1e9 + 1;
  for (int i = 0; i < 100; i++) {
    int mid = (l + r) / 2;
    if (can(mid))
      r = mid;
    else
      l = mid;
  }
  cout << r << endl;

  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 < (n); i++)

typedef long long ll;
typedef pair<int, int> P;
typedef map<int, int> MP;

#define INF 1e9

int main(int, char **) {
  int n, k;
  cin >> n >> k;

  vector<int> a(n);
  int l = 1, r = 0, mid;
  rep(i, n) {
    cin >> a[i];
    r = max(r, a[i]);
  }

  while (r > l) {
    mid = (l + r) / 2;
    int cnt = 0;
    rep(i, n) { cnt += (a[i] + mid - 1) / mid - 1; }
    if (cnt <= k) {
      r = mid;
    } else {
      l = mid + 1;
    }
  }

  cout << l << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

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

typedef long long ll;
typedef pair<int, int> P;
typedef map<int, int> MP;

#define INF 1e9

int main(int, char **) {
  int n, k;
  cin >> n >> k;

  vector<int> a(n);
  int l = 0, r = 0, mid;
  rep(i, n) {
    cin >> a[i];
    r = max(r, a[i]);
  }

  while (r > l) {
    mid = (l + r) / 2;
    int cnt = 0;
    rep(i, n) { cnt += (a[i] + mid - 1) / mid - 1; }
    if (cnt <= k) {
      r = mid;
    } else {
      l = mid + 1;
    }
  }

  cout << l << endl;

  return 0;
}
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);
  for (int i = 0; i < n; i++)
    cin >> a[i];

  // 全丸太の長さをx以下にするのに必要な回数がk以下になる最小のxを二分探索？
  double left = 0, right = 1e9; // left:不可能 right:可能
  int64_t count = 0;
  while (right - left > 1) {
    double x = (left + right) / 2.0;
    count = 0;
    for (int i = 0; i < n; i++) {
      double cut = a[i] / x;
      if (cut == (int)cut)
        cut -= 1;
      count += (int)cut;
    }
    if (count <= k)
      right = x;
    else
      left = x;
  }

  int ans = (int)right; // ここで right<1 だと ans=0 で divided by 0 になる
  if (ans == 0) {
    cout << 1 << endl;
    return 0;
  }
  count = 0;
  for (int i = 0; i < n; i++) {
    count += (a[i] - 1) / ans;
  }
  if (count > k)
    ans++;
  cout << ans << endl;
}

Error: 0

Fixed submission:

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

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

  // 全丸太の長さをx以下にするのに必要な回数がk以下になる最小のxを二分探索？
  double left = 0, right = 1e9; // left:不可能 right:可能
  while (right - left > 1) {
    double x = (left + right) / 2.0;
    int64_t count = 0;
    for (int i = 0; i < n; i++) {
      double cut = a[i] / x;
      if (cut == (int)cut)
        cut -= 1;
      count += (int)cut;
    }
    if (count <= k)
      right = x;
    else
      left = x;
  }
  int ans = (int)right;
  int64_t count = 0;
  for (int i = 0; i < n; i++) {
    count += (a[i] - 1) / ans;
  }
  if (count > k)
    ans++;
  cout << ans << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long
bool solve(long double mid, ll n, ll a[], ll k) {
  bool ok = 0;
  for (int i = 0; i < n; ++i) {
    ll req = a[i] / mid;
    k -= req;
  }
  if (k >= 0)
    return false;
  else
    return true;
}
int main() {
  ll n, k;
  cin >> n >> k;
  ll a[n];
  for (int i = 0; i < n; ++i)
    cin >> a[i];
  sort(a, a + n);
  if (k == 0) {
    cout << a[n - 1] << "\\n";
    return 0;
  }
  long double lo = 0, hi = 1e12;
  int count = 0;
  while (1) {
    ++count;
    if (count == 150)
      break;
    long double mid = lo + (hi - lo) / 2;
    if (mid == 0)
      continue;
    // cout << lo << " " << hi << " " << mid << " " << solve(mid,n,a,k) << "\\n";
    if (solve(mid, n, a, k))
      lo = mid;
    else
      hi = mid;
  }
  cout << (ll)ceil(lo) << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
bool solve(ll mid, ll n, ll a[], ll k) {
  bool ok = 0;
  for (int i = 0; i < n; ++i) {
    ll req = a[i] / mid;
    k -= req;
  }
  if (k >= 0)
    return false;
  else
    return true;
}
int main() {
  ll n, k;
  cin >> n >> k;
  ll a[n];
  for (int i = 0; i < n; ++i)
    cin >> a[i];
  sort(a, a + n);
  if (k == 0) {
    cout << a[n - 1] << "\\n";
    return 0;
  }
  ll lo = 0, hi = 1e12;
  int count = 0;
  while (lo < hi) {
    ++count;
    if (count == 100)
      break;
    ll mid = lo + (hi - lo) / 2;
    // cout << lo << " " << hi << " " << mid << " " << solve(mid,n,a,k) << "\\n";
    if (solve(mid, n, a, k))
      lo = mid + 1;
    else
      hi = mid;
  }
  cout << lo << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define GO                                                                     \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define int long long int

const int maxr = 2e5 + 5;
int arr[maxr];
int n, k;
bool cheak(int x) {
  int count = 0;
  for (int i = 0; i < n; i++) {
    count += ((arr[i] - 1) / x);
  }
  return count <= k;
}

int binary_search(int low, int high) {
  int ans;
  while (low <= high) {
    int mid = (low + high) / 2;
    if (cheak(mid)) {
      ans = mid;
      high = mid - 1;
    } else {
      low = mid + 1;
    }
  }
  return ans;
}

int32_t main() {
  GO;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  int ans = binary_search(1, 1e12);
  cout << ans << endl;
  return 0;
}

//!

Error: TLE

Fixed submission:

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

#define GO                                                                     \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define int long long int

const int maxr = 2e5 + 5;

int32_t main() {
  GO;
  int n, k;
  cin >> n >> k;

  priority_queue<pair<double, pair<int, double>>> q;
  for (int i = 0; i < n; i++) {
    double x;
    cin >> x;
    q.push({x, {1, x}});
  }
  while (k--) {
    auto top = q.top();
    q.pop();
    top.second.first++;
    q.push({top.second.second / top.second.first,
            {top.second.first, top.second.second}});
  }
  auto ans = q.top();
  int fans = ceil(ans.first);
  cout << fans << endl;
  return 0;
}

//!
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int l = 0, r = 1e9;
  while (r - l > 1) {
    int x = (l + r) / 2;
    auto f = [&](int x) {
      ll now = 0;
      rep(i, n) now += (a[i] - 1) / x;
      return now <= k;
    };
    if (f(x))
      r = x;
    else
      l = x;
  }
  cout << r << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int l = 0, r = 1e9;
  while (r - 1 > 1) {
    int x = (l + r) / 2;
    auto f = [&](int x) {
      ll now = 0;
      rep(i, n) now += (a[i] - 1) / x;
      return now <= k;
    };
    if (f(x))
      r = x;
    else
      l = x;
  }
  cout << r << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define vi vector<int>
using namespace std;
const int INF = 1001001001;
const int MOD = 1e9 + 7;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
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 (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  cin.tie(0), ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  vi a(n);
  rep(i, n) cin >> a[i];
  int l = 0, r = INF;
  while (1 < r - l) {
    int mid = (l + r) / 2;
    auto f = [&](int x) {
      ll cnt = 0;
      rep(i, n) cnt += (a[i] - 1) / x;
      return cnt <= k;
    };
    if (f(mid))
      r = mid;
    else
      l = mid;
  }
  cout << r;
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define vi vector<int>
using namespace std;
const int INF = 1001001001;
const int MOD = 1e9 + 7;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
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 (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  cin.tie(0), ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  vi a(n);
  rep(i, n) cin >> a[i];
  int l = 0, r = 1e9;
  while (l < r) {
    int mid = (l + r) / 2;
    auto f = [&](int x) {
      ll cnt = 0;
      rep(i, n) cnt += (a[i] - 1) / x;
      return cnt <= k;
    };
    if (f(mid))
      r = mid;
    else
      l = mid + 1;
  }
  cout << l;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
bool isok(vector<int> &v, int mini, int k) {
  int cnt = 0;
  for (auto i : v) {
    if (i > mini) {
      if (i % mini == 0)
        cnt += (i / mini) - 1;
      else
        cnt += ((i + mini) / mini) - 1;
    }
  }

  if (cnt <= k) {
    return true;
  } else {
    return false;
  }
}
int main() {
  int n, k;
  cin >> n >> k;

  vector<int> v(n);

  for (auto &i : v) {
    cin >> i;
  }

  int mini = 1, maxi = 1e9 + 100;

  while (mini < maxi) {
    int mid = mini + (maxi - mini) / 2;
    if (isok(v, mid, k)) {
      maxi = mid;
    } else {
      mini = mid + 1;
    }
  }

  cout << mini << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
bool isok(vector<int> &v, int mini, int k) {
  int cnt = 0;
  for (auto i : v) {
    if (i > mini) {
      if (i % mini == 0)
        cnt += i / mini;
      else
        cnt += (i + mini) / mini;
    }
  }

  if (cnt <= k) {
    return true;
  } else {
    return false;
  }
}
int main() {
  int n, k;
  cin >> n >> k;

  vector<int> v(n);

  for (auto &i : v) {
    cin >> i;
  }

  int mini = 1, maxi = 1e9 + 100;

  while (mini <= maxi) {
    int mid = mini + (maxi - mini) / 2;
    if (isok(v, mid, k)) {
      maxi = mid;
    } else {
      mini = mid + 1;
    }
  }

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

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

#define mp make_pair
#define pb push_back
#define fiint(a) memset(a, 0, sizeof(a))

typedef long long ll;
typedef long double ld;

ll func(ll arr[], ll n, ll mid) {
  if (mid == 0)
    return INT_MAX;
  ll ans = 0;
  for (ll i = 0; i < n; i++) {
    ans += (arr[i] - 1) / mid;
  }
  // cout<<mid<<" "<<ans<<"\\n";
  return ans;
}

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

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

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

  ll low = 0, high = 1e9 + 10;
  while (low < high) {
    ll mid = low + (high - low) / 2;
    ll cut = func(arr, n, mid);

    if (cut > k)
      low = mid + 1;
    else
      high = mid;
  }
  cout << low << "\\n";

  return 0;
}


Error: 0

Fixed submission:

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

#define mp make_pair
#define pb push_back
#define fiint(a) memset(a, 0, sizeof(a))

typedef long long ll;
typedef long double ld;

int func(int arr[], int n, ll mid) {
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += (arr[i] - 1) / mid;
  }
  // cout<<mid<<" "<<ans<<"\\n";
  return ans;
}

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

  int n, k;
  cin >> n >> k;

  int arr[n];
  for (int i = 0; i < n; i++)
    cin >> arr[i];

  ll low = 0, high = 1e9 + 10;
  while (low < high) {
    ll mid = low + (high - low) / 2;
    int cut = func(arr, n, mid);

    if (cut > k)
      low = mid + 1;
    else
      high = mid;
  }
  cout << low << "\\n";

  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define req(i, n) for (int i = 1; i <= n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define ALL(a) a.begin(), a.end()
#define PI acos(-1)
using namespace std;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  std::fill((T *)array, (T *)(array + N), val);
}
typedef long long int ll;
typedef long double ld;
const int MOD = 1e9 + 7;
int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0}, sum = 0, k;
vector<int> a;
bool check(int x) {
  int cnt = 0;
  for (int i : a) {
    int kk = (i - 1) / x + 1;
    if (kk * x < i)
      kk++;
    cnt += kk - 1;
  }
  if (cnt > k)
    return 1;
  else
    return 0;
}
int main() {
  int n;
  cin >> n >> k;
  a.resize(n);
  rep(i, n) cin >> a[i];
  int right = 1e9 + 7, left = 0;
  while (right - left > 1) {
    int mid = (right + left) / 2;
    if (check(mid))
      left = mid;
    else
      right = mid;
  }
  cout << right << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define req(i, n) for (int i = 1; i <= n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define ALL(a) a.begin(), a.end()
#define PI acos(-1)
using namespace std;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  std::fill((T *)array, (T *)(array + N), val);
}
typedef long long int ll;
typedef long double ld;
const int MOD = 1e9 + 7;
int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0}, sum = 0, k;
vector<int> a;
bool check(int x) {
  int cnt = 0;
  for (int i : a) {
    int aa = i;
    req(j, 1e9) {
      if ((aa - 1) / j + 1 <= x)
        break;
      cnt++;
    }
  }
  if (cnt > k)
    return 1;
  else
    return 0;
}
int main() {
  int n;
  cin >> n >> k;
  a.resize(n);
  rep(i, n) cin >> a[i];
  int right = 1e9 + 7, left = 0;
  while (right - left > 1) {
    int mid = (right + left) / 2;
    if (check(mid))
      left = mid;
    else
      right = mid;
  }
  cout << right << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define fast                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define int long long
#define endl "\\n"
using namespace std;

int arr[200005];
int n, k;

bool check(int cuts) {
  int req = 0;
  for (int i = 0; i < n; i++) {
    req += ((arr[i] + cuts - 1) / cuts - 1);
  }
  return req <= k;
}

int32_t main() {

  fast cin >> n >> k;

  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  int left = 1, right = (int)1e10 + 5;

  int ans = 0;
  while (left <= right) {
    int mid = (left + right) / 2;
    if (check(mid)) {
      ans = mid;
      right = mid - 1;
    } else {
      left = mid + 1;
    }
  }
  cout << ans << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define fast                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define int long long
#define endl "\\n"
using namespace std;

int arr[200005];
int n, k;

bool check(int cuts) {
  int req = 0;
  for (int i = 0; i < n; i++) {
    req += ((arr[i] + cuts - 1) / cuts - 1);
  }
  return req <= k;
}

int32_t main() {

  fast cin >> n >> k;

  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  int left = 0, right = (int)1e10 + 5;

  int ans = 0;
  while (left <= right) {
    int mid = (left + right) / 2;
    if (check(mid)) {
      ans = mid;
      right = mid - 1;
    } else {
      left = mid + 1;
    }
  }
  cout << ans << endl;

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

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

template <class TH> void _dbg(const char *sdbg, TH h) {
  cerr << sdbg << '=' << h << endl;
}
template <class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while (*sdbg != ',')
    cerr << *sdbg++;
  cerr << '=' << h << ',';
  _dbg(sdbg + 1, a...);
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

typedef long long ll;
string s;
const int maxn = 2e5 + 100;
int a[maxn];
int main() {
  int n, k;
  cin >> n >> k;
  int maxx = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (a[i] > maxx)
      maxx = a[i];
  }
  int l = 1, r = maxx;
  while (l < r) {
    int mid = (l + r) >> 1;
    int res = k;
    for (int i = 0; i < n; ++i) {
      if (a[i] % mid == 0)
        res -= a[i] / mid - 1;
      else
        res -= a[i] / mid;
    }
    debug(l, r, mid, res);

    if (res < 0)
      l = mid + 1;
    else
      r = mid;
  }
  cout << l << endl;
  return 0;
}

Error: 0

Fixed submission:

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

template <class TH> void _dbg(const char *sdbg, TH h) {
  cerr << sdbg << '=' << h << endl;
}
template <class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while (*sdbg != ',')
    cerr << *sdbg++;
  cerr << '=' << h << ',';
  _dbg(sdbg + 1, a...);
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

typedef long long ll;
string s;
const int maxn = 2e5 + 100;
int a[maxn];
int main() {
  int n, k;
  cin >> n >> k;
  int maxx = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (a[i] > maxx)
      maxx = a[i];
  }
  int l = 0, r = maxx;
  while (l < r) {
    int mid = (l + r) >> 1;
    int res = k;
    for (int i = 0; i < n; ++i) {
      if (a[i] % mid == 0)
        res -= a[i] / mid - 1;
      else
        res -= a[i] / mid;
    }
    debug(l, r, mid, res);

    if (res < 0)
      l = mid + 1;
    else
      r = mid;
  }
  cout << l << endl;
  return 0;
}