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

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

#define ll long long

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  int n, k;
  cin >> n >> k;
  int A[n];
  for (int i = 0; i < n; i++)
    cin >> A[i];
  int a = 1, b = 1e9;
  while (a < b) {
    // cout<<a<<" "<<b<<endl;
    int mid = (a + b) / 2;
    int times = 0;
    for (int i = 0; i < n; i++) {
      int y = A[i] / mid;
      if (A[i] % mid == 0)
        y--;
      times += y;
    }
    if (times > k)
      a = mid + 1;
    else
      b = mid;
  }
  cout << a;
}

Error: -8

Fixed submission:

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

#define ll long long

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  int n, k;
  cin >> n >> k;
  int A[n];
  for (int i = 0; i < n; i++)
    cin >> A[i];
  int a = 0, b = 1e9;
  while (a < b) {
    // cout<<a<<" "<<b<<endl;
    int mid = (a + b) / 2;
    int times = 0;
    for (int i = 0; i < n; i++) {
      int y = A[i] / mid;
      if (A[i] % mid == 0)
        y--;
      times += y;
    }
    if (times > k)
      a = mid + 1;
    else
      b = mid;
  }
  cout << a;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 100000000;
#define rep1(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, k, n) for (ll i = k; i < (n); i++)
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

ll n, k;
vector<ll> a;
bool check(ll x) {
  ll count = 0;
  rep1(i, n) count += (a[i] - 1) / x;
  if (count <= k)
    return true;
  else
    return false;
}

