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 rep1(i, n) for (int i = 1; i < n + 1; i++)
#define all(A) A.begin(), A.end()
typedef long long ll;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int maxA = *max_element(all(a));

  int ng = -1;
  int ok = maxA;

  while (abs(ok - ng) > 1) {
    int mid = (ok + ng) / 2;
    int tmp = 0;
    if (mid == 0) {
      ng = mid;
      continue;
    }
    rep(i, n) { tmp += (a[i] + mid - 1) / mid - 1; }
    if (tmp <= k)
      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 < n; i++)
#define rep1(i, n) for (int i = 1; i < n + 1; i++)
#define all(A) A.begin(), A.end()
typedef long long ll;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int maxA = *max_element(all(a));

  int ng = -1;
  int ok = maxA;

  while (abs(ok - ng) > 1) {
    int mid = (ok + ng) / 2;
    int tmp = 0;
    rep(i, n) { tmp += (a[i] + mid - 1) / mid - 1; }
    if (tmp <= k)
      ok = mid;
    else
      ng = mid;
  }

  cout << ok << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define pi 2 * asin(1.0)
#define large pow(10, 9) + 7

// template functions
/////////////////////////
long Comb(long N, long M) { // nCm
  long ans = 1;
  for (long i = N; i > N - M; i--) {
    ans = ans * i;
  }
  for (long i = M; i > 0; i--) {
    ans = ans / i;
  }
  return ans;
}
long Perm(long N, long M) { // nPm
  long ans = 1;
  for (long i = N; i > N - M; i--) {
    ans = ans * i;
  }
  return ans;
}
long Divup(long a, long b) { return (a + b - 1) / b; }
/////////////////////////

// Answer

int main() {

  long count;
  long N, K;
  cin >> N >> K;

  vector<int> A(N);
  for (long i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  sort(A.begin(), A.end());
  long ok = A.at(N - 1);
  long ng = 0;
  long mid = (ok + ng) / 2;
  while (abs(ok - ng) > 1) {
    mid = (ok + ng) / 2;
    long count = 0;
    for (long i = 0; i < N; i++) {
      count += Divup(A.at(i), mid) - 1;
    }
    if (count <= K) {
      ok = mid;
    } else {
      ng = mid;
    }
  }

  cout << ok << endl;
}

// 高精度要求→しつこくlong doubleでcast　出力はprintf("20.20Lf")とかで
// printf("%a.bLf")のとき、a-b-1が整数部分の桁数。
/*配列系の書き方
long N;
cin>>N;
vector<long> p(N);
for(long i=0;i<N;i++){
cin>>p.at(i);
}

vector<int> d(102,1);
*/


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define pi 2 * asin(1.0)
#define large pow(10, 9) + 7

// template functions
/////////////////////////
long Comb(long N, long M) { // nCm
  long ans = 1;
  for (long i = N; i > N - M; i--) {
    ans = ans * i;
  }
  for (long i = M; i > 0; i--) {
    ans = ans / i;
  }
  return ans;
}
long Perm(long N, long M) { // nPm
  long ans = 1;
  for (long i = N; i > N - M; i--) {
    ans = ans * i;
  }
  return ans;
}
/////////////////////////

// Answer

int main() {

  long count;
  long N, K;
  cin >> N >> K;

  vector<vector<int>> A(N, vector<int>(3));
  vector<long> B(N);
  for (long i = 0; i < N; i++) {
    cin >> A.at(i).at(0);
    A.at(i).at(2) = A.at(i).at(0);
    A.at(i).at(1) = 1;
  }
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());
  for (int i = 0; i < K; i++) {
    A.at(0).at(0) = (A.at(0).at(2) + A.at(0).at(1)) / (A.at(0).at(1) + 1);
    A.at(0).at(1)++;
    sort(A.begin(), A.end());
    reverse(A.begin(), A.end());
  }
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());
  cout << A.at(0).at(0) << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define PI acos(-1)
