alexjercan/bugnet huggingface dataset:
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < n; i++)
#define repn(i, n) for (int i = 1; i <= n; i++)
#define LL long long
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD = 1e9 + 7;

LL n, k;
double a[200010];

LL f(double x, double y) {
  if (y >= x)
    return 0;
  LL r = (LL)x / y;
  for (LL i = max(0LL, r - 5); i <= r + 5; i++) {
    double res = x / (i + 1);
    // cout<<i<<' '<<res<<' '<<(LL)res<<endl;
    if (res <= y)
      return i;
  }
}

bool check(LL mid) {
  LL lft = k;
  rep(i, n) {
    lft -= f(a[i], (double)mid);
    if (lft < 0)
      return false;
  }
  // cout<<lft<<endl;
  return true;
}

int main() { // freopen("in.txt","r",stdin);
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  rep(i, n) cin >> a[i];
  LL lb = 1, ub = 1e9, mid;
  while (lb < ub) {
    mid = (lb + ub) / 2; // cout<<lb<<' '<<ub<<' '<<mid<<endl;
    if (check(mid))
      ub = mid;
    else
      lb = mid + 1;
  }
  cout << lb << endl;
  // check(0);
  // f(9,4);
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < n; i++)
#define repn(i, n) for (int i = 1; i <= n; i++)
#define LL long long
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD = 1e9 + 7;

LL n, k;
double a[200010];

LL f(double x, LL y) {
  if ((double)y >= x)
    return 0;
  int r = (LL)x / (y == 0 ? y + 1 : y);
  for (LL i = max(0, r - 2); i <= r + 1; i++) {
    double res = x / (i + 1);
    // cout<<i<<' '<<res<<' '<<(LL)res<<endl;
    if (res <= (double)y)
      return i;
  }
}

bool check(LL mid) {
  LL lft = k;
  rep(i, n) {
    lft -= f(a[i], mid);
    if (lft < 0)
      return false;
  }
  // cout<<lft<<endl;
  return true;
}

