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

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

#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define endl '\\n'

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

const int INF = 1e9;
const int MOD = 1e9 + 7;
const int MAXN = 2e5 + 5;

ll N, K, A[MAXN];

bool chk(ll x) {
  ll tot = 0;
  for (int i = 1; i <= N; i++) {
    ll cnt = A[i] / x;
    if (A[i] % x)
      cnt++;
    tot += cnt - 1;
  }
  return tot <= K;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> N >> K;
  for (int i = 1; i <= N; i++)
    cin >> A[i], A[i] *= 2;

  ll l = 1, r = 2e9, ans = 2e9;
  while (l <= r) {
    ll m = l + r >> 1;
    if (chk(m)) {
      ans = m;
      r = m - 1;
    } else
      l = m + 1;
  }
  if (ans % 2)
    ans++;
  cout << ans / 2;
}


Error: WA

Fixed submission:

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

#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define endl '\\n'

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

const int INF = 1e9;
const int MOD = 1e9 + 7;
const int MAXN = 2e5 + 5;

int N, K, A[MAXN];

bool chk(ll x) {
  ll tot = 0;
  for (int i = 1; i <= N; i++) {
    ll cnt = A[i] / x;
    if (A[i] % x)
      cnt++;
    tot += cnt - 1;
  }
  return tot <= K;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> N >> K;
  for (int i = 1; i <= N; i++)
    cin >> A[i], A[i] *= 2;

  ll l = 1, r = 2e9, ans = 2e9;
  for (int i = 1; i <= 100; i++) {
    ll m = l + r >> 1;
    if (chk(m)) {
      ans = m;
      r = m - 1;
    } else
      l = m + 1;
  }
  if (ans % 2)
    ans++;
  cout << ans / 2;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define INFLL 1e18
using namespace std;

#define REPR(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
#define endl "\\n"

template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
typedef long long ll;

void solve() {
  // 解xに対して K回以内の切断で達成かのうか調べる O(Nlogmax(Ai))
  ll N, K;
  cin >> N >> K;
  vector<ll> A(N);
  REP(i, N) cin >> A[i];

  auto isOk = [&](ll key) {
    ll need_cut = 0;
    for (const auto &a : A) {
      // debug
      ll cut = ((a + key - 1) / key) - 1;
      need_cut += cut;
    }
    bool res = need_cut <= K;
    return res;
  };

  // binary search
  ll l = 0;
  ll r = INFLL;

  while ((r - l) > 1) {
    ll mid = (l + r) / 2;
    if (isOk(mid))
      r = mid;
    else
      l = mid;
  }

  cout << r << endl;
}

int main() {
  solve();
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define INFLL 1e18
using namespace std;

#define REPR(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
#define endl "\\n"

template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
typedef long long ll;

void solve() {
  // 解xに対して K回以内の切断で達成かのうか調べる O(Nlogmax(Ai))
  ll N, K;
  cin >> N >> K;
  vector<ll> A(N);
  REP(i, N) cin >> A[i];

  auto isOk = [&](ll key) {
    ll need_cut = 0;
    for (const auto &a : A) {
      // debug
      ll cut = ((a + key - 1) / key) - 1;
      need_cut += cut;
    }
    bool res = need_cut <= K;
    return res;
  };

  // binary search
  ll l = -1;
  ll r = INFLL;

  while ((r - l) > 1) {
    ll mid = (l + r) / 2;
    if (isOk(mid))
      r = mid;
    else
      l = mid;
  }

  cout << r << endl;
}

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

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

int main() {
  // your code goes
  long long int n, k;
  cin >> n >> k;
  long long int a[n];
  for (long int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long int l = 1, r = 1e9;
  long long int ans = 1e9;
  while (l <= r) {
    long long int mid = (l + r) / 2;
    long long int ss = 0;
    for (long int i = 0; i < n; i++) {
      ss += a[i] / mid;
      if (a[i] % mid == 0)
        ss--;
    }
    if (ss > k) {
      l = mid + 1;
    } else {
      ans = min(ans, mid);
      r = mid - 1;
    }
  }
  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

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

int main() {
  // your code goes
  long long int n, k;
  cin >> n >> k;
  long long int a[n];
  for (long int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long int l = 0, r = 1e9;
  long long int ans = 1e9;
  while (l <= r) {
    long long int mid = (l + r) / 2;
    long long int ss = 0;
    for (long int i = 0; i < n; i++) {
      ss += a[i] / mid;
      if (a[i] % mid == 0)
        ss--;
    }
    if (ss > k) {
      l = mid + 1;
    } else {
      ans = min(ans, mid);
      r = mid - 1;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int N, K;
vector<int> A;

bool isOK(int m) {
  int sum = 0;
  for (int i = 0; i < N; i++) {
    sum += ceil((double)A[i] / m - 1);
  }
  if (sum <= K)
    return true;
  else
    return false;
}

int binary_search() {
  int ng = 0;
  int ok = *max_element(A.begin(), A.end()) + 1;
  while (abs(ok - ng) > 1) {
    int mid = (ok + ng) / 2;

    if (isOK(mid))
      ok = mid;
    else
      ng = mid;
  }
  return ok;
}

int main() {
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    A.push_back(a);
  }
  cout << binary_search() << endl;
}

Error: TLE

Fixed submission:


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

int main() {
  int N, K;
  cin >> N >> K;
  priority_queue<tuple<double, double, int>> A;
  for (int i = 0; i < N; i++) {
    double Ai;
    cin >> Ai;
    A.push(make_tuple(Ai, Ai, 1));
  }
  for (int i = 0; i < K; i++) {
    auto B = A.top();
    A.pop();
    A.push(make_tuple(get<1>(B) / (get<2>(B) + 1), get<1>(B), get<2>(B) + 1));
  }
  cout << (int)ceil(get<0>(A.top())) << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

#define ull unsigned long long
#define ll long long
#define imei(...) "[ " << #__VA_ARGS__ << " = " << __VA_ARGS__ << " ] "

using namespace std;

void solve(int t) {
  int n;
  cin >> n;
}

int main(int argc, char *argv[]) {
  int n, k, l = 1, r = 1;
  vector<int> a;

  cin >> n >> k;
  a.resize(n);

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

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

    for (int &v : a)
      need += (v - 1) / m;

    if (need > k)
      l = m + 1;
    else
      r = m - 1;
  }
  cout << l << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define ull unsigned long long
#define ll long long
#define imei(...) "[ " << #__VA_ARGS__ << " = " << __VA_ARGS__ << " ] "

using namespace std;

void solve(int t) {
  int n;
  cin >> n;
}

int main(int argc, char *argv[]) {
  int n, k;
  priority_queue<pair<double, int>> pq;
  vector<pair<int, int>> tag;

  cin >> n >> k;
  tag.resize(n);

  for (int i = 0; i < n; i++) {
    int l;
    cin >> l;
    pq.push({(double)l, i});
    tag[i] = {l, 1};
  }

  while (k--) {
    auto it = pq.top();
    int idx = it.second;
    pq.pop();

    tag[idx].second++;

    pq.push({((double)tag[idx].first) / ((double)tag[idx].second), idx});
  }

  cout << (int)ceil(pq.top().first);

  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++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const ll LINF = 1001001001001001;
const int MOD = 1000000007;

template <typename T> void print(const T &v);

// numをboarder以下にするために何回切る必要があるかを返す
ll f(ll num, ll boarder) {
  if (num <= boarder) {
    return 0;
  }
  return ((num + boarder - 1) / boarder) - 1;
}

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> as(n);
  ll maxi = 0;
  for (int i = 0; i < n; i++) {
    cin >> as[i];
    maxi = max(maxi, as[i]);
  }
  // 二分探索
  ll left = 0;
  ll right = 1000000000;
  while (right - left > 1) {
    ll cnt = 0;
    bool flag = true;
    ll mid = (right + left) / 2;
    // cout << mid << endl;
    for (int i = 0; i < n && flag; i++) {
      cnt += f(as[i], mid);
      if (cnt > k) {
        flag = false;
      }
    }
    if (flag) {
      right = mid;
    } else {
      left = mid;
    }
  }
  cout << right << endl;
  return 0;
}

// Use For Debug
template <typename T> void print(T const &v) {
  for (int i = 0; i < v.size(); i++) {
    if (i)
      cout << ' ';
    cout << v[i];
  }
  cout << endl;
};

Error: 0

Fixed submission:

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

template <typename T> void print(const T &v);

// numをboarder以下にするために何回切る必要があるかを返す
ll f(ll num, ll boarder) {
  if (num <= boarder) {
    return 0;
  }
  return ((num + boarder - 1) / boarder) - 1;
}

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> as(n);
  for (int i = 0; i < n; i++) {
    cin >> as[i];
  }
  // 二分探索
  ll left = -1;
  ll right = 1000000000;
  while (right - left > 1) {
    ll cnt = 0;
    bool flag = true;
    ll mid = (right + left) / 2;
    // cout << mid << endl;
    for (int i = 0; i < n && flag; i++) {
      cnt += f(as[i], mid);
      if (cnt > k) {
        flag = false;
      }
    }
    if (flag) {
      right = mid;
    } else {
      left = mid;
    }
  }
  cout << right << endl;
  return 0;
}

// Use For Debug
template <typename T> void print(T const &v) {
  for (int i = 0; i < v.size(); i++) {
    if (i)
      cout << ' ';
    cout << v[i];
  }
  cout << endl;
};
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define fast                                                                   \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define endl "\\n";
using namespace std;
typedef long long int ll;
bool possible(int mid, vector<int> a, int k) {
  for (auto i : a) {
    k -= (i + mid - 1) / mid - 1;
  }
  if (k >= 0)
    return true;
  return false;
}
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int mn = 1, mx = (int)1e9 + 100;
  while (mn != mx) {
    int mid = (mn) + (mx - mn) / 2;
    if (possible(mid, a, k))
      mx = mid;
    else
      mn = mid + 1;
  }
  cout << mx << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <map>
#include <vector>
#define fast                                                                   \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define endl "\\n";
using namespace std;
typedef long long int ll;
bool possible(int mid, vector<int> a, int k) {
  for (auto i : a) {
    k -= (i - 1) / mid;
  }
  if (k >= 0)
    return true;
  return false;
}
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int mn = 0, mx = (int)1e9 + 100;
  while (mn != mx) {
    int mid = (mn + mx) / 2;
    if (possible(mid, a, k))
      mx = mid;
    else
      mn = mid + 1;
  }
  cout << mx << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int n, k, a[200005];

bool can(int x) {
  int need = 0;
  for (int i = 0; i < n; i++) {
    need += (a[i] - 1) / x;
  }

  return need <= k;
}

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

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

  int lo = 1, mid, hi = 1e9;
  while (lo < hi) {
    mid = (lo + hi) / 2;
    if (can(mid)) {
      hi = mid;
    } else {
      lo = mid + 1;
    }
  }

  cout << lo << '\\n';

  return 0;
}

Error: TLE

Fixed submission:

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

int n, k, a[200005];

bool can(int x) {
  priority_queue<int> pq;
  for (int i = 0; i < n; i++) {
    pq.push(a[i]);
  }

  for (int i = 0; i < k && !pq.empty(); i++) {
    int log = pq.top();
    pq.pop();
    if (x >= log) {
      continue;
    }

    pq.push(x);
    pq.push(log - x);
  }

  while (!pq.empty()) {
    if (pq.top() > x) {
      return 0;
    }

    pq.pop();
  }

  return 1;
}

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

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

  int lo = 1, mid, hi = 1e9;
  while (lo < hi) {
    mid = (lo + hi) / 2;
    if (can(mid)) {
      hi = mid;
    } else {
      lo = mid + 1;
    }
  }

  cout << lo << '\\n';

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

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

template <typename T> void print(T t) { cout << t << endl; }
template <typename T, typename... Args> void print(T t, Args... args) {
  cout << t << " ";
  print(args...);
}

typedef complex<double> base;

#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define endl '\\n'
#define int long long
#define double long double

int n, k;
int arr[200005];
bool check(int req) {
  int moves = 0;
  for (int i = 0; i < n; i++) {
    if (arr[i] <= req)
      continue;
    int ans = 0;
    ans += arr[i] / req;
    if (arr[i] % req == 0)
      ans--;
    moves += ans;
    if (moves > k)
      return 0;
  }
  return 1;
}
int32_t main() {
  IOS cin >> n >> k;
  for (int i = 0; i < n; i++)
    cin >> arr[i];
  int low = 1;
  int high = 2e9;
  while (low < high) {
    int mid = (low + high) / 2;
    if (!check(mid))
      low = mid + 1;
    else
      high = mid;
  }
  print(low);
}


Error: 0

Fixed submission:

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

template <typename T> void print(T t) { cout << t << endl; }
template <typename T, typename... Args> void print(T t, Args... args) {
  cout << t << " ";
  print(args...);
}

typedef complex<double> base;

#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define endl '\\n'
#define int long long
#define double long double

int n, k;
int arr[200005];
bool check(int req) {
  int moves = 0;
  for (int i = 0; i < n; i++) {
    if (arr[i] <= req)
      continue;
    int ans = 0;
    ans += arr[i] / req;
    if (arr[i] % req == 0)
      ans--;
    moves += ans;
    if (moves > k)
      return 0;
  }
  return 1;
}
int32_t main() {
  IOS cin >> n >> k;
  for (int i = 0; i < n; i++)
    cin >> arr[i];
  int low = 0;
  int high = 2e9;
  while (low < high) {
    int mid = (low + high) / 2;
    if (!check(mid))
      low = mid + 1;
    else
      high = mid;
  }
  print(low);
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define vii vector<ll>
#define pb push_back
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
using namespace std;
const int MOD = 1e9 + 7, N = 1e4 + 3;

int main() {
  fast;
  ll n, k;
  cin >> n >> k;
  ll a[n];
  for (int i = 0; i < n; ++i)
    cin >> a[i];
  ll low = 1, high = 1e9 + 5, ans;
  while (low <= high) {
    ll mid = (low + high) / 2, sum = 0;
    for (int i = 0; i < n; ++i) {
      ll g;
      if (a[i] < mid)
        continue;
      if (a[i] % mid == 0)
        g = a[i] / mid - 1;
      else
        g = a[i] / mid;
      sum += g;
    }
    if (sum > k)
      low = mid + 1;
    else if (sum <= k) {
      ans = mid;
      high = mid - 1;
    }
  }
  cout << ans;
  cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \\n";
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define vii vector<ll>
#define pb push_back
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
using namespace std;
const int MOD = 1e9 + 7, N = 1e4 + 3;

int main() {
  fast;
  ll n, k;
  cin >> n >> k;
  ll a[n];
  for (int i = 0; i < n; ++i)
    cin >> a[i];
  ll low = 0, high = 1e9 + 5, ans;
  while (low <= high) {
    ll mid = (low + high) / 2, sum = 0;
    for (int i = 0; i < n; ++i) {
      ll g;
      if (a[i] < mid)
        continue;
      if (a[i] % mid == 0)
        g = a[i] / mid - 1;
      else
        g = a[i] / mid;
      sum += g;
    }
    if (sum > k)
      low = mid + 1;
    else if (sum <= k) {
      ans = mid;
      high = mid - 1;
    }
  }
  cout << ans;
  cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \\n";
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define INIT                                                                   \\
  ios_base ::sync_with_stdio(false);                                           \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);                                                              \\
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define ll long long
#define pii pair<int, int>
#define count_bits __builtin_popcount
#define int ll

int t, n, m, k, a[300010], q, l, r;

int32_t main() {
  INIT cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }

  int l = 0, r = 1e9;
  while ((l + 1) < r) {
    int mid = (l + r) / 2;
    int cnt = 0;
    for (int i = 1; i <= n; i++) {
      if (a[i] % mid == 0) {
        cnt += (a[i] / mid) - 1;
      } else {
        cnt += a[i] / mid;
      }
    }
    if (cnt <= k) {
      r = mid;
    } else {
      l = mid;
    }
  }
  cout << r;

  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define INIT                                                                   \\
  ios_base ::sync_with_stdio(false);                                           \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);                                                              \\
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define ll long long
#define pii pair<int, int>
#define count_bits __builtin_popcount
#define int ll

int t, n, m, k, a[300010], q, l, r;
multiset<int> s;

int32_t main() {
  INIT cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    s.insert(a[i]);
  }
  int l = 0, r = ((int)1000000000), m = (l + r) / 2;

  while (l < r) {
    //  cout<<l<<" "<<r<<" ";
    m = (l + r) / 2;
    int k0 = k;
    int sz = (m);
    for (int i = 1; i <= n; i++) {
      if (((a[i]) % sz) == 0) {
        k0 -= max(((int)(a[i] / sz)) - 1, (int)0);
      } else {
        k0 -= max(((int)(a[i] / sz)), (int)0);
      }
    }

    if (k0 < 0) {
      l = m + 1;
    } else {
      r = m;
    }
    m = (l + r) / 2;
  }
  int k0 = k;
  int sz = m;
  for (int i = 1; i <= n; i++) {
    if (((a[i]) % sz) == 0) {
      k0 -= max(((int)(a[i] / sz)) - 1, (int)0);
    } else {
      k0 -= max(((int)(a[i] / sz)), (int)0);
    }
  }
  if (k0 < 0) {
    m++;
  }
  cout << (m);

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

#include <bits/stdc++.h>

using namespace std;
#define all(a) a.begin(), a.end()
using ll = long long;
const int INF = 1 << 30;
const ll INFll = 1LL << 62;
const int mod = int(1e9) + 7;
using P = pair<ll, ll>;
using ld = long double;

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

int main() {
  cin >> n >> k;
  a.resize(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  ll ok = 1e9;
  ll ng = 0;
  ll cnt = 0;
  while (cnt < 1000) {
    ll m = (ok + ng) / 2;
    if (ch(m))
      ok = m;
    else
      ng = m;
    cnt++;
  }
  cout << ok << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
#define all(a) a.begin(), a.end()
using ll = long long;
const int INF = 1 << 30;
const ll INFll = 1LL << 62;
const int mod = int(1e9) + 7;
using P = pair<ll, ll>;
using ld = long double;

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

int main() {
  cin >> n >> k;
  a.resize(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  ll ok = 1e9;
  ll ng = 0;
  ll cnt = 0;
  while (cnt < 1000) {
    ll m = (ok + ng) / 2;
    if (ch(m))
      ok = m;
    else
      ng = m;
    cnt++;
  }
  cout << ok << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

// Sky's the limit :)
#include <bits/stdc++.h>
using namespace std;
#define int long long

// Nice problem.. Started simulating the answer, whereas the correct answer was
// binary serch
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  int T = 1;
  // cin >> T;
  while (T--) {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (auto &&x : a)
      cin >> x;

    auto check = [&](int x) {
      int cnt = 0;
      for (int i = 0; i < n; i++) {
        if (x > 0)
          cnt += (a[i] - 1) / x;
        else
          cnt += a[i];
      }
      return cnt;
    };

    int lo = 0, hi = 1e10, lst = 1;
    while (lo <= hi) {
      int mid = (lo + hi) / 2;
      cerr << mid << ' ' << check(mid) << '\\n';
      if (check(mid) <= k) {
        lst = mid;
        hi = mid - 1;
      } else
        lo = mid + 1;
    }

    cout << max(lst, 1LL) << '\\n';
  }

  return 0;
}


Error: 0

Fixed submission:

// Sky's the limit :)
#include <bits/stdc++.h>
using namespace std;
#define int long long

// Nice problem.. Started simulating the answer, whereas the correct answer was
// via binary serch
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  int T = 1;
  // cin >> T;
  while (T--) {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (auto &&x : a)
      cin >> x;

    auto check = [&](int x) {
      int cnt = 0;
      for (int i = 0; i < n; i++) {
        cnt += (a[i] - 1) / x;
      }
      return cnt;
    };

    int lo = 0, hi = 1e10, lst = -1;
    while (lo <= hi) {
      int mid = (lo + hi) / 2;
      // cout << mid << ' ' << check(mid) << '\\n';
      if (check(mid) <= k) {
        lst = mid;
        hi = mid - 1;
      } else
        lo = mid + 1;
    }

    cout << lst << '\\n';
  }

  return 0;
}