int main() {
  cin >> n >> k;
  a.resize(n);
  rep1(i, n) cin >> a[i];
  ll ans = 0;
  ll left = 1, right = 1e9;
  while (right > left) {
    ll mid = (right + left) / 2;
    if (check(mid))
      right = mid;
    else
      left = mid + 1;
  }
  cout << left << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 100000000;
#define rep1(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, k, n) for (ll i = k; i < (n); i++)
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

ll n, k;
vector<ll> a;
bool check(ll x) {
  ll count = 0;
  rep1(i, n) count += (a[i] - 1) / x;
  if (count <= k)
    return true;
  else
    return false;
}

int main() {
  cin >> n >> k;
  a.resize(n);
  rep1(i, n) cin >> a[i];
  ll ans = 0;
  ll left = -1, right = 1e9 + 1;
  while (right > left) {
    ll mid = (right + left) / 2;
    if (check(mid))
      right = mid;
    else
      left = mid + 1;
  }
  cout << left << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define sz(x) (int)((x).size())
#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int N = 2e5 + 5;

ll n, k;
ll a[N];

bool check(ll x) {
  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    if (a[i] == x)
      continue;
    ans += a[i] / x;
  }
  return ans <= k;
}

void solve() {
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  ll l = 1, r = 1e9, ans = 1e9;
  while (l <= r) {
    ll m = (l + r) / 2;
    if (check(m)) {
      ans = m;
      r = m - 1;
    } else
      l = m + 1;
  }
  cout << ans;
}

int main() {
  ios_base ::sync_with_stdio(false);
  int test = 1;
  // cin >> test;
  while (test--) {
    solve();
  }
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define sz(x) (int)((x).size())
#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int N = 2e5 + 5;

ll n, k;
ll a[N];

bool check(ll x) {
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    ans += a[i] / x;
  }
  return ans <= k;
}

void solve() {
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  // sort(a,a+n);
  // reverse(a,a+n);
  ll l = 0, r = 1e9, ans = 1e9;
  while (l <= r) {
    ll m = (l + r) / 2;
    if (check(m)) {
      ans = m;
      r = m - 1;
    } else
      l = m + 1;
  }
  cout << ans;
}

int main() {
  ios_base ::sync_with_stdio(false);
  int test = 1;
  // cin >> test;
  while (test--) {
    solve();
  }
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define inf 1001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(), v.end()

int k;

ll gcd(ll a, ll b) {
  if (b > a)
    swap(a, b);
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a / g * b;
}
ll rep_jijo(ll n, ll x) {
  if (x == 0)
    return 1;
  if (x % 2 == 0) {
    ll t = rep_jijo(n, x / 2);
    return t * t % mod;
  }
  return n * rep_jijo(n, x - 1) % mod;
}

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

  vector<double> L(n);
  rep(i, n) cin >> L[i];
  // cin >> k;
  double l = 0;
  double r = inf;
  ll count;

  auto judge = [&](double x) {
    count = 0;
    rep(i, n) count += floor(L[i] / x);
    if (count >= k)
      return true;
    else
      return false;
  };

  for (int j = 0; j < 100; j++) {
    double mid = (l + r) / 2.0;
    bool flag;
    flag = judge(mid);
    if (flag)
      l = mid;
    else
      r = mid;
  }
  cout << ll(ceil(l)) << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define inf 1001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(), v.end()

int k;

ll gcd(ll a, ll b) {
  if (b > a)
    swap(a, b);
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a / g * b;
}
ll rep_jijo(ll n, ll x) {
  if (x == 0)
    return 1;
  if (x % 2 == 0) {
    ll t = rep_jijo(n, x / 2);
    return t * t % mod;
  }
  return n * rep_jijo(n, x - 1) % mod;
}

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

  vector<double> L(n);
  rep(i, n) cin >> L[i];
  // cin >> k;
  double l = 0;
  double r = inf;
  ll count;

  auto judge = [&](double x) {
    count = 0;
    rep(i, n) count += floor(L[i] / x);
    if (count >= k)
      return true;
    else
      return false;
  };

  for (int j = 0; j < 2000; j++) {
    double mid = (l + r) / 2.0;
    bool flag;
    flag = judge(mid);
    if (flag)
      l = mid;
    else
      r = mid;
  }
  cout << ll(ceil(l)) << endl;

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

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;

void solve() {
  int n;
  ll k;
  cin >> n >> k;
  vector<ll> a(n);

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

  ll left = 0;
  ll right = ma + 1;

  while (right - left > 1) {
    const ll mid = (left + right) / 2;

    ll sum = 0;
    for (int i = 0; i < n; i++) {
      sum += (a[i] + mid - 1) / mid - 1;
    }

    if (sum <= k)
      right = mid;
    else
      left = mid;
  }

  cout << right << endl;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);

  solve();
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;

void solve() {
  int n;
  ll k;
  cin >> n >> k;
  vector<ll> a(n);

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

  ll left = -1;
  ll right = ma + 1;

  while (right - left > 1) {
    const ll mid = (left + right) / 2;

    ll sum = 0;
    for (int i = 0; i < n; i++) {
      sum += (a[i] + mid - 1) / mid - 1;
    }

    if (sum <= k)
      right = mid;
    else
      left = mid;
  }

  cout << right << endl;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);

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

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

ll cutsToLEQ(vector<int> &arr, ll x) {
  ll ans = 0;
  for (int k : arr)
    ans += k / x + (k % x == 0 ? -1 : 0);
  //	printf("%lld cuts to %lld\\n", ans, x);
  return ans;
}

int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  vector<int> arr(n);
  for (int i = 0; i < n; ++i)
    scanf("%d", &arr[i]);
  ll lo = 1, hi = 1000000000;
  while (lo < hi) {
    //		printf("%lld %lld\\n", lo, hi);
    ll mid = (lo + hi) / 2;
    if (cutsToLEQ(arr, mid) <= k)
      hi = mid;
    else
      lo = mid + 1;
    //		printf("%lld %lld\\n", lo, hi);
  }
  printf("%lld\\n", lo);
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  vector<int> arr(n);
  for (int i = 0; i < n; ++i)
    scanf("%d", &arr[i]);
  multiset<pair<int, ll>> toCut; // (log len, log count)
  for (int x : arr)
    toCut.emplace(x, 1);
  int totalCutsMade = 0;
  while (totalCutsMade < k) {
    auto [logLen, logCount] = *toCut.rbegin();
    toCut.erase(toCut.find({logLen, logCount}));
    if (totalCutsMade + logCount > k)
      break;
    totalCutsMade += logCount;
    pair<int, ll> newBatch(logLen / 2 + (logLen % 2), 2 * logCount);
    toCut.emplace(logLen / 2 + (logLen % 2), 2 * logCount);
  }
  printf("%d\\n", toCut.rbegin()->first);
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

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

int n, k;
int a[200010];
char check(const int &n);

int main() {
  scanf("%d%d", &n, &k);
  int maxv = 0;
  long long sum = 0;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    sum += a[i], maxv = max(maxv, a[i]);
  }

  int l = (sum + n + k - 1) / (n + k), r = maxv;
  while (l <= r) {
    int m = l + r >> 1;
    if (check(m))
      r = m - 1;
    else
      l = m + 1;
  }
  printf("%d\\n", l);
  return 0;
}

char check(const int &m) {
  int sum = 0;
  for (int i = 0; i < n; ++i)
    sum += (a[i] - 1) / m;
  return sum <= k;
}


Error: 0

Fixed submission:

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

int n, k;
int a[200010];
char check(const int &n);

int main() {
  scanf("%d%d", &n, &k);
  int maxv = 0;
  long long sum = 0;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    sum += a[i], maxv = max(maxv, a[i]);
  }

  int l = sum / (n + k), r = maxv;
  while (l <= r) {
    int m = l + r >> 1;
    if (check(m))
      r = m - 1;
    else
      l = m + 1;
  }
  printf("%d\\n", l);
  return 0;
}

