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;

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

  while (true) {
    ll X = minX + (maxX - minX) / 2;
    if (X == 0)
      break;
    ll c = 0;
    for (int i = 0; i < N; i++) {
      c += ((A[i] % X) == 0 ? A[i] / X - 1 : A[i] / X);
    }
    //		cout << minX << "," << X << "," << maxX  << ";" << c << endl;
    if (c <= K) {
      maxX = X;
    } else {
      minX = X;
    }
    if (maxX - minX <= 1)
      break;
  }
  cout << maxX << endl;
  return (0);
}


Error: 0

Fixed submission:

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

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

  while (true) {
    ll X = minX + (maxX - minX) / 2;
    ll c = 0;
    for (int i = 0; i < N; i++) {
      c += ((A[i] % X) == 0 ? A[i] / X - 1 : A[i] / X);
    }
    //		cout << minX << "," << X << "," << maxX  << ";" << c << endl;
    if (c <= K) {
      maxX = X;
    } else {
      minX = X;
    }
    if (maxX - minX <= 1)
      break;
  }
  cout << maxX << endl;
  return (0);
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (auto &&e : a) {
    cin >> e;
  }
  int upper = *max_element(a.begin(), a.end());
  int lower = 0;
  while (upper - lower > 1) {
    int mid = lower + (upper - lower) / 2;
    auto ok = [&](int x) {
      int cnt = 0;
      for (auto &&e : a) {
        cnt += (e - 1) / x;
      }
      return (cnt <= k);
    };
    if (ok(mid)) {
      upper = mid;
    } else {
      lower = mid;
    }
  }
  cout << upper << '\\n';
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (auto &&e : a) {
    cin >> e;
  }
  int upper = *max_element(a.begin(), a.end()) + 1;
  int lower = -1;
  while (upper - lower > 1) {
    int mid = lower + (upper - lower) / 2;
    auto ok = [&](int x) {
      int cnt = 0;
      for (auto &&e : a) {
        cnt += (e - 1) / x;
      }
      return (cnt <= k);
    };
    if (ok(mid)) {
      upper = mid;
    } else {
      lower = mid;
    }
  }
  cout << upper << '\\n';
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

// C++ Program to find the minimum of maximum
// differerence between adjacent elements
// after at most K insertions

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

int minMaxDiff(int arr[], int n, int k) {
  int max_adj_dif = *max_element(arr, arr + n);

  // If the maximum adjacent
  // difference is already zero
  if (max_adj_dif == 0)
    return 0;

  // best and worst specifies
  // range of the maximum
  // adjacent difference
  int best = 1;
  int worst = max_adj_dif;
  long long mid, required;

  while (best < worst) {

    mid = (best + worst) / 2;

    // To store the no of insertions
    // required for respective
    // values of mid
    required = 0;

    for (int i = 0; i < n; i++) {

      required += (arr[i] - 1) / mid;
    }

    // If the number of insertions
    // required exceeds K
    if (required > k)
      best = mid + 1;

    // Otherwise
    else
      worst = mid;
  }

  return worst;
}