#define INF 0x3f3f3f
#define ll long long
#define pb push_back
#define mp make_pair
#define pair pair<int, int>
#define C(a) cout << a << endl;
#define CY cout << "YES" << endl;
#define CN cout << "NO" << endl;
#define Cy cout << "Yes" << endl;
#define Cn cout << "No" << endl;
#define ull unsigned long long
#define me(a) memset(a, 0, sizeof(a));
#define my(a, b) memcpy(a, b, sizeof(b));
#define cio ios::sync_with_stdio(false)
ll mod = 1e9 + 7;
ll gcd(ll a, ll b) { return (a % b == 0) ? b : gcd(b, a % b); }
ll s[250000];
ll n, k;
inline bool check(int m) {
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] != m)
      ans += s[i] / m;
    if (ans > k)
      return 0;
  }
  return ans <= k;
}
int main() {
  ll max1 = 0;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    max1 = max(max1, s[i]);
  }
  ll l = 1, r = max1, mid;
  int m;
  int ans = 1;
  while (l < r) {

    m = (l + r) / 2;
    if (check(m)) {
      r = m;
      ans = m;
    } else
      l = m + 1;
  }
  cout << r << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define PI acos(-1)
#define INF 0x3f3f3f
#define ll long long
#define pb push_back
#define mp make_pair
#define pair pair<int, int>
#define C(a) cout << a << endl;
#define CY cout << "YES" << endl;
#define CN cout << "NO" << endl;
#define Cy cout << "Yes" << endl;
#define Cn cout << "No" << endl;
#define ull unsigned long long
#define me(a) memset(a, 0, sizeof(a));
#define my(a, b) memcpy(a, b, sizeof(b));
#define cio ios::sync_with_stdio(false)
ll mod = 1e9 + 7;
ll gcd(ll a, ll b) { return (a % b == 0) ? b : gcd(b, a % b); }
ll s[250000];
ll n, k;
bool check(ll x) {
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] != x)
      ans += s[i] / x;
    if (ans > k) {
      return 0;
    }
  }
  return ans <= k;
}
int main() {
  ll max1 = 0;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    max1 = max(max1, s[i]);
  }
  //	if(k==0){
  //		cout<<max1<<endl;
  //		return 0;
  //	}
  ll l = 0, r = max1, mid;
  int m;
  int ans = 1;
  while (l < r) {

    m = (l + r) / 2;
    if (check(m)) {
      r = m;
      ans = m;
    } else
      l = m + 1;
  }
  cout << ans << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int n, k, mid, Left, Right, len[200005];
bool Judge(int lim) {
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (len[i] % lim == 0)
      cnt += len[i] / lim - 1;
    else
      cnt += len[i] / lim;
  }
  return cnt > k;
}
int main() {
  scanf("%d%d", &n, &k), Left = 1;
  for (int i = 1; i <= n; i++)
    scanf("%d", &len[i]), Right = max(Right, len[i]);
  while (Left <= Right) {
    mid = (Left + Right) / 2;
    if (Judge(mid))
      Left = mid + 1;
    else
      Right = mid - 1;
  }
  printf("%d\\n", Left);
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int n, k, mid, Left, Right, len[200005];
bool Judge(int lim) {
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (len[i] % lim == 0)
      cnt += len[i] / lim - 1;
    else
      cnt += len[i] / lim;
  }
  return cnt > k;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++)
    scanf("%d", &len[i]), Right = max(Right, len[i]);
  while (Left <= Right) {
    mid = (Left + Right) / 2;
    if (Judge(mid))
      Left = mid + 1;
    else
      Right = mid - 1;
  }
  printf("%d\\n", Left);
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int n, k;
double mid, Left, Right, len[200005];
const double eps = 1e-6;
bool Judge(double lim) {
  int cnt = 0;
  for (int i = 1; i <= n; i++)
    cnt += ceil(len[i] / lim) - 1;
  return cnt <= k;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++)
    scanf("%lf", &len[i]), Right = max(Right, len[i]);
  while (abs(Left - Right) > eps) {
    mid = (Left + Right) / 2.0;
    if (Judge(mid))
      Right = mid;
    else
      Left = mid;
  }
  printf("%.0lf\\n", ceil(Right));
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int n, k;
double mid, Left, Right, len[200005];
const double eps = 1e-8;
bool Judge(double lim) {
  int cnt = 0;
  for (int i = 1; i <= n; i++)
    cnt += ceil(len[i] / lim) - 1;
  return cnt <= k;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++)
    scanf("%lf", &len[i]), Right = max(Right, len[i]);
  while (abs(Left - Right) > eps) {
    mid = (Left + Right) / 2.0;
    if (Judge(mid))
      Right = mid;
    else
      Left = mid;
  }
  printf("%.0lf\\n", ceil(Right));
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <queue>

using namespace std;