char check(const int &m) {
  int sum = 0;
  for (int i = 0; i < n; ++i)
    sum += (a[i] - 1) / m;
  return sum <= k;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define REP(i, start, end) for (int i = start, i##Len = (end); i < i##Len; ++i)
#define REPR(i, start, end) for (int i = start, i##Len = (end); i > i##Len; --i)
using ll = long long;
using namespace std;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);

  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  REP(i, 0, n)
  cin >> a[i];

  auto solve = [&](ll x) {
    ll cnt = 0;
    for (auto &l : a)
      cnt += l / x;
    return cnt > k;
  };

  ll ok = 0, ng = 1e9 + 1;
  while (abs(ok - ng) > 1) {
    ll mid = (ok + ng) / 2;
    if (solve(mid))
      ok = mid;
    else
      ng = mid;
  }

  ll cnt = 0;
  if (ok == 0) {
    cout << 1 << endl;
    return 0;
  }
  for (auto &l : a) {
    cnt += (l % ok > 0 ? l / ok : l / ok - 1);
  }
  cout << (cnt > k ? ok + 1 : ok) << endl;
}

Error: 0

Fixed submission:

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define REP(i, start, end) for (int i = start, i##Len = (end); i < i##Len; ++i)
#define REPR(i, start, end) for (int i = start, i##Len = (end); i > i##Len; --i)
using ll = long long;
using namespace std;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);

  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  REP(i, 0, n)
  cin >> a[i];

  auto solve = [&](ll x) {
    ll cnt = 0;
    for (auto &l : a)
      cnt += l / x;
    return cnt > k;
  };

  ll ok = 0, ng = 1e9 + 1;
  while (abs(ok - ng) > 1) {
    ll mid = (ok + ng) / 2;
    if (solve(mid))
      ok = mid;
    else
      ng = mid;
  }

  ll cnt = 0;
  for (auto &l : a) {
    cnt += (l % ok > 0 ? l / ok : l / ok - 1);
  }
  cout << (cnt > k ? ok + 1 : ok) << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

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

const int MOD = 1000000007;
const int INF = 1e9;

int main() {
  int n, k;
  const int max_n = 2 * 1e5;
  int a[max_n + 1];
  cin >> n >> k;
  int max_a = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    max_a = max(max_a, a[i]);
  }
  int left = 0;
  int right = max_a;
  int x;
  int sum = 0;
  while (right - left > 1) {
    sum = 0;
    x = (right + left) / 2;
    for (int i = 0; i < n; i++) {
      if (a[i] == x)
        sum += a[i] / x - 1;
      else
        sum += a[i] / x;
    }
    // cout << "x= " << x << ", sum = " << sum << endl;
    if (sum <= k)
      right = x;
    else
      left = x;
    // if(right - left <= 1) break;
  }

  cout << right << endl;

  return 0;
}

Error: 0

Fixed submission:

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

const int MOD = 1000000007;
const int INF = 1e9;

int main() {
  int n, k;
  const int max_n = 2 * 1e5;
  int a[max_n + 1];
  cin >> n >> k;
  int max_a = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    max_a = max(max_a, a[i]);
  }
  int left = 0;
  int right = max_a;
  int x = (right + left) / 2;
  int sum = 0;
  if (max_a == 0) {
    cout << 0 << endl;
    return 0;
  }
  while (1) {
    sum = 0;
    x = (right + left) / 2;
    for (int i = 0; i < n; i++) {
      if (a[i] == x)
        sum += a[i] / x - 1;
      else
        sum += a[i] / x;
    }
    // cout << "x= " << x << ", sum = " << sum << endl;
    if (sum <= k)
      right = x;
    else
      left = x;
    if (right - left <= 1)
      break;
  }

  cout << right << endl;

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

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;

int n, k;
vector<int> a;

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