// Driver code
int main() {

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

  cout << minMaxDiff(a, n, k);
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pi 3.14159265358979323846
#define pdd pair<double, double>
struct comp {
  bool operator()(pdd a, pdd b) {
    return (a.first / a.second) < (b.first / b.second);
  }
};
int main() {
  int n, k;
  cin >> n >> k;
  int a[n];
  priority_queue<pdd, vector<pdd>, comp> q;
  map<int, int> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    q.push({a[i], 1});
    m[a[i]] = 1;
  }

  while (k--) {
    pdd p = q.top();
    // cout<<p.first<<" "<<p.second<<"\\n";
    q.pop();
    if (m[p.first] != p.second)
      continue;
    q.push({p.first, p.second + 1});
    m[p.first] = p.second + 1;
  }
  cout << fixed << setprecision(0) << ceil(q.top().first / q.top().second);
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define int long long

const int maxn = 2e5 + 5;

int n, k, a[maxn];

bool go(int t) {
  int res = 0;
  for (int i = 0; i < n; i++) {
    res += (a[i] / t) - (a[i] % t == 0);
  }
  return res <= k;
}

signed main() {
  IOS cin >> n >> k;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int l = 0, r = *max_element(a, a + n);

  while (l < r - 1) {
    int mid = (l + r) >> 1;
    if (go(mid))
      r = mid;
    else
      l = mid + 1;
  }
  if (l and go(l))
    r = l;
  cout << r;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define int long long

const int maxn = 2e5 + 5;

int n, k, a[maxn];

bool go(int t) {
  int res = 0;
  for (int i = 0; i < n; i++) {
    res += max(0LL, (a[i] / t) - (a[i] % t == 0));
  }
  return res <= k;
}

signed main() {
  IOS cin >> n >> k;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int l = 0, r = *max_element(a, a + n);

  while (l < r - 1) {
    int mid = (l + r) >> 1;
    if (go(mid))
      r = mid;
    else
      l = mid + 1;
  }
  if (go(l))
    r = l;
  cout << r;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>

using namespace std;
int a[200000];

int main() {
  int n, k, t;
  scanf("%d%d", &n, &t);
  int i;
  int l = 0, r = 0, m;
  for (i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    if (a[i] > r)
      r = a[i];
  }
  sort(a, a + n);
  while (true) {
    m = (l + r) >> 1;
    if (m == 0) {
      printf("1\\n");
      return 0;
    }
    k = t;
    for (i = n - 1; i >= 0; --i)
      if (a[i] <= m)
        break;
      else {
        k -= (a[i] - 1) / m;
        if (k < 0)
          break;
      }
    if (k >= 0)
      r = m;
    else
      l = m;
    if (r == l + 1) {
      printf("%d\\n", r);
      break;
    }
  }
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>

using namespace std;
// #include <queue>
// #include <cmath>
int a[200000];

int main() {
  // std::priority_queue<double> q;
  int n, k, t;
  scanf("%d%d", &n, &t);
  int i;
  int l = 0, r = 0, m;
  for (i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    if (a[i] > r)
      r = a[i];
  }
  sort(a, a + n);
  while (true) {
    m = (l + r) >> 1;
    k = t;
    for (i = n - 1; i >= 0; --i)
      if (a[i] <= m)
        break;
      else {
        k -= (a[i] - 1) / m;
        if (k < 0)
          break;
      }
    if (k >= 0)
      r = m;
    else
      l = m;
    if (r == l + 1) {
      printf("%d\\n", r);
      break;
    }
  }
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

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

#define ll long long
#define VI vector<int>
#define VLL vector<ll>
#define PII pair<int, int>
#define mp make_pair
#define pb push_back
#define PI acos(-1)
#define ld long double
const int MxN = 200001;
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define RFOR(i, a, b) for (int i = a; i >= b; --i)
const int MOD = 1e9 + 7;

/* VARIABLES */
int n, k;
VI logs(MxN);
/* END OF VARIABLES */

ll fun(int v) {
  ll cnt = 0;
  FOR(i, 0, n) {
    if (logs[i] <= v)
      continue;
    int rem = (logs[i] + v - 1) / v;
    // cout << rem << " " ;
    cnt += rem - 1;
  }
  return cnt;
}

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

  cin >> n >> k;
  FOR(i, 0, n)
  cin >> logs[i];
  ll l = 1;
  ll r = 1e9;
  ll ans = 1e9;
  while (l <= r) {
    ll m = l + (r - l) / 2;
    // cout << m << " " << fun(m) << endl ;
    if (fun(m) > k)
      l = m + 1;
    else {
      ans = min(ans, m);
      r = m - 1;
    }
  }
  cout << ans;
  cout << endl;
  // cout << fun(5) ;

  return 0;
}


Error: 0

Fixed submission:

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

#define ll long long
#define VI vector<int>
#define VLL vector<ll>
#define PII pair<int, int>
#define mp make_pair
#define pb push_back
#define PI acos(-1)
#define ld long double
const int MxN = 200001;
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define RFOR(i, a, b) for (int i = a; i >= b; --i)
const int MOD = 1e9 + 7;

/* VARIABLES */
int n, k;
VI logs(MxN);
/* END OF VARIABLES */

ll fun(int v) {
  ll cnt = 0;
  FOR(i, 0, n) {
    if (logs[i] <= v)
      continue;
    int rem = (logs[i] + v - 1) / v;
    // cout << rem << " " ;
    cnt += rem - 1;
  }
  return cnt;
}

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

  cin >> n >> k;
  FOR(i, 0, n)
  cin >> logs[i];
  ll l = 0;
  ll r = 1e9;
  ll ans = 1e9;
  while (l <= r) {
    ll m = l + (r - l) / 2;
    // cout << m << " " << fun(m) << endl ;
    if (fun(m) > k)
      l = m + 1;
    else {
      ans = min(ans, m);
      r = m - 1;
    }
  }
  cout << ans;
  cout << endl;
  // cout << fun(5) ;

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

#include <bits/stdc++.h>
using namespace std;
typedef bool boool;
typedef long long ll;
#define vl vector<ll>
#define vb vector<boool>
#define vs vector<string>
#define vp vector<pair<ll, ll>>
#define vvl vector<vector<ll>>
#define vvp vector<vector<pair<ll, ll>>>
#define mod 1000000007
#define all(x) x.begin(), x.end()
#define rep1(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep2(i, s, e) for (long long i = (s); i < (long long)(e); i++)
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)

int main() {
  ll n, k;
  cin >> n >> k;
  vl vec(n);
  rep(i, n) cin >> vec[i];
  sort(all(vec));
  ll ng = 0;
  ll ok = 1000000001;
  while (abs(ok - ng) > 1) {
    ll mid = (ok + ng) / 2;
    ll sum = 0;
    rep(i, n) { sum += (vec[i] + (mid - 1)) / mid - 1; }
    if (sum <= k)
      ok = mid;
    else
      ng = mid;
  }
  cout << ok << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef bool boool;
typedef long long ll;
#define vl vector<ll>
#define vb vector<boool>
#define vs vector<string>
#define vp vector<pair<ll, ll>>
#define vvl vector<vector<ll>>
#define vvp vector<vector<pair<ll, ll>>>
#define mod 1000000007
#define all(x) x.begin(), x.end()
#define rep1(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep2(i, s, e) for (long long i = (s); i < (long long)(e); i++)
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)

int main() {
  ll n, k;
  cin >> n >> k;
  vl vec(n);
  rep(i, n) cin >> vec[i];
  sort(all(vec));
  if (k == 0) {
    cout << vec.back() << endl;
    return 0;
  }
  ll ng = -1;
  ll ok = 1000000001;
  while (abs(ok - ng) > 1) {
    ll mid = (ok + ng) / 2;
    ll sum = 0;
    rep(i, n) { sum += (vec[i] + (mid - 1)) / mid - 1; }
    if (sum <= k)
      ok = mid;
    else
      ng = mid;
  }
  cout << ok << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

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

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

  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; ++i)
    cin >> a[i];
  int lo = 1, hi = 1e10;
  while (lo < hi) {
    int mid = (lo + hi) / 2, r = 0;
    for (int i = 0; i < n; ++i) {
      r += a[i] / mid;
      if (a[i] % mid != 0)
        r++;
    }
    if (r <= n + k) {
      hi = mid;
    } else
      lo = mid + 1;
  }
  cout << hi;
}


Error: WA

Fixed submission:

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

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

  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; ++i)
    cin >> a[i];
  int lo = 0, hi = 1e10;
  while (lo < hi) {
    int mid = (lo + hi) / 2, r = 0;
    for (int i = 0; i < n; ++i) {
      r += a[i] / mid;
      if (a[i] % mid != 0)
        r++;
    }
    if (r <= n + k) {
      hi = mid;
    } else
      lo = mid + 1;
  }
  cout << hi;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

/*
AtCoder Beginner Contest 174 - E - Logs
https://atcoder.jp/contests/abc174/tasks/abc174_e
*/

#include <bits/stdc++.h>
using namespace std;
#define FAST_INP                                                               \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL)
typedef long long ll;
const ll MOD = 1000000007;

int main() {
  FAST_INP;
  // binary search
  int n, k;
  cin >> n >> k;
  vector<ll> a(n);
  ll l = 1, r = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    r = max(r, a[i]);
  }
  while (l != r) {
    int m = l + (r - l) / 2;
    ll kk = 0;
    for (int i = 0; i < n; i++) {
      kk += (a[i] - 1) / m;
    }
    if (kk <= k)
      r = m;
    else
      l = m + 1;
  }
  cout << l << endl;
  return 0;
}

