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

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

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;

#define ll long long int
#define ld long double
#define FAST                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define pb push_back
#define pi 3.14159265358979
#define pa pair<ll, ll>
// #define goodset tree<pa, null_type, less<pa>, rb_tree_tag,
// tree_order_statistics_node_update> #define FRE freopen("acm.in","r",stdin);
// freopen("acm.out","w",stdout);

const ll mod = 1e9 + 7;
const ll N = 1e7 + 5;
int main() {
  FAST

      ll tc,
      i, j, k;
  // cin>>tc;
  tc = 1;
  while (tc--) {
    ll n, k;
    cin >> n >> k;
    ll a[n];
    for (i = 0; i < n; i++)
      cin >> a[i];
    sort(a, a + n);

    ll lo = 0;
    ll hi = a[n - 1];
    ll ans = a[n - 1];
    while (lo <= hi) {
      ll mi = (lo + hi) / 2;
      if (mi == 0) {
        ans = 1;
        break;
      }
      ll cnt = 0;
      for (i = 0; i < n; i++) {
        ll val = a[i] / mi;
        if (a[i] % mi != 0)
          val++;
        if (val > 0)
          cnt += (val - 1);
      }
      if (cnt <= k) {
        ans = min(ans, mi);
        hi = mi - 1;
      } else
        lo = mi + 1;
    }
    cout << ans;
  }
  return 0;
}


Error: WA

Fixed submission:

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

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;

#define ll long long int
#define ld long double
#define FAST                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define pb push_back
#define pi 3.14159265358979
#define pa pair<ll, ll>
// #define goodset tree<pa, null_type, less<pa>, rb_tree_tag,
// tree_order_statistics_node_update> #define FRE freopen("acm.in","r",stdin);
// freopen("acm.out","w",stdout);

const ll mod = 1e9 + 7;
const ll N = 1e7 + 5;
int main() {
  FAST

      ll tc,
      i, j, k;
  // cin>>tc;
  tc = 1;
  while (tc--) {
    ll n, k;
    cin >> n >> k;
    ll a[n];
    for (i = 0; i < n; i++)
      cin >> a[i];
    sort(a, a + n);

    ll lo = 0;
    ll hi = a[n - 1];
    ll ans = a[n - 1];
    while (lo <= hi) {
      ll mi = (lo + hi) / 2;
      ll cnt = 0;
      for (i = 0; i < n; i++) {
        ll val = a[i] / mi;
        if (a[i] % mi != 0)
          val++;
        if (val > 0)
          cnt += (val - 1);
      }
      if (cnt <= k) {
        ans = min(ans, mi);
        hi = mi - 1;
      } else
        lo = mi + 1;
    }
    cout << ans;
  }
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

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

typedef vector<int> vi;
typedef long long ll;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i, a, b) for (int i = a; i <= b; i++)
#define pmod 1000000007
#define INF 1000000000000000000
#define pi atan(1) * 4
#define modi 1000000

void solve() {

  ll n, k;

  cin >> n >> k;

  ll a[n];

  ll sum = 0;

  for (ll i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }

  ll mini = sum;

  ll ini = 1, fin = sum;

  bool can;

  while (ini <= fin) {

    ll med = (fin + ini) / 2;
    ll counter = 0;

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

      counter += (((a[i] + med - 1) / med) - 1);
    }

    if (counter <= k) {
      mini = min(mini, med);
      fin = med - 1;
    } else {
      ini = med + 1;
    }
  }

  cout << mini << endl;
}

int main() {

  ifstream fin("text.in");
  ofstream fout("text.out");

  ll t = 1;

  while (t--)
    solve();

  return 0;
}

Error: 0

Fixed submission:

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

typedef vector<int> vi;
typedef long long ll;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i, a, b) for (int i = a; i <= b; i++)
#define pmod 1000000007
#define INF 1000000000000000000
#define pi atan(1) * 4
#define modi 1000000