int main() {
  cin >> n >> k;
  a.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int low = 1;
  int high = 1e9;
  int ans = 1e9;
  while (low <= high) {
    int md = (low + high) / 2;
    if (ok(md)) {
      high = md - 1;
      ans = min(ans, md);
    } else {
      low = md + 1;
    }
  }
  cout << ans << "\\n";
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;

int n, k;
vector<int> a;

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

int main() {
  cin >> n >> k;
  a.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int low = 0;
  int high = 1e9;
  int ans = 1e9;
  while (low <= high) {
    int md = (low + high) / 2;
    if (ok(md)) {
      high = md - 1;
      ans = min(ans, md);
    } else {
      low = md + 1;
    }
  }
  cout << ans << "\\n";
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

bool able_check(long L, long *A, long N, long K);

int main(void) {
  long N, K;
  cin >> N >> K;
  long *A = (long *)malloc(sizeof(long) * N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  long min = 1;
  long max = 1000000010;
  while (max - min > 5) {
    long mid = (min + max) / 2;
    if (able_check(mid, A, N, K)) {
      max = mid;
    } else {
      min = mid;
    }
  }
  for (long i = min; i <= max; i++) {
    if (able_check(i, A, N, K)) {
      cout << i << endl;
      break;
    }
  }
  return 0;
}

bool able_check(long L, long *A, long N, long K) {
  long retval = 0;
  for (int i = 0; i < N; i++) {
    if (A[i] % L == 0) {
      retval += A[i] / L - 1;
    } else {
      retval += A[i] / L;
    }
  }
  return retval <= K;
}


Error: 0

Fixed submission:

#include <iostream>
using namespace std;

bool able_check(long L, long *A, long N, long K);

int main(void) {
  long N, K;
  cin >> N >> K;
  long *A = (long *)malloc(sizeof(long) * N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  long min = 0;
  long max = 1000000010;
  while (max - min > 5) {
    long mid = (min + max) / 2;
    if (able_check(mid, A, N, K)) {
      max = mid;
    } else {
      min = mid;
    }
  }
  for (long i = min; i <= max; i++) {
    if (able_check(i, A, N, K)) {
      cout << i << endl;
      break;
    }
  }
  return 0;
}

bool able_check(long L, long *A, long N, long K) {
  long retval = 0;
  for (int i = 0; i < N; i++) {
    if (A[i] % L == 0) {
      retval += A[i] / L - 1;
    } else {
      retval += A[i] / L;
    }
  }
  return retval <= K;
}
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 all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  auto solve = [&](int x) {
    int cnt = 0;
    rep(i, n) {
      // x = 3
      // a: 1, 2, 3, 4, 5, 6, 7...
      // b: 0, 0, 0, 1, 1, 1, 2...
      cnt += (a[i] - 1) / x;
    }

    if (cnt <= k)
      return true;
    else
      return false;
  };
  int ok = 1e9; // 解が存在する値
  int ng = 0;   // 解が存在しない値
  while (abs(ok - ng) > 1) {
    int mid = (ok + ng) / 2;
    if (solve(mid)) {
      ok = mid;
    } else {
      ng = mid;
    }
  }
  cout << ok << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  auto solve = [&](int x) {
    int cnt = 0;
    rep(i, n) {
      double now = a[i];
      int div = 1;
      while (x < now / div) {
        cnt++;
        div++;
      }
    }

    if (cnt <= k)
      return true;
    else
      return false;
  };
  int ok = 1e9; // 解が存在する値
  int ng = 0;   // 解が存在しない値
  while (abs(ok - ng) > 1) {
    int mid = (ok + ng) / 2;
    if (solve(mid)) {
      ok = mid;
    } else {
      ng = mid;
    }
  }
  cout << ok << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, l = 0, r = pow(10, 9);
  cin >> n >> k;
  vector<double> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a.rbegin(), a.rend());
  while (r - l > 1) {
    int m = (l + r) / 2, c = 0;
    for (int i = 0; i < n; i++) {
      double t = a[i] / m;
      c += (t == (int)t ? t - 1 : t);
      if (c > k)
        break;
    }
    c > k ? l = m : r = m;
  }
  cout << r;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<double> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a.rbegin(), a.rend());
  for (int l = 1; l <= a[0]; l++) {
    int c = 0;
    for (int i = 0; i < n; i++) {
      double t = a[i] / l;
      if (t == (int)t)
        t--;
      c += t;
      if (c > k)
        break;
    }
    if (c <= k) {
      cout << l;
      return 0;
    }
  }
}
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 FILL0(x) memset(x, 0, sizeof(x))
#define FILL1(x) memset(x, -1, sizeof(x))

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20);

  int n, k;

  cin >> n;
  cin >> k;

  int a[n];
  rep(i, n) { cin >> a[i]; }

  int l = 0;
  int r = 1e9;

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

    auto judge = [&](int val) {
      ll count = 0;
      rep(i, n) { count += (a[i] - 1) / val; }
      return count <= k;
    };

    if (judge(mid)) {
      r = mid;
    } else {
      l = mid;
    }
  }

  cout << r << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FILL0(x) memset(x, 0, sizeof(x))
#define FILL1(x) memset(x, -1, sizeof(x))

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20);

  int n, k;

  cin >> n;
  cin >> k;

  int a[n];
  rep(i, n) { cin >> a[i]; }

  int l = -1;
  int r = 1e9;

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

    auto judge = [&](int val) {
      ll count = 0;
      rep(i, n) { count += (a[i] - 1) / val; }
      return count <= k;
    };

    if (judge(mid)) {
      r = mid;
    } else {
      l = mid;
    }
  }

  cout << r << endl;

  return 0;
}