Error: 0

Fixed submission:

/*
AtCoder Beginner Contest 174 - E - Logs
https://atcoder.jp/contests/abc174/tasks/abc174_e
*/

#include <bits/stdc++.h>
using namespace std;
#define FAST_INP                                                               \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL)
typedef long long ll;
const ll MOD = 1000000007;

int main() {
  FAST_INP;
  // binary search
  int n, k;
  cin >> n >> k;
  vector<ll> a(n);
  ll l = 0, r = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    r = max(r, a[i]);
  }
  while (l != r) {
    int m = l + (r - l) / 2;
    ll kk = 0;
    for (int i = 0; i < n; i++) {
      kk += (a[i] - 1) / m;
    }
    if (kk <= k)
      r = m;
    else
      l = m + 1;
  }
  cout << l << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define MAXSIZE 1000000001
#define ll long long int

using namespace std;

bool findcut(vector<ll> &logs, ll K, ll mid) {
  for (int i = 0; i < logs.size(); i++) {
    K -= (ceil((double)logs[i] / (double)mid) - 1);
    if (K < 0)
      return false;
  }
  return true;
}

ll custom_binary_search(vector<ll> &logs, ll K) {
  ll start = 1, end = MAXSIZE, mid;
  while (start < end) {
    mid = (start + end) / 2;
    if (findcut(logs, K, mid))
      end = mid;
    else
      start = mid + 1;
  }
  return end;
}

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N, K;
  cin >> N >> K;
  vector<ll> logs(N);
  for (ll i = 0; i < N; i++)
    cin >> logs[i];
  cout << custom_binary_search(logs, K) << '\\n';
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