int main() {
  long long n, k;
  cin >> n >> k;
  int *a = new int[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int l = 1, r = 1e9;
  long long cnt = 0;
  for (int i = 0; i < n; i++) {
    cnt += a[i] - 1;
  }
  if (cnt <= k) {
    cout << 1 << endl;
    return 0;
  }
  while (r - l > 1) {
    int mid = (r + l) / 2;
    cnt = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] % mid) {
        cnt += a[i] / mid;
      } else {
        cnt += a[i] / mid - 1;
      }
    }
    if (cnt <= k)
      r = mid;
    else
      l = mid;
  }
  cout << r << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <queue>

using namespace std;

class Log {
public:
  int length;
  int max_length;
  int cnt_cut;
};

inline bool operator>=(Log a, Log b) { return a.length >= b.length; }

inline bool operator>(Log a, Log b) { return a.length > b.length; }

inline bool operator<=(Log a, Log b) { return a.length <= b.length; }

inline bool operator<(Log a, Log b) { return a.length < b.length; }

int main() {
  int n, k;
  cin >> n >> k;
  priority_queue<Log> pq;
  for (int i = 0; i < n; i++) {
    Log a;
    cin >> a.max_length;
    a.length = a.max_length;
    a.cnt_cut = 0;
    pq.push(a);
  }
  for (int i = 0; i < k; i++) {
    Log a = pq.top();
    pq.pop();
    a.cnt_cut++;
    a.length = a.max_length / (a.cnt_cut + 1);
    if (a.max_length % (a.cnt_cut))
      a.length++;
    pq.push(a);
  }
  cout << pq.top().length << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for (int i = (l), i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define pb push_back

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

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

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

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
                  'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
                  's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int main() {
  ll n, k;
  cin >> n >> k;
  ll high = 1e10, low = 1;
  vector<ll> lis(n);
  REP(i, 0, n) { cin >> lis[i]; }
  sort(ALL(lis), greater<>());
  if (k == 0) {
    cout << lis[0] << endl;
    return 0;
  }
  while (high - low > 1) {
    ll ck = k;
    ll mid = (high + low) / 2;
    REP(i, 0, n) {
      if (lis[i] <= mid) {
        continue;
      } else {
        ll c = lis[i] / mid;
        ck -= c;
      }
    }
    // cout  << mid  << " " << ck << endl;
    if (ck >= 0 || ck == k) {
      high = mid;
    } else {
      low = mid;
    }
  }
  ll ck = k;
  ll mid = low;
  REP(i, 0, n) {
    if (lis[i] <= mid) {
      continue;
    } else {
      ll c = lis[i] / mid;
      ck -= c;
    }
  }
  if (ck >= 0 || ck == k) {
    cout << low << endl;
    return 0;
  }
  cout << high << endl;
}

Error: TLE

Fixed submission:

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

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for (int i = (l), i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define pb push_back

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

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

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

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
                  'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
                  's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int main() {
  ll n, k;
  cin >> n >> k;
  ll high = 1e10, low = 1;
  priority_queue<ll> pq;
  REP(i, 0, n) {
    ll a;
    cin >> a;
    pq.push(a);
  }
  while (high - low > 1) {
    priority_queue<ll> cpq = pq;
    ll mid = (high + low) / 2;
    REP(i, 0, k) {
      ll b = cpq.top();
      cpq.pop();
      ll c = b - mid;
      cpq.push(c);
      cpq.push(mid);
    }
    if (cpq.top() <= mid) {
      high = mid;
    } else {
      low = mid;
    }
  }
  cout << high << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\\n"
const int mod = 1e9 + 7;
const int MAX = 1e6 + 7;
int a[MAX];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int l = 1, r = mod, ans = mod;
  while (l <= r) {
    int mid = (l + r) / 2, cnt = 0;
    for (int i = 0; i < n; i++)
      cnt += (a[i] - 1) / mid;
    if (cnt <= k)
      ans = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  cout << ans;
  return 0;
}

Error: WA

Fixed submission:

#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\\n"
const int mod = 1e9 + 7;
const int MAX = 1e6 + 7;
int a[MAX];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int l = 0, r = 2 * mod, ans = 2 * mod;
  while (l <= r) {
    int mid = (l + r) / 2, cnt = 0;
    for (int i = 0; i < n; i++)
      cnt += (a[i] - 1) / mid;
    if (cnt <= k)
      ans = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  cout << ans;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

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

  auto isok = [&](int m) -> bool {
    int sum = 0;
    for (auto aa : a)
      sum += (aa + m - 1) / m - 1;
    return sum <= k;
  };

  int l = 0;
  int r = 1e9;
  while (r - l > 1) {
    int m = l + (r - l) / 2;
    if (isok(m)) {
      r = m;
    } else {
      l = m;
    }
  }
  cout << r << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

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

  auto isok = [&](int m) -> bool {
    int sum = 0;
    for (auto aa : a)
      sum += (aa + m - 1) / m - 1;
    return sum <= k;
  };

  int l = -1;
  int r = *max_element(a.begin(), a.end());
  while (r - l > 1) {
    int m = l + (r - l) / 2;
    if (isok(m)) {
      r = m;
    } else {
      l = m;
    }
  }
  cout << r << endl;

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

#include <bits/stdc++.h>
#define int long long
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)
using namespace std;
int n, k, a[200005], mx;
bool check(int x) {
  /*
  priority_queue<int,vector<int>,less<int> > pq;
  rep(i,1,n) pq.push(a[i]);
  rep(i,1,k) {
      int kk=pq.top();pq.pop();
      if(kk>x) pq.push(kk-x),pq.push(x);
      else return true;
  }
  while(!pq.empty()) {
      if(pq.top()>x) return false;
      pq.pop();
  }
  return true;*/
  int now = 0;
  rep(i, 1, n) {
    int kk = a[i] / x;
    if (a[i] % x == 0)
      kk--;
    now += kk;
    if (now > k)
      return false;
  }
  return true;
}
signed main() {
  scanf("%lld%lld", &n, &k);
  rep(i, 1, n) scanf("%lld", &a[i]), mx = max(mx, a[i]);
  int l = 1, r = mx;
  while (l < r) {
    int mid = (l + r) >> 1;
    if (check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  printf("%lld\\n", r);
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)
using namespace std;
int n, k, a[200005], mx;
bool check(int x) {
  priority_queue<int, vector<int>, less<int>> pq;
  rep(i, 1, n) pq.push(a[i]);
  rep(i, 1, k) {
    int kk = pq.top();
    pq.pop();
    if (kk > x)
      pq.push(kk - x), pq.push(x);
    else
      return true;
  }
  while (!pq.empty()) {
    if (pq.top() > x)
      return false;
    pq.pop();
  }
  return true;
}
int main() {
  scanf("%d%d", &n, &k);
  rep(i, 1, n) scanf("%d", &a[i]), mx = max(mx, a[i]);
  int l = 1, r = mx;
  while (l < r) {
    int mid = (l + r) >> 1;
    if (check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  printf("%d\\n", l);
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define full(a) a.begin(), a.end()
#define rfull(a) a.rbegin(), a.rend()

using namespace std;
const double pi = acos(-1.0);
const double pii = 2 * pi;
const double eps = 1e-6;
const long long MOD = 1e9 + 7;

bool tf(long long lim, int n, long long k, vector<long long> &l) {
  long long ans = 0;
  for (int i = 0; i < n; i++)
    if (l[i] % lim == 0)
      ans += (l[i] / lim) - 1;
    else
      ans += (l[i] / lim);
  return ans <= k;
}

void solve() {
  int n;
  long long k;
  cin >> n >> k;
  vector<long long> l(n, 0);
  for (int i = 0; i < n; i++)
    cin >> l[i];
  long long ll = 1, rr = MOD, mid;
  while (rr - ll > 1) {
    mid = (ll + rr) / 2;
    if (tf(mid, n, k, l))
      rr = mid;
    else
      ll = mid;
  }
  if (tf(ll, n, k, l))
    rr = ll;
  cout << rr << "\\n";
}

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

  solve();
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define full(a) a.begin(), a.end()
#define rfull(a) a.rbegin(), a.rend()

using namespace std;
const double pi = acos(-1.0);
const double pii = 2 * pi;
const double eps = 1e-6;
const long long MOD = 1e9 + 7;

bool tf(long long lim, int n, long long k, vector<long long> &l) {
  long long ans = 0;
  for (int i = 0; i < n; i++)
    if (l[i] % lim == 0)
      ans += (l[i] / lim) - 1;
    else
      ans += (l[i] / lim);
  return ans <= k;
}

void solve() {
  int n;
  long long k;
  cin >> n >> k;
  vector<long long> l(n, 0);
  for (int i = 0; i < n; i++)
    cin >> l[i];
  long long ll = 0, rr = MOD, mid;
  while (rr - ll > 1) {
    mid = (ll + rr) / 2;
    if (tf(mid, n, k, l))
      rr = mid;
    else
      ll = mid;
  }
  if (tf(ll, n, k, l))
    rr = ll;
  cout << rr << "\\n";
}

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

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

/*
Author: Vishal Singh
(singhvishal0304@gmail.com)

"The days that break you are the days that make you."

*/

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

#define fastio()                                                               \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);

#define md 1000000007

#define lli long long int
#define pb push_back
#define mp make_pair
#define vvi(r, c) vector<vector<lli>> v(r, vector<lli>(c));
#define fi first
#define se second
#define mem(arr, x) memset(arr, x, sizeof(arr))

lli power(lli a, lli b) {
  if (b == 0)
    return 1;
  if (b % 2)
    return ((a % md) * (power(a, b - 1))) % md;
  else {
    lli x = power(a, b / 2);
    return (x * x) % md;
  }
}

lli numCuts(vector<lli> &a, lli mid) {
  int n = a.size();
  lli sum = 0;
  for (int i = 0; i < n; i++) {
    lli x = a[i] / mid;
    if (a[i] % mid)
      x++;
    sum += x - 1;
  }
  return sum;
}
lli bin_search(vector<lli> &a, lli l, lli r, lli k) {
  if (l < r) {
    lli mid = l + (r - l) / 2;
    if (numCuts(a, mid) > k)
      return bin_search(a, mid + 1, r, k);
    return bin_search(a, l, mid, k);
  }
  return l;
}

void solve() {
  lli n, k;
  cin >> n >> k;
  vector<lli> a(n);
  lli r = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    r = max(r, a[i]);
  }
  lli ans = bin_search(a, 1, r, k);
  cout << ans << endl;
}

int main() {
  fastio();
  int t;

  t = 1;
  while (t--) {
    solve();
  }

  return 0;
}

Error: 0

Fixed submission:

/*
Author: Vishal Singh
(singhvishal0304@gmail.com)

"The days that break you are the days that make you."

*/

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

#define fastio()                                                               \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);

#define md 1000000007

#define lli long long int
#define pb push_back
#define mp make_pair
#define vvi(r, c) vector<vector<lli>> v(r, vector<lli>(c));
#define fi first
#define se second
#define mem(arr, x) memset(arr, x, sizeof(arr))

lli power(lli a, lli b) {
  if (b == 0)
    return 1;
  if (b % 2)
    return ((a % md) * (power(a, b - 1))) % md;
  else {
    lli x = power(a, b / 2);
    return (x * x) % md;
  }
}

lli numCuts(vector<lli> &a, lli mid) {
  int n = a.size();
  lli sum = 0;
  for (int i = 0; i < n; i++) {
    lli x = a[i] / mid;
    if (a[i] % mid)
      x++;
    sum += x - 1;
  }
  return sum;
}
lli bin_search(vector<lli> &a, lli l, lli r, lli k) {
  if (l < r) {
    lli mid = l + (r - l) / 2;
    if (numCuts(a, mid) > k)
      return bin_search(a, mid + 1, r, k);
    return bin_search(a, l, mid, k);
  }
  return l;
}

void solve() {
  lli n, k;
  cin >> n >> k;
  vector<lli> a(n);
  lli r = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    r = max(r, a[i]);
  }
  lli ans = bin_search(a, 0, r, k);
  cout << ans << endl;
}

int main() {
  fastio();
  int t;

  t = 1;
  while (t--) {
    solve();
  }

  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 (auto &i : A)
    cin >> i;

  auto ok = [&](auto x) {
    long long k = 0;
    for (auto &a : A)
      k += (a - 1) / x;
    return k <= K;
  };

  int l = 0, h = 1e9;
  while (1 < h - l) {
    auto m = (l + h) / 2;
    if (ok(m))
      h = m;
    else
      l = m;
  }
  cout << h << 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 (auto &i : A)
    cin >> i;

  auto ok = [&](auto x) {
    long long k = 0;
    for (auto &a : A)
      k += (a - 1) / x;
    return k <= K;
  };

  int l = -1, h = 1e9;
  while (1 < h - l) {
    auto m = (l + h) / 2;
    if (ok(m))
      h = m;
    else
      l = m;
  }
  cout << h << endl;
}