int main() { // freopen("in.txt","r",stdin);
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  rep(i, n) cin >> a[i];
  LL lb = 0, ub = 1e9, mid;
  while (lb < ub) {
    mid = (lb + ub) / 2; // cout<<lb<<' '<<ub<<' '<<mid<<endl;
    if (check(mid))
      ub = mid;
    else
      lb = mid + 1;
  }
  cout << lb << endl;
  // check(0);
  // f(9,4);
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

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

void solve() {
  int n, k;
  cin >> n >> k;
  multiset<int, greater<int>> s;
  ll a[n];
  ll maxi = 0;
  ll sum = 0;
  for (int i = 0; i < n; ++i) {
    // int e;
    cin >> a[i];
    maxi = max(maxi, a[i]);
    sum += a[i];
    // mini
    // s.insert(e);
  }
  // if(sum<=k)
  // {
  // 	cout<<0<<endl;
  // 	return;
  // }
  ll l = 1, r = maxi, ans = maxi;
  while (l <= r) {
    ll mid = (l + r) / 2;
    int temp = 0;
    for (int i = 0; i < n; ++i) {
      if (a[i] > mid)
        temp += a[i] / mid;
    }
    if (temp > k) {
      l = mid + 1;
    } else {
      ans = mid;
      r = mid - 1;
    }
  }
  cout << ans << endl;
}

int main() {
  ll t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
}

Error: 0

Fixed submission:

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

void solve() {
  int n, k;
  cin >> n >> k;
  multiset<int, greater<int>> s;
  ll a[n];
  ll maxi = 0;
  for (int i = 0; i < n; ++i) {
    // int e;
    cin >> a[i];
    maxi = max(maxi, a[i]);
    // s.insert(e);
  }
  ll l = 0, r = maxi, ans = maxi;
  while (l <= r) {
    ll mid = (l + r) / 2;
    int temp = 0;
    for (int i = 0; i < n; ++i) {
      temp += a[i] / mid;
    }
    if (temp > k) {
      l = mid + 1;
    } else {
      ans = mid;
      r = mid - 1;
    }
  }
  cout << ans << endl;
}

int main() {
  ll t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl '\\n'
bool check(int x, vector<int> &v, int k) {
  int cuts = 0;
  for (int i = 0; i < v.size(); i++) {
    cuts += v[i] / x;
    if (v[i] % x == 0)
      cuts--;
  }
  if (cuts <= k)
    return true;
  else
    return false;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  int low = 1;
  int high = 1000000000;
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
  }
  int ans;
  while (low <= high) {
    int mid = (low + high) / 2;
    if (check(mid, v, k)) {
      ans = mid;
      high = mid - 1;
    } else {
      low = mid + 1;
    }
  }
  cout << ans;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl '\\n'
bool check(int x, vector<int> &v, int k) {
  int cuts = 0;
  for (int i = 0; i < v.size(); i++) {
    cuts += v[i] / x;
    if (v[i] % x == 0)
      cuts--;
  }
  if (cuts <= k)
    return true;
  else
    return false;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  int low = 0;
  int high = 1000000000;
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
  }
  int ans;
  while (low <= high) {
    int mid = (low + high) / 2;
    if (check(mid, v, k)) {
      ans = mid;
      high = mid - 1;
    } else {
      low = mid + 1;
    }
  }
  cout << ans;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define pi 3.14159265359
#define all(i) i.begin(), i.end()
using namespace std;
const long long INF = 1e9 + 7;
const string alp = "abcdefghijklmnopqrstuvwxyz"; // 26
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
// const ll MOD=998244353LL;
// const ll MOD=1777777777LL;

int main() {
  ll N, K;
  cin >> N >> K;
  ll a[N];
  rep(i, N) cin >> a[i];

  ll lb = 0, ub = INF;

  while (ub - lb > 1) {
    ll mid = (lb + ub) / 2;
    ll num = 0;
    for (int i = 0; i < N; i++) {
      num += (a[i] - 1) / mid;
    }
    if (num > K)
      lb = mid;
    else
      ub = mid;
  }
  int ans = ub;
  if (ub > ans)
    ans++;
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define pi 3.14159265359
#define all(i) i.begin(), i.end()
using namespace std;
const long long INF = 1e9 + 7;
const string alp = "abcdefghijklmnopqrstuvwxyz"; // 26
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
// const ll MOD=998244353LL;
// const ll MOD=1777777777LL;

int main() {
  ll N, K;
  cin >> N >> K;
  ll a[N];
  rep(i, N) cin >> a[i];

  ll lb = 0, ub = INF;

  for (int i = 0; i < 100; i++) {
    ll mid = (lb + ub) / 2;
    ll num = 0;
    for (int i = 0; i < N; i++) {
      num += (a[i] - 1) / mid;
    }
    if (num > K)
      lb = mid;
    else
      ub = mid;
  }
  int ans = ub;
  if (ub > ans)
    ans++;
  cout << ans << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

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

void solve() {
  int n, k;
  cin >> n >> k;
  double a[n];
  REP(i, n) cin >> a[i];
  double l = 0, r = 1000000010;
  REP(re, 1000) {
    int sum = 0;
    double mid = (l + r) / 2;
    REP(i, n) if (a[i] > mid) sum += ceil(a[i] / mid) - 1;
    if (sum <= k)
      r = mid;
    else
      l = mid;
  }
  cout << setprecision(20) << ceil(l) << endl;
}

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

Error: TLE

Fixed submission:

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

void solve() {
  int n, k, a;
  cin >> n >> k;
  priority_queue<pair<double, pair<double, double>>,
                 vector<pair<double, pair<double, double>>>>
      pq;
  REP(i, n) {
    cin >> a;
    pq.push({a, {a, 1}});
  }
  REP(i, k) {
    auto t = pq.top();
    pq.pop();
    t.second.second++;
    t.first = t.second.first / t.second.second;
    pq.push(t);
  }
  cout << setprecision(20) << ceil(pq.top().first) << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
#define lp(i, n) for (int i = 0; i < (n); ++i)
#define pr1(x) cout << "[" << #x << ": " << x << "] \\n";
#define pr2(x, y)                                                              \\
  cout << "[" << #x << ": " << x << ", " << #y << ": " << y << "] \\n";
#define mod 1000000007
#define int long long
#define sz(v) (int)(v).size()

int n, k;
vector<int> v;

bool can(int md) {
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    cnt += ((v[i] + md - 1) / md) - 1;
  }
  return cnt <= k;
}

void solve() {
  cin >> n >> k;
  v.resize(n);
  lp(i, n) cin >> v[i];

  int lo = 1, hi = 1e12, md, ans = 0;
  while (hi >= lo) {
    md = (lo + hi) / 2;
    if (can(md)) {
      ans = md;
      hi = md - 1;
    } else
      lo = md + 1;
  }
  cout << ans << "\\n";
}

int32_t main() {
  ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
  int t = 1;
  // cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
#define lp(i, n) for (int i = 0; i < (n); ++i)
#define pr1(x) cout << "[" << #x << ": " << x << "] \\n";
#define pr2(x, y)                                                              \\
  cout << "[" << #x << ": " << x << ", " << #y << ": " << y << "] \\n";
#define mod 1000000007
#define int long long
#define sz(v) (int)(v).size()

int n, k;
vector<int> v;

bool can(int md) {
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    cnt += ((v[i] + md - 1) / md) - 1;
  }
  return cnt <= k;
}

void solve() {
  cin >> n >> k;
  v.resize(n);
  lp(i, n) cin >> v[i];

  int lo = 0, hi = 1e12, md, ans = 0;
  while (hi >= lo) {
    md = (lo + hi) / 2;
    if (can(md)) {
      ans = md;
      hi = md - 1;
    } else
      lo = md + 1;
  }
  cout << ans << "\\n";
}

int32_t main() {
  ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
  int t = 1;
  // cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define LL long long
#define MOD 1000000007
using namespace std;
int a[200005];
int N, K;
int check(int M) {
  int cnt = 0;
  for (int i = 0; i < N; ++i) {
    cnt += (a[i] - 1) / M;
  }
  if (cnt <= K)
    return true;
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> N >> K;
  int maxx = 0;
  for (int i = 0; i < N; ++i) {
    cin >> a[i];
    maxx = max(a[i], maxx);
  }
  int L = 0, R = maxx;
  while (L + 1 < R) {
    int mid = (L + R) / 2;
    if (check(mid))
      R = mid;
    else
      L = mid;
  }
  cout << R << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define LL long long
#define MOD 1000000007
using namespace std;
int a[200005];
int N, K;
int check(int M) {
  int cnt = 0;
  for (int i = 0; i < N; ++i) {
    cnt += (a[i] - 1) / M;
  }
  if (cnt <= K)
    return true;
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> N >> K;
  int maxx = 0;
  for (int i = 0; i < N; ++i) {
    cin >> a[i];
    maxx = max(a[i], maxx);
  }
  int L = 0, R = maxx;
  int ans;
  while (L < R) {
    int mid = (L + R) / 2;
    if (check(mid))
      R = mid;
    else
      L = mid + 1;
    ans = mid;
  }
  cout << R << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
bool solve(vector<int> &a, int k, int l) {
  ll r = 0;
  for (int i : a)
    r += (i - 1) / l;
  return r <= k;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int x = 1, y = 1 << 30;
  while (x < y) {
    int sr = (x + y) / 2;
    if (solve(a, k, sr))
      y = sr;
    else
      x = sr + 1;
  }
  cout << x << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
bool solve(vector<int> &a, int k, int l) {
  ll r = 0;
  for (int i : a)
    r += (i - 1) / l;
  return r <= k;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int x = 0, y = 1 << 30;
  while (x < y) {
    int sr = (x + y) / 2;
    if (solve(a, k, sr))
      y = sr;
    else
      x = sr + 1;
  }
  cout << x << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define all_map(itr, mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define ALL(a) (a).begin(), (a).end()

using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

const ll MOD = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;

int main() {
  ll n, k;
  cin >> n >> k;

  vector<ll> a(n);
  rep(i, n) { cin >> a[i]; }
  sort(ALL(a));

  ll l = 1, r = a[n - 1];

  while (r >= l) {
    ll mid = l + (r - l) / 2;

    ll cnt = 0;
    rep(i, n) if (a[i] > mid) { cnt += a[i] / mid; }

    if (cnt <= k)
      r = mid - 1;
    else
      l = mid + 1;
  }

  cout << r + 1 << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define all_map(itr, mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define ALL(a) (a).begin(), (a).end()

using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

const ll MOD = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;

int main() {
  ll n, k;
  cin >> n >> k;

  vector<ll> a(n);
  rep(i, n) { cin >> a[i]; }
  sort(ALL(a));

  ll l = 0, r = a[n - 1];

  while (r >= l) {
    ll mid = l + (r - l) / 2;

    mid = max((ll)1, mid);

    ll cnt = 0;
    rep(i, n) if (a[i] > mid) { cnt += a[i] / mid; }

    if (cnt <= k)
      r = mid - 1;
    else
      l = mid + 1;
  }

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

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

const ll MAXN = 1e9;
ll n, k;
vector<ll> a;

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

void search() {
  ll left = 1, right = MAXN;
  while (left < right) {
    ll mid = (left + right) / 2;
    if (!check(mid)) {
      left = mid + 1;
    } else {
      right = mid;
    }
  }
  cout << right << endl;
}

int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    ll nums;
    cin >> nums;
    a.push_back(nums);
  }
  sort(a.begin(), a.end());
  search();
  return 0;
}

Error: 0

Fixed submission:

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

const ll MAXN = 1e9;
ll n, k;
vector<ll> a;

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

void search() {
  ll left = 0, right = MAXN, ans = -1;
  while (left < right) {
    ll mid = (left + right) / 2;
    if (!check(mid)) {
      left = mid + 1;
    } else {
      right = mid;
    }
  }
  cout << right << endl;
}

int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    ll nums;
    cin >> nums;
    a.push_back(nums);
  }
  sort(a.begin(), a.end());
  search();
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

typedef long long ll;

using namespace std;

const ll mod = 1000000007;

bool judge(ll x, ll *A, ll N, ll K) {
  ll p = 0;

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

    p += (A[i] - 1) / x;
  }
  // cout<<"x: "<<x<<" p:"<<p<<endl;

  return p <= K;
}

ll binarysearch(ll *A, ll N, ll K) {
  ll ok = 1e9;
  ll ng = 0;
  while (abs(ok - ng) > 1) {
    ll mid = (ok + ng) / 2;
    if (judge(mid, A, N, K)) {
      ok = mid;
    } else {
      ng = mid;
    }
  }
  return ok;
}

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

  ll end;

  for (int i = 0; i != N; i++) {
    cin >> A[i];
  }

  ll ans = binarysearch(A, N, K);
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

typedef long long ll;

using namespace std;

const ll mod = 1000000007;

bool judge(ll x, ll *A, ll N, ll K) {
  ll p = 0;

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

    p += (A[i] - 1) / x;
  }
  // cout<<"x: "<<x<<" p:"<<p<<endl;

  return p <= K;
}

ll binarysearch(ll *A, ll N, ll K) {
  ll ok = 1e9;
  ll ng = -1;
  while (abs(ok - ng) > 1) {
    ll mid = (ok + ng) / 2;
    if (judge(mid, A, N, K)) {
      ok = mid;
    } else {
      ng = mid;
    }
  }
  return ok;
}

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

  ll end;

  for (int i = 0; i != N; i++) {
    cin >> A[i];
  }

  ll ans = binarysearch(A, N, K);
  cout << ans << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <cstring>
#include <iostream>

using namespace std;
int a[200007];
// WWRRWRR
int main() {
  int n;
  cin >> n;
  int k;
  cin >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int l = 1, r = 1000000007;
  while (l < r) {
    int m = (l + r) >> 1;
    long long ans = 0;
    for (int i = 0; i < n; i++) {
      ans += (1ll * a[i] + m - 1) / m - 1;
      if (ans > k)
        break;
    }
    if (ans > k) {
      l = m + 1;
    } else {
      r = m;
    }
  }
  cout << r << '\\n';
}


Error: 0

Fixed submission:

#include <iostream>

using namespace std;

long long int n, k;
long long int a[20005];
bool check(long long int m) {
  int sl = 0;
  for (long long int i = 1; i <= n; i++) {
    sl += (a[i] / m);
    if (a[i] % m == 0)
      sl--;
  }
  if (sl <= k)
    return true;
  return false;
}
int main() {
  cin >> n >> k;
  long long int d = 1, c = -1, g, m = -1;
  for (long long int i = 1; i <= n; i++) {
    cin >> a[i];
    if (c < a[i])
      c = a[i];
  }

  while (d <= c) {
    g = (d + c) / 2;
    if (check(g)) {
      m = g;
      c = g - 1;
    } else
      d = g + 1;
  }
  cout << m << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
const int maxn = 2e5 + 10;
int a[maxn], n, k;
bool judge(int x) {
  int cnt = 0;
  for (int i = 0; i < n; i++)
    cnt += (a[i] - 1) / x;
  return cnt <= k;
}
int main() {
  int l = 1, r = 0;
  cin >> n >> k;
  for (int i = 0; i < n; i++)
    cin >> a[i], r = max(r, a[i]);
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (judge(mid))
      r = mid - 1;
    else
      l = mid + 1;
  }
  cout << l;
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <queue>

using namespace std;

// typedef pair<int,int> pii;
// #define int long long

int a[200010];

int n;
int cal(int x) {
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    ans = ans + a[i] / x;
  }
  return ans;
}

int main() {
  int k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
  }
  int l = 0, r = 1e9, mid;
  while (l <= r) {
    mid = l + r >> 1;
    int f = cal(mid);
    if (f > k)
      l = mid + 1;
    else
      r = mid - 1;
  }
  cout << l << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int a[200005], n, k;
bool check(int x) {
  int now = 0;
  for (int i = 0; i < n; i++) {
    now += (a[i] - 1) / x;
  }
  return now <= k;
}
int main() {
  cin >> n >> k;
  int maxn = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if (a[i] > maxn)
      maxn = a[i];
  }
  int l = 1, r = maxn;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check(mid))
      r = mid - 1;
    else
      l = mid + 1;
  }
  cout << l << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <queue>
using namespace std;
// typedef pair<int,int> pii;
#define int long long

int a[500010];

int n, k;
int cal(int x) {
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (ans - k > -(a[i] / x)) {
      return 1e9;
    }
    if (a[i] / x > k) {
      return 1e9;
    }
    ans = ans + (a[i] / x);
    if (ans > k) {
      return 1e9;
    }
  }
  return ans;
}

signed main() {
  scanf("%lld%lld", &n, &k);
  for (int i = 1; i <= n; ++i) {
    scanf("%lld", &a[i]);
  }
  int l = 0, r = 1e10, mid;
  while (l <= r) {
    mid = (l + r) / 2;
    int f = cal(mid);
    if (f > k)
      l = mid + 1;
    else
      r = mid - 1;
  }
  printf("%lld\\n", l);
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define ll long long
#define rep(A, B, C) for (A = B; A < C; ++A)
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

/////////////////////////////////////////////////////

ll N, K;
ll A[202020];

ll i, j, k;

bool calc(ll aa) {
  ll k = K, i;
  rep(i, 0, N) {
    ll c = (A[i] - 1) / aa;
    k -= c;
    if (k < 0)
      return false;
  }
  return true;
}

int main() {
  scanf("%lld%lld", &N, &K);
  rep(i, 0, N) { scanf("%lld", &A[i]); }
  ll l = 1, r = 1e12;
  while (l < r) {
    ll c = (l + r) / 2;
    if (calc(c)) {
      r = c;
    } else {
      l = c + 1;
    }
  }
  printf("%lld\\n", l);

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

#define ll long long
#define rep(A, B, C) for (A = B; A < C; ++A)
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

/////////////////////////////////////////////////////

ll N, K;
ll A[202020];

ll i, j, k;

bool calc(ll aa) {
  ll k = K, i;
  rep(i, 0, N) {
    ll c = (A[i] - 1) / aa;
    k -= c;
    if (k < 0)
      return false;
  }
  return true;
}

int main() {
  scanf("%lld%lld", &N, &K);
  rep(i, 0, N) { scanf("%lld", &A[i]); }
  ll l = 0, r = 1e12;
  while (l < r) {
    ll c = (l + r) / 2;
    if (calc(c)) {
      r = c;
    } else {
      l = c + 1;
    }
  }
  printf("%lld\\n", l);

  return 0;
}