#define MAXSIZE 1000000000
#define ll long long int

using namespace std;

ll findmax(vector<ll> &logs, vector<ll> &cuts, ll &sum, ll &K) {
  ll maximum = 0;
  for (ll i = 0; i < logs.size(); i++)
    if (ceil((double)logs[i] / (double)(cuts[i] + 1)) > maximum)
      maximum = ceil((double)logs[i] / (double)(cuts[i] + 1));
  return maximum;
}

void custom_binary_search(vector<ll> &logs, ll &K, ll mid, ll start, ll end,
                          ll &ans) {
  ll sum = 0, cut = 0;
  vector<ll> cuts(logs.size(), 0);
  if (mid == start || start == end || mid == end)
    for (ll i = 0; i < logs.size(); i++) {
      cut = (ceil((double)logs[i] / (double)mid) - 1);
      if (sum + cut > K)
        cut = K - sum;
      sum += cut;
      cuts[i] = cut;
      if (sum == K)
        break;
    }
  else
    for (ll i = 0; i < logs.size(); i++) {
      cut = (ceil((double)logs[i] / (double)mid) - 1);
      sum += cut;
      cuts[i] = cut;
    }
  if (sum > K)
    custom_binary_search(logs, K, (mid + end) / 2, mid, end, ans);
  else if (sum < K)
    custom_binary_search(logs, K, (mid + start) / 2, start, mid, ans);
  else
    ans = findmax(logs, cuts, sum, K);
}

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N, K, mid = MAXSIZE / 2, ans = 0;
  cin >> N >> K;
  vector<ll> logs(N);
  for (ll i = 0; i < N; i++)
    cin >> logs[i];
  sort(logs.begin(), logs.end());
  custom_binary_search(logs, K, mid, 1, MAXSIZE, ans);
  cout << ans << '\\n';
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;
typedef long double ld;
#define REP(i, n) for (ll i = 0LL; i < (ll)(n); i++)
#define REPR(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, n, m) for (ll i = (ll)n; i < (ll)(m); i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define INF (1LL << 62)

