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

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define endl '\\n'
#define maxn 200010
const int MOD = 1000000007;

int v[maxn];
int n;
int k;

bool check(int m) {
  int times = 0;
  for (int i = 0; i < n; i++) {
    times += v[i] / m + (v[i] % m > 0) - 1;
  }
  return times <= k;
}

void solve() {
  cin >> n >> k;

  for (int i = 0; i < n; ++i)
    cin >> v[i];
  int lo = 1, hi = 1e12, mid, ans = 0;
  while (lo <= hi) {
    mid = lo + hi >> 1;
    if (check(mid)) {
      ans = mid;
      hi = mid - 1;
    } else
      lo = mid + 1;
  }
  cout << ans << endl;
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int t = 1;
  //    cin >> t;

  while (t--)
    solve();
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define endl '\\n'
#define maxn 200010
const int MOD = 1000000007;

int v[maxn];
int n;
int k;

bool check(int m) {
  int times = 0;
  for (int i = 0; i < n; i++) {
    times += v[i] / m + (v[i] % m > 0) - 1;
  }
  return times <= k;
}

void solve() {
  cin >> n >> k;

  for (int i = 0; i < n; ++i)
    cin >> v[i];
  int lo = 0, hi = 1e12, mid, ans = 0;
  while (lo <= hi) {
    mid = lo + hi >> 1;
    if (check(mid)) {
      ans = mid;
      hi = mid - 1;
    } else
      lo = mid + 1;
  }
  cout << ans << endl;
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int t = 1;
  //    cin >> t;

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

#include <bits/stdc++.h>

#define rep(i, N) for (int i = 0; i < N; i++)
#define rep2(i, N) for (int i = 1; i <= N; i++)
using namespace std;
long long INF = 1e18;
long long mod = 1e9 + 7;

// status unsolved

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

  long long a[n];
  rep(i, n) cin >> a[i];

  long long second[46];
  second[0] = 1;
  long long sum[50];
  sum[0] = 0;
  rep2(i, 45) {
    second[i] = second[i - 1] * 2;
    sum[i] = sum[i - 1] + second[i - 1];
    // cout<<sum[i]<<" ";
  }
  // cout<<endl;
  long long right = 1e9;
  long long left = 0;

  while (left + 1 < right) {

    long long mid = (right + left) / 2;

    long long cnt = 0;
    // cout<<mid<<endl;
    rep(i, n) {

      // if(a[i]<=mid)continue;

      // cnt+=ceil(((double)a[i]/mid))-1;
      cnt += (a[i] + mid - 1) / mid - 1;
    }

    if (cnt > k) {
      left = mid;
    } else {
      right = mid;
    }
  }
  // cout<<endl;

  cout << right << endl;
  return 0;
}
/*


*/


Error: 0

Fixed submission:

#include <bits/stdc++.h>

#define rep(i, N) for (int i = 0; i < N; i++)
#define rep2(i, N) for (int i = 1; i <= N; i++)
using namespace std;
long long INF = 1e18;
long long mod = 1e9 + 7;

// status unsolved

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

  long long a[n];
  rep(i, n) cin >> a[i];

  long long second[46];
  second[0] = 1;
  long long sum[50];
  sum[0] = 0;
  rep2(i, 45) {
    second[i] = second[i - 1] * 2;
    sum[i] = sum[i - 1] + second[i - 1];
    // cout<<sum[i]<<" ";
  }
  // cout<<endl;
  long long right = 1e9;
  long long left = -1;

  while (left + 1 < right) {

    long long mid = (right + left) / 2;

    long long cnt = 0;
    // cout<<mid<<endl;
    rep(i, n) {

      // if(a[i]<=mid)continue;

      // cnt+=ceil(((double)a[i]/mid))-1;
      cnt += (a[i] + mid - 1) / mid - 1;
    }
    // cout<<endl;

    if (cnt > k) {
      left = mid;
    } else {
      right = mid;
    }
  }
  // cout<<endl;

  cout << right << endl;
  return 0;
}
/*


*/
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
int main() {
#define int long long
  int N, K, ans = MOD;
  cin >> N >> K;
  vector<int> A(N);
  int MA = 0;
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    MA = max(MA, A.at(i));
  }
  int left = 1, right = MA;
  while (left <= right) {
    // cout<<left<<" "<<right<<endl;
    int mid = left + (right - left) / 2;
    int count = 0;
    for (int i = 0; i < N; i++) {
      if (mid >= A.at(i)) {
        continue;
      }
      // cout<<i<<" "<<mid<<endl;
      int answer_for_i = MOD;
      int L = 1, R = A.at(i);
      while (L <= R) {
        int M = L + (R - L) / 2;
        // cout<<M<<endl;
        if (A.at(i) <= mid * M) {
          answer_for_i = min(answer_for_i, M - 1);
          R = M - 1;
        } else {
          L = M + 1;
        }
      }
      count += answer_for_i;
      // cout<<i<<" "<<answer_for_i<<" "<<mid<<endl;
    }
    if (count <= K) {
      right = mid - 1;
      ans = min(ans, mid);
    } else {
      left = mid + 1;
    }
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
int main() {
  long double N, K;
  cin >> N >> K;
  priority_queue<pair<long double, long double>> que;
  // unordered_map<long long, long long> mp;
  for (long long i = 0; i < N; i++) {
    long double a;
    cin >> a;
    que.push(make_pair(a, 1));
    // mp[a]++;
  }
  for (long long i = 0; i < K; i++) {
    auto R = que.top();
    long double R1 = R.first;
    long double R2 = R.second;
    // cout<<R1<<" "<<R2<<endl;
    R1 = R1 * R2 / (R2 + 1);
    R2++;
    que.pop();
    que.push(make_pair(R1, R2));
  }
  auto A = que.top();
  // long long ans = A.first;
  std::string str;
  str = std::to_string(A.first);
  long long mm = MOD;
  int count = 0, check = 0;
  for (int i = 0; i < (long long)str.size(); i++) {
    if (count == 1 && str.at(i) != '0') {
      check++;
      break;
    }
    if (str.at(i) == '.') {
      mm = i;
      count++;
    }
  }
  if (check == 0) {
    long long ans = A.first;
    cout << ans << endl;
  } else {
    long long ans = A.first;
    cout << ans + 1 << endl;
  }
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n, k;
  cin >> n >> k;
  int a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int l = 1, r = 1e9;
  auto check = [&](int len, int k) {
    int req = 0;
    for (int i = 0; i < n; i++) {
      int factor = a[i] / len;
      req += (factor - ((factor * len == a[i]) ? 1 : 0));
    }
    return req <= k;
  };
  while (l <= r) {
    int mid = l + (r - l) / 2;
    if (check(mid, k)) {
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  cout << r + 1 << "\\n";
  return 0;
}


Error: 0

Fixed submission:

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

int main() {
  int n, k;
  cin >> n >> k;
  int a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int l = 0, r = 1e9;
  auto check = [&](int len, int k) {
    int req = 0;
    for (int i = 0; i < n; i++) {
      int factor = a[i] / len;
      req += (factor - ((factor * len == a[i]) ? 1 : 0));
    }
    return req <= k;
  };
  int count = 0;
  while (l <= r && (count++) < 1000) {
    int mid = l + (r - l) / 2;
    if (check(mid, k)) {
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  cout << r + 1 << "\\n";
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <functional>
#include <iostream>
#include <string>
using namespace std;

#include <climits>
#include <iomanip>
#include <math.h>
#include <queue>
#include <vector>
using Graph = vector<vector<int>>;
const double PI = 3.14159265358979323846;

int needed_kaisu(long long a, long long N, long long *A) {
  int count = 0;
  for (long long i = 0; i < N; i++) {
    count += (A[i] + a - 1) / a - 1;
  }
  return count;
}

int main() {

  long long N, K, A[200100], ans, mem[200100];
  priority_queue<pair<long long, long long>> queue;

  long long max = 0;

  cin >> N >> K;
  for (long long i = 0; i < N; i++) {
    cin >> A[i];
    if (max < A[i]) {
      max = A[i];
    }
  }

  long long lb = 0;
  long long ub = max;

  if (K == 0) {
    cout << max << endl;
    return 0;
  }

  while (1) {
    long long tmp = (lb + ub + 1) / 2;
    if (needed_kaisu(tmp, N, A) <= K) {
      ub = tmp;
    }
    if (needed_kaisu(tmp, N, A) >= K + 1) {
      lb = tmp;
    }
    if (ub <= lb + 1) {
      break;
    }
  }

  cout << ub << endl;

  cin >> N;

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <functional>
#include <iostream>
#include <string>
using namespace std;

#include <climits>
#include <iomanip>
#include <math.h>
#include <queue>
#include <vector>
using Graph = vector<vector<int>>;
const double PI = 3.14159265358979323846;

int needed_kaisu(long long a, long long N, long long *A) {
  int count = 0;
  for (long long i = 0; i < N; i++) {
    count += (A[i] + a - 1) / a - 1;
  }
  return count;
}

int main() {

  long long N, K, A[200100], ans, mem[200100];
  priority_queue<pair<long long, long long>> queue;

  long long max = 0;

  cin >> N >> K;
  for (long long i = 0; i < N; i++) {
    cin >> A[i];
    if (max < A[i]) {
      max = A[i];
    }
  }

  long long lb = 0;
  long long ub = max;

  if (K == 0) {
    cout << max << endl;
    return 0;
  }

  while (1) {
    long long tmp = (lb + ub) / 2;
    if (needed_kaisu(tmp, N, A) <= K) {
      ub = tmp;
    }
    if (needed_kaisu(tmp, N, A) >= K + 1) {
      lb = tmp;
    }
    if (ub <= lb + 1) {
      break;
    }
  }

  cout << ub << endl;

  cin >> N;

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

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

typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<pii> vpii;
typedef vector<vpll> vvpll;
typedef vector<vpii> vvpii;

#define pb push_back
#define eb emplace_back
#define pf push_front
#define all(c) (c).begin(), (c).end()
#define ff first
#define ss second
#define mp(x, y) make_pair((x), (y))
#define boost                                                                  \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL)

int f(int len, int goal) { return len / goal - (len % goal == 0); }

void solve() {

  int n, k;
  cin >> n >> k;
  int a[n];
  for (int &u : a) {
    cin >> u;
  }
  int lo = 1, hi = 1e9;
  int ans;
  while (lo <= hi) {
    int mid = (lo + hi) / 2;
    int cnt = 0;
    for (int u : a) {
      cnt += f(u, mid);
    }
    if (cnt <= k) {
      ans = mid;
      hi = mid - 1;
    } else {
      lo = mid + 1;
    }
  }
  cout << ans << '\\n';
}

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

  boost;

  int t = 1;
  // cin >> t;

  for (int i = 1; i <= t; i++) {
    // cout << "Case #" << i << ": ";

    solve();
  }
  return 0;
}

Error: -11

Fixed submission:

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

typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<pii> vpii;
typedef vector<vpll> vvpll;
typedef vector<vpii> vvpii;

#define pb push_back
#define eb emplace_back
#define pf push_front
#define all(c) (c).begin(), (c).end()
#define ff first
#define ss second
#define mp(x, y) make_pair((x), (y))
#define boost                                                                  \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL)

int f(int len, int goal) { return len / goal - (len % goal == 0); }

void solve() {

  int n, k;
  cin >> n >> k;
  int a[n];
  for (int &u : a) {
    cin >> u;
  }
  int lo = 0, hi = 1e9;
  int ans;
  while (lo <= hi) {
    int mid = (lo + hi) / 2;
    int cnt = 0;
    for (int u : a) {
      cnt += f(u, mid);
    }
    if (cnt <= k) {
      ans = mid;
      hi = mid - 1;
    } else {
      lo = mid + 1;
    }
  }
  cout << ans << '\\n';
}

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

  boost;

  int t = 1;
  // cin >> t;

  for (int i = 1; i <= t; i++) {
    // cout << "Case #" << i << ": ";

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

#include "bits/stdc++.h"

using namespace std;

bool possible(long long longestLog, const vector<long long> &A, long long K) {
  long long N = A.size();
  long long numOfLongestLogs = 0;
  for (long long i = 0; i < N; ++i) {
    numOfLongestLogs += A[i] / longestLog;
    if (A[i] % longestLog == 0) {
      --numOfLongestLogs;
    }
  }
  return (numOfLongestLogs <= K);
}

void Main() {
  long long N, K;
  cin >> N >> K;
  vector<long long> A(N, 0LL);
  for (long long i = 0; i < N; ++i) {
    cin >> A[i];
  }
  sort(A.begin(), A.end(), greater<long long>());

  long long ub = A.front();
  long long lb = 0LL;
  while (ub - lb > 1LL) {
    long long mid = (ub + lb) / 2LL;
    if (possible(mid, A, K)) {
      ub = mid;
    } else {
      lb = mid;
    }
  }
  cout << ub << endl;
  // if (ub == lb) {
  //     cout << ub << endl;
  // }
  // else {
  //     if (possible(lb, A, K)) {
  //         cout << lb << endl;
  //     }
  //     else {
  //         cout << ub << endl;
  //     }
  // }
}

int main() {
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Error: 0

Fixed submission:

#include "bits/stdc++.h"

using namespace std;

bool possible(long long longestLog, const vector<long long> &A, long long K) {
  long long N = A.size();
  long long numOfLongestLogs = 0;
  for (long long i = 0; i < N; ++i) {
    numOfLongestLogs += A[i] / longestLog;
    if (A[i] % longestLog == 0) {
      --numOfLongestLogs;
    }
  }
  return (numOfLongestLogs <= K);
}

void Main() {
  long long N, K;
  cin >> N >> K;
  vector<long long> A(N, 0LL);
  for (long long i = 0; i < N; ++i) {
    cin >> A[i];
  }
  sort(A.begin(), A.end(), greater<long long>());

  long long ub = A.front();
  long long lb = 0LL;
  while (ub - lb > 1LL) {
    long long mid = (ub + lb) / 2LL;
    if (possible(mid, A, K)) {
      ub = mid;
    } else {
      lb = mid;
    }
  }
  if (ub == lb) {
    cout << ub << endl;
  } else {
    if (possible(lb, A, K)) {
      cout << lb << endl;
    } else {
      cout << ub << endl;
    }
  }
}

int main() {
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, s, n) for (int i = s; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

ll n, k;

bool isOK(vector<ll> &a, ll mid) {
  ll l = 0;
  rep(i, 0, n) {
    if (a[i] % mid == 0) {
      l += a[i] / mid - 1;
    } else {
      l += a[i] / mid;
    }
  }
  if (l <= k)
    return true;
  else
    return false;
}

ll binary_search(vector<ll> &a, ll m) {
  ll left = 0;
  ll right = m;

  while (right - left > 1) {
    ll mid = (right + left) / 2;
    if (isOK(a, mid))
      right = mid;
    else
      left = mid;
  }
  return right;
}

int main() {
  cin >> n >> k;
  vector<ll> a(n);
  ll m = 0;
  rep(i, 0, n) {
    cin >> a[i];
    m = max(m, a[i]);
  }
  sort(a.begin(), a.end());
  int ans = binary_search(a, m);
  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, s, n) for (int i = s; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

ll n, k;

bool isOK(vector<ll> &a, ll mid) {
  ll l = 0;
  rep(i, 0, n) {
    if (a[i] % mid == 0) {
      l += a[i] / mid - 1;
    } else {
      l += a[i] / mid;
    }
  }
  if (l <= k)
    return true;
  else
    return false;
}

ll binary_search(vector<ll> &a, ll m) {
  ll left = -1;
  ll right = m + 1;

  while (right - left > 1) {
    ll mid = (right + left) / 2;
    if (isOK(a, mid))
      right = mid;
    else
      left = mid;
  }
  return right;
}

int main() {
  cin >> n >> k;
  vector<ll> a(n);
  ll m = 0;
  rep(i, 0, n) {
    cin >> a[i];
    m = max(m, a[i]);
  }
  sort(a.begin(), a.end());
  int ans = binary_search(a, m);
  cout << ans << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int cut(int k, int *a, int n, int u) {
  int res = 0;
  if (!k)
    return 0;
  for (int i = 0; i < n; ++i) {
    res += (a[i] + k - 1) / k - 1;
  }
  // cout<<k<<" "<<res<<endl;
  return (res <= u) ? 1 : 0;
}

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

  int l = -1, r = 1000000001, m;
  while (l < r - 1) {
    m = l + (r - l) / 2;
    if (cut(m, a, n, k)) {
      r = m;
    } else {
      l = m;
    }
  }

  cout << r << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int cut(int k, int *a, int n, int u) {
  int res = 0;
  for (int i = 0; i < n; ++i) {
    res += (a[i] + k - 1) / k - 1;
  }
  // cout<<k<<" "<<res<<endl;
  return (res <= u) ? 1 : 0;
}

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

  int l = -1, r = 1000000001, m;
  while (l < r - 1) {
    m = l + (r - l) / 2;
    if (cut(m, a, n, k)) {
      r = m;
    } else {
      l = m;
    }
  }

  cout << r << endl;

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int &x : a) {
    cin >> x;
  }
  int l = 1, r = *max_element(a.begin(), a.end());
  while (l < r) {
    int64_t m = (l + r) >> 1;
    int64_t tmp = 0;
    for (int x : a) {
      tmp += (x + m - 1) / m - 1;
    }
    if (tmp > k) {
      l = m + 1;
    } else {
      r = m;
    }
  }
  cout << r << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int &x : a) {
    cin >> x;
  }
  int l = 0, r = *max_element(a.begin(), a.end());
  while (l < r) {
    int64_t m = (l + r) >> 1;
    int64_t tmp = 0;
    for (int x : a) {
      tmp += (x + m - 1) / m - 1;
    }
    if (tmp > k) {
      l = m + 1;
    } else {
      r = m;
    }
  }
  cout << r << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#define ll long long

using namespace std;

ll a[200002];

bool isValid(ll n, ll k, ll x) {
  ll count = 0;
  for (ll i = 0; i < n; i++) {
    if (a[i] > x)
      count += a[i] / x;
  }
  return (count <= k);
}

ll getAns(ll n, ll k) {
  if (k == 0) {
    ll ans = a[0];
    for (ll i = 1; i < n; i++)
      ans = max(ans, a[i]);
    return ans;
  }

  ll low = 1;
  ll high = 1000000002;
  ll mid = 0;
  ll ans;

  while (low <= high) {
    mid = low + (high - low) / 2;
    if (isValid(n, k, mid)) {
      ans = mid;
      high = mid - 1;
    } else
      low = mid + 1;
  }
  return ans;
}

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

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

  cout << getAns(n, k) << '\\n';
}


Error: TLE

Fixed submission:

#include <iostream>
#define ll long long

using namespace std;

ll a[200002];

bool isValid(ll n, ll k, ll x) {
  ll count = 0;
  for (ll i = 0; i < n; i++) {
    count += a[i] / x;
  }
  return (count <= k);
}

ll getAns(ll n, ll k) {
  if (k == 0) {
    ll ans = a[0];
    for (ll i = 1; i < n; i++)
      ans = max(ans, a[i]);
    return ans;
  }

  ll low = 1;
  ll high = 1000000002;
  ll mid = 0;
  ll ans;

  while (low <= high) {
    mid = low + (high - low) / 2;
    if (isValid(n, k, mid)) {
      ans = mid;
      high = mid;
    } else
      low = mid + 1;
  }
  return ans;
}

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

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

  cout << getAns(n, k) << '\\n';
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;

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

  ll l, r;
  l = 0;
  r = 1000001000;
  while (l + 1 < r) {
    ll t = (l + r) / 2;
    int tn = 0;
    for (int i = 0; i < n; i++) {
      tn += a[i] / t;
      if (a[i] % t != 0)
        tn++;
      tn--;
    }
    if (tn <= k) {
      r = t;
    } else {
      l = t;
    }
    // cout << l << "," << r << " " << t << " " << tn << endl;
  }

  cout << r << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;

int main() {
  int n, k;
  cin >> n >> k;
  auto compare = [](pair<ll, ll> l, pair<ll, ll> r) {
    return l.first * r.second < l.second * r.first;
  };

  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, decltype(compare)> q{
      compare};

  for (int i = 0; i < n; i++) {
    ll a;
    cin >> a;
    q.push(make_pair(a, 1));
  }

  for (int i = 0; i < k; i++) {
    pair<ll, ll> p;
    p = q.top();
    q.pop();
    p.second++;
    q.push(p);
  }

  pair<ll, ll> ans;
  ans = q.top();

  if ((ans.first % ans.second) == 0)
    cout << ans.first / ans.second << endl;
  else
    cout << ans.first / ans.second + 1 << endl;

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

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int ng = 0, ok = 1e9;
  while (ok - ng > 1) {
    int x = (ok + ng) / 2;
    auto f = [&](int x) {
      ll now = 0;
      rep(i, n) now += (a[i] - 1) / x;
      return now <= k;
    };
    if (f(x))
      ok = x;
    else
      ng = x;
  }
  cout << ok << endl;
  return 0;
}

Error: 0

Fixed submission:

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

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

  ll ok = 1000000000 + 1;
  ll ng = 0;
  ll mid, k_cnt;
  rep(i, 100) {
    mid = (ok + ng) / 2;
    // cout<<mid<<endl;
    k_cnt = 0;
    rep(j, n) { k_cnt = k_cnt + (a[j] + mid - 1) / mid - 1; }
    if (k_cnt <= k)
      ok = mid;
    else
      ng = mid;
  }
  cout << ok << endl;

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
using namespace std;
long long int lis[200003];
int main() {
  long long int N, K;
  cin >> N >> K;
  for (int i = 0; i < N; i++)
    cin >> lis[i];
  long long int l = 0, r = 2100000000, mid;
  for (int i = 0; i < 100; i++) {
    mid = (l + r) / 2;
    if (mid == 0) {
      cout << 1 << endl;
      return 0;
    }
    long long int cou = 0;
    for (int i = 0; i < N; i++) {
      cou += (lis[i] - 1) / mid;
    }
    if (cou <= K)
      r = mid;
    else
      l = mid;
    if (mid == 0) {
      cout << 1 << endl;
      return 0;
    }
  }
  cout << r << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
using namespace std;
long long int lis[200003];
int main() {
  long long int N, K;
  cin >> N >> K;
  for (int i = 0; i < N; i++)
    cin >> lis[i];
  long long int l = 0, r = 2100000000, mid;
  for (int i = 0; i < 100; i++) {
    mid = (l + r) / 2;
    long long int cou = 0;
    for (int i = 0; i < N; i++) {
      cou += (lis[i] - 1) / mid;
    }
    if (cou <= K)
      r = mid;
    else
      l = mid;
    if (mid == 0) {
      cout << 1 << endl;
      return 0;
    }
  }
  cout << r << endl;
  return 0;
}