void solve() {

  ll n, k;

  cin >> n >> k;

  ll a[n];

  ll sum = 0;

  for (ll i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }

  ll mini = sum;

  ll ini = 0, fin = sum;

  bool can;

  while (ini <= fin) {

    ll med = (fin + ini) / 2;
    ll counter = 0;

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

      counter += (((a[i] + med - 1) / med) - 1);
    }

    if (counter <= k) {
      mini = min(mini, med);
      fin = med - 1;
    } else {
      ini = med + 1;
    }
  }

  cout << mini << endl;
}

int main() {

  ifstream fin("text.in");
  ofstream fout("text.out");

  ll t = 1;

  while (t--)
    solve();

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

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

bool check(vector<long> a, int c, long k) {
  long tmp = 0;
  for (int i = 0; i < a.size(); i++) {
    if (a[i] <= c)
      continue;
    tmp += a[i] / c;
    if (a[i] % c == 0)
      tmp--;
    // cout << tmp << endl;
  }
  if (tmp <= k)
    return true;
  else
    return false;
}

int main() {
  int n;
  long k;
  cin >> n >> k;

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

  int l = 0;
  int r = 1000000000;
  while (r - l > 1) {
    int c = (l + r) / 2;
    if (check(a, c, k)) {
      // cout << c << " yes" << endl;
      r = c;
    } else {
      // cout << c << " no" << endl;
      l = c;
    }
  }

  cout << r << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

class t {
public:
  long num;
  long now;
  int cnt;

  void set(long num);
  void add_cnt();
};

void t::set(long num) {
  this->num = num;
  this->now = num;
  this->cnt = 1;
}

void t::add_cnt() {
  this->cnt++;
  this->now = num / cnt;
  if (num % cnt != 0)
    this->now++;
}

int main() {
  int n;
  long k;
  cin >> n >> k;

  vector<long> a(n);
  vector<t> tmp(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    tmp[i].set(a[i]);
  }

  sort(tmp.begin(), tmp.end(),
       [](const t &lhoge, const t &rhoge) { return lhoge.now < rhoge.now; });

  // for(int i=0;i<n;i++){
  //   cout << tmp[i].now << endl;
  // }

  long nowm = 0;
  int count = 0;
  for (int i = 0; i < k; i++) {
    if (count >= k)
      break;
    tmp[tmp.size() - 1].add_cnt();

    // cout << tmp[tmp.size()-1].now << endl;

    count++;
    nowm = tmp[tmp.size() - 1].now;
    for (int j = 1; j < n; j++) {
      if (count >= k)
        break;
      if (tmp[tmp.size() - 1 - j].now > nowm) {
        while (tmp[tmp.size() - 1 - j].now > nowm) {
          tmp[tmp.size() - 1 - j].add_cnt();

          // cout << tmp[tmp.size()-1-i].now << endl;

          count++;
          if (count >= k)
            break;
        }
      } else {
        break;
      }
    }
    sort(tmp.begin(), tmp.end(),
         [](const t &lhoge, const t &rhoge) { return lhoge.now < rhoge.now; });

    // cout << endl;
    // for(int j=0;j<n;j++){
    //   cout << tmp[j].now << endl;
    // }

    if (count >= k)
      break;
  }

  // for(int i=0;i<n;i++){
  //   cout << tmp[i].now << endl;
  // }

  cout << tmp[tmp.size() - 1].now << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
ll mod = 1e9 + 7;
#define rep(i, n) for (int i = 0; i < (n); ++i)

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


Error: 0

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
ll mod = 1e9 + 7;
#define rep(i, n) for (int i = 0; i < (n); ++i)

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

#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
ll mod = 1e9 + 7;
// ll mod = 998244353;
#define rep(i, n) for (int i = 0; i < (n); ++i)

int main() {
  int n;
  ll k;
  cin >> n >> k;
  vector<ll> a(n);
  ll max_num = 0;
  rep(i, n) {
    cin >> a[i];
    max_num = max(max_num, a[i]);
  }
  if (k == 0) {
    cout << max_num << endl;
    return 0;
  }
  ll l = 0;
  ll r = 1e9;

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


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
ll mod = 1e9 + 7;
// ll mod = 998244353;
#define rep(i, n) for (int i = 0; i < (n); ++i)

int main() {
  int n;
  ll k;
  cin >> n >> k;
  vector<ll> a(n);
  ll max_num = 0;
  rep(i, n) {
    cin >> a[i];
    max_num = max(max_num, a[i]);
  }
  if (k == 0) {
    cout << max_num << endl;
    return 0;
  }
  ll l = -1;
  ll r = 1e9 + 1;

  while (r - l > 1LL) {
    ll m = (l + r) / 2LL;
    ll cnt = 0;
    rep(i, n) { cnt += (a[i] + m - 1LL) / m - 1LL; }
    // cout << l << " " << r << " " << cnt << endl;
    if (cnt > k) {
      l = m;
    } else {
      r = m;
    }
  }
  cout << r << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long int
#define pii pair<double, pair<int, int>>
#define F first
#define S second
using namespace std;
#define mod 1000000007

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  ll k;
  cin >> n >> k;
  int arr[n];
  for (int i = 0; i < n; i++)
    cin >> arr[i];
  int lo = 1;
  int hi = (*max_element(arr, arr + n));
  while (lo < hi) {
    int mid = lo + (hi - lo) / 2;
    ll curr = 0;
    for (int i = 0; i < n; i++) {
      if (arr[i] > mid) {
        curr += (ll)ceil(arr[i] / mid);
      }
    }
    if (curr <= k)
      hi = mid;
    else
      lo = mid + 1;
  }
  cout << lo << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
#define pii pair<double, pair<int, int>>
#define F first
#define S second
using namespace std;
#define mod 1000000007

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  cin >> n >> k;
  priority_queue<pii> pq;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    pq.push({(double)a, {a, 1}});
  }
  while (k > 0) {
    pii curr = pq.top();
    pq.pop();
    double temp = (double)curr.S.F / ((double)curr.S.S + 1);
    pq.push({temp, {curr.S.F, curr.S.S + 1}});
    k--;
  }
  double ans = pq.top().F;
  ll temp = (ll)ans;
  /// cout<< ans <<endl;
  if (ans - (double)temp > 0.0) {
    cout << temp + 1 << endl;
  } else
    cout << temp << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define int long long
using namespace std;
constexpr int mod = 1e9 + 7;
signed main() {
  int n, k, a[200000];
  cin >> n >> k;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int ub = 0, lb = mod;
  while (lb - ub > 1) {
    int mid = (lb + ub) / 2;
    int ans = 0;
    for (int i = 0; i < n; i++)
      ans += (a[i] + mid - 1) / mid;
    (ans <= n + k ? lb : ub) = mid;
  }
  cout << lb << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define int long long
using namespace std;
constexpr int mod = 1e9 + 7;
signed main() {
  int n, k, a[200000];
  cin >> n >> k;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int ub = 0, lb = mod;
  for (int cnt = 0; cnt < 100; cnt++) {
    int mid = (lb + ub) / 2;
    int ans = 0;
    for (int i = 0; i < n; i++)
      ans += (a[i] + mid - 1) / mid;
    (ans <= n + k ? lb : ub) = mid;
  }
  cout << lb << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(c) c.begin(), c.end()

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  rep(i, N) { cin >> A[i]; }

  int l = 1;
  int r = 1e9;
  int ans = 0;
  while (l < r) {
    int m = (l + r) / 2;
    int t = 0;
    rep(i, N) { t += (A[i] - 1) / m; }

    if (t <= K) {
      ans = r = m;
    } else {
      ans = l = m + 1;
    }
  }

  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(c) c.begin(), c.end()

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  rep(i, N) { cin >> A[i]; }

  int l = 0;
  int r = 1000000000 + 1;
  int ans = 0;
  while (l < r) {
    int m = l + (r - l) / 2;

    int t = 0;
    rep(i, N) { t += (A[i] + m - 1) / m - 1; }

    if (t <= K) {
      ans = r = m;
    } else {
      ans = l = m + 1;
    }
  }

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

#include <cstdio>
long long a[200005];

int isOk(int n, long long have, long long len) {
  long long left = have;
  for (int i = 1; i <= n; i++) {
    long long L = 0, R = left;
    long long res = -1;
    while (L <= R) {
      long long M = (L + R) / 2;
      if ((M + 1) * len >= a[i]) {
        res = M;
        R = M - 1;
      } else
        L = M + 1;
    }
    if (res == -1)
      return 0;
    else
      left -= res;
  }
  return 1;
}

int main() {
  int n;
  long long k;
  scanf("%d%lld", &n, &k);
  for (int i = 1; i <= n; i++)
    scanf("%lld", &a[i]);
  long long L = 1, R = 1000000000;
  long long res = -1;
  while (L <= R) {
    int M = (L + R) / 2;
    if (isOk(n, k, M)) {
      res = M;
      R = M - 1;
    } else
      L = M + 1;
  }
  printf("%lld\\n", res);
  return 0;
}


Error: 0

Fixed submission:

#include <cstdio>
long long a[100005];

int isOk(int n, long long have, long long len) {
  long long left = have;
  for (int i = 1; i <= n; i++) {
    long long L = 0, R = left;
    long long res = -1;
    while (L <= R) {
      long long M = (L + R) / 2;
      if ((M + 1) * len >= a[i]) {
        res = M;
        R = M - 1;
      } else
        L = M + 1;
    }
    if (res == -1)
      return 0;
    else
      left -= res;
  }
  return 1;
}

int main() {
  int n;
  long long k;
  scanf("%d%lld", &n, &k);
  for (int i = 1; i <= n; i++)
    scanf("%lld", &a[i]);
  long long L = 1, R = 1000000000;
  long long res = -1;
  while (L <= R) {
    int M = (L + R) / 2;
    if (isOk(n, k, M)) {
      res = M;
      R = M - 1;
    } else
      L = M + 1;
  }
  printf("%lld\\n", res);
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

bool isPos(vector<long long> &a, long long p, long long k) {

  long long cuts = 0;

  for (long long i = 0; i < a.size(); i++) {

    long long cur = ceil(a[i] / (long double)p);

    cuts += (cur - 1);
  }

  return cuts <= k;
}

int32_t main() {

  ios_base::sync_with_stdio(false);

  cin.tie(0);

  long long n;

  cin >> n;

  long long k;

  cin >> k;

  vector<long long> a(n);

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

    cin >> a[i];
  }

  long long l = 1;

  long long r = LLONG_MAX / 100;

  long long res = LLONG_MAX / 100;

  while (l <= r) {

    if (l == r) {

      if (isPos(a, l, k)) {

        res = min(res, l);
      }

      break;
    }

    long long m = (l + r) / 2;

    if (isPos(a, m, k)) {

      res = min(res, m);

      r = m - 1;

    } else {

      l = m + 1;
    }
  }

  cout << res << '\\n';

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

set<int> *segment;

void build(int i, int s, int e, int arr[]) {

  if (s == e) {

    segment[i].insert(arr[s]);

    return;
  }

  build(2 * i, s, (s + e) / 2, arr);

  build(1 + 2 * i, 1 + (s + e) / 2, e, arr);

  segment[i].insert(segment[2 * i].begin(),

                    segment[2 * i].end());

  segment[i].insert(segment[2 * i + 1].begin(),

                    segment[2 * i + 1].end());
}

set<int> query(int node, int l, int r, int a, int b) {

  set<int> left, right, result;

  if (b < l || a > r)

    return result;

  if (a <= l && r <= b)

    return segment[node];

  left = query(2 * node, l, (l + r) / 2, a, b);

  result.insert(left.begin(), left.end());

  right = query(1 + 2 * node, 1 + (l + r) / 2, r, a, b);

  result.insert(right.begin(), right.end());

  return result;
}

void init(int n) {

  int h = (int)ceil(log2(n));

  h = (2 * (powl(2, h))) - 1;

  segment = new set<int>[h];
}

void getDistinct(int l, int r, int n) {

  set<int> ans = query(1, 0, n - 1, l, r);

  cout << ans.size() << endl;
}

int main() {

  int n, m;

  cin >> n >> m;

  int arr[n];

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

    cin >> arr[i];
  }

  init(n);

  build(1, 0, n - 1, arr);

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

    int x, y;

    cin >> x >> y;

    x--;

    y--;

    getDistinct(x, y, n);
  }

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

#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
using ll = long long;
using P = pair<ll, ll>;
long double binary_search(ll n, ll k, vector<ll> a) {
  long double lb = 0, ub = a.back();
  long double mid = 1;
  ll cnt = 0;
  while (cnt <= 100) {
    ll lim_cut = 0;
    bool flag = true;
    mid = (lb + ub) / 2;
    if (mid != 0) {
      rep(i, n) { lim_cut += (ll)(a[i] / mid); }
    }
    if (lim_cut > k)
      flag = 0;
    if (flag)
      ub = mid;
    else
      lb = mid;
    cnt += 1;
  }
  // cout << lb << ub << endl;
  return lb;
}
int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) { cin >> a[i]; }
  sort(a.begin(), a.end());
  long double ans = binary_search(n, k, a);

  cout << (ll)ceil(ans) << endl;
}

Error: WA

Fixed submission:

#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
using ll = long long;
using P = pair<ll, ll>;

long double binary_search(ll n, ll k, vector<ll> a) {
  ll lb = -1, ub = 1e9;
  ll mid = 1;
  while (ub - lb > 1) {
    ll lim_cut = 0;
    bool flag = true;
    mid = (lb + ub) / 2;
    rep(i, n) { lim_cut += (ll)(a[i] / mid); }
    if (lim_cut > k)
      flag = 0;
    if (flag)
      ub = mid;
    else
      lb = mid;
  }
  return mid;
}
int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) { cin >> a[i]; }
  sort(a.begin(), a.end());
  ll ans = binary_search(n, k, a);
  if (k == 0) {
    cout << a.back() << endl;
    return 0;
  }

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

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

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

  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  ll ub = 2e9;
  ll lb = 0;
  rep(i, 100) {
    ll mid = (ub + lb) / 2;
    if (mid == 0)
      break;
    ll tans = 0;
    rep(j, n) {
      if (a[j] > mid) {
        tans += (a[j] + mid - 1) / mid - 1;
      }
    }
    if (tans > k)
      lb = mid;
    else
      ub = mid;
  }
  cout << ub << endl;

  return 0;
}


Error: 0

Fixed submission:

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

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

  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  ll ub = 2e9;
  ll lb = 0;
  rep(i, 100) {
    ll mid = (ub + lb) / 2;
    ll tans = 0;
    rep(j, n) {
      if (a[j] > mid) {
        tans += (a[j] + mid - 1) / mid - 1;
      }
    }
    if (tans > k)
      lb = mid;
    else
      ub = mid;
  }
  cout << ub << endl;

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

#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (register int i = a; i <= b; i++)
#define per(i, a, b) for (register int i = a; i >= b; i--)
typedef long long LL;
const LL mod = 1e9 + 7;
const int N = 3e5 + 5;

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

bool Check(LL s) {
  LL res = 0;
  rep(i, 1, n) res += (a[i] + s - 1) / s - 1;
  return res <= k;
}

int main() {
  cin >> n >> k;
  rep(i, 1, n) cin >> a[i];
  l = 1, r = 1e9;
  while (l < r) {
    LL mid = (r + l) / 2;
    if (Check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  cout << l << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (register int i = a; i <= b; i++)
#define per(i, a, b) for (register int i = a; i >= b; i--)
typedef long long LL;
const LL mod = 1e9 + 7;
const int N = 3e5 + 5;

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

bool Check(LL s) {
  LL res = 0;
  rep(i, 1, n) res += (a[i] + s - 1) / s - 1;
  return res <= k;
}

int main() {
  cin >> n >> k;
  rep(i, 1, n) cin >> a[i];
  l = 0, r = 1e9;
  while (l < r) {
    LL mid = (r + l) / 2;
    if (Check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  cout << l << endl;
}