#define PI (acos(-1))
#define PRINT(x) std::cout << x << endl

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; }
ll countDigit(ll n) { return floor(log10(n) + 1); }
typedef pair<ll, ll> P;
static const ll dx[8] = {0, 1, 0, -1, 1, -1, 1, -1},
                dy[8] = {1, 0, -1, 0, 1, 1, -1, -1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
  for (int i = 0; i < (int)v.size(); ++i)
    os << v[i] << " ";
  return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const map<T1, T2> &m) {
  for (auto p : m)
    os << "<" << p.first << ", " << p.second << "> ";
  return os;
}

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

  vector<ll> A(N);
  REP(i, N) { cin >> A[i]; }

  ll left = 1;
  ll right = 1e9;
  while (right >= left) {
    ll mid = (left + right) / 2;
    ll tK = K + N;
    bool flag = false;
    REP(i, N) {
      ll n = (A[i] + mid - 1) / mid;
      if (n <= tK) {
        tK -= n;
      } else {
        i = N;
        flag = true;
      }
    }
    if (flag) {
      left = mid + 1;
    } else {
      right = mid - 1;
    }
  }
  cout << left << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;
typedef long double ld;
#define REP(i, n) for (ll i = 0LL; i < (ll)(n); i++)
#define REPR(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, n, m) for (ll i = (ll)n; i < (ll)(m); i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define INF (1LL << 62)

#define PI (acos(-1))
#define PRINT(x) std::cout << x << endl

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; }
ll countDigit(ll n) { return floor(log10(n) + 1); }
typedef pair<ll, ll> P;
static const ll dx[8] = {0, 1, 0, -1, 1, -1, 1, -1},
                dy[8] = {1, 0, -1, 0, 1, 1, -1, -1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
  for (int i = 0; i < (int)v.size(); ++i)
    os << v[i] << " ";
  return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const map<T1, T2> &m) {
  for (auto p : m)
    os << "<" << p.first << ", " << p.second << "> ";
  return os;
}

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

  vector<ll> A(N);
  REP(i, N) { cin >> A[i]; }

  ll left = 0.;
  ll right = 1e9;
  while (right >= left) {
    ll mid = (left + right) / 2;
    ll tK = K + N;
    bool flag = false;
    REP(i, N) {
      ll n = (A[i] + mid - 1) / mid;
      if (n <= tK) {
        tK -= n;
      } else {
        i = N;
        flag = true;
      }
    }
    if (flag) {
      left = mid + 1;
    } else {
      right = mid - 1;
    }
  }
  cout << left << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define fi first
#define se second
#define pb push_back
#define mod(n, k) ((((n) % (k)) + (k)) % (k))
#define forn(i, a, b) for (int i = a; i < b; i++)
#define forr(i, a, b) for (int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const int maxn = 200000 + 10;
int N, K, A[maxn];

int get(int act, int x) {
  // if(act <= x)return 0;
  // return 1+get(act-x,x);
  return act / x;
}
int can(int x) {
  int cnt = 0;
  forn(i, 0, N) {
    if (A[i] <= x)
      continue;
    cnt += get(A[i], x);
  }
  if (cnt > K)
    return 0;
  return 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> N >> K;
  forn(i, 0, N) cin >> A[i];
  int ini = 1, fin = 1e9 + 1;
  while (ini < fin) {
    int mit = (ini + fin) >> 1;
    if (can(mit))
      fin = mit;
    else
      ini = mit + 1;
  }
  cout << ini << '\\n';
  return 0;
}
/*
__builtin_mul_overflow(x,y,&x)
-fsplit-stack
*/


Error: TLE

Fixed submission:

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

#define fi first
#define se second
#define pb push_back
#define mod(n, k) ((((n) % (k)) + (k)) % (k))
#define forn(i, a, b) for (int i = a; i < b; i++)
#define forr(i, a, b) for (int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const int maxn = 200000 + 10;
int N, K, A[maxn];

int get(int act, int x) {
  if (act <= x)
    return 0;
  return 1 + get(act - x, x);
}
int can(int x) {
  int cnt = 0;
  forn(i, 0, N) {
    if (A[i] <= x)
      continue;
    cnt += get(A[i], x);
  }
  if (cnt > K)
    return 0;
  return 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> N >> K;
  forn(i, 0, N) cin >> A[i];
  int ini = 1, fin = 1e9 + 1;
  while (ini < fin) {
    int mit = (ini + fin) >> 1;
    if (can(mit))
      fin = mit;
    else
      ini = mit + 1;
  }
  cout << ini << '\\n';
  return 0;
}
/*
__builtin_mul_overflow(x,y,&x)
-fsplit-stack
*/