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

#include <cmath>
#include <iostream>
#include <vector>
// #include<fstream>
// #include<iomanip>
using namespace std;

int main() {
  long long N, K, A;
  long long ans = 0, ans_1 = 0;
  long long champ = 0;
  double ok, ng, mid;
  long long tmp;
  long long sum = 0;
  std::cin >> N >> K;
  // ifstream ifs("./handmade11");
  // ifs >> N >> K;
  vector<long long> A_list(N);
  for (int i = 0; i < N; i++) {
    std::cin >> A;
    // ifs >> A;
    A_list[i] = A;
    sum = sum + A;
    if (A > champ) {
      champ = A;
    }
  }
  // ifs.close();

  if (sum <= K) {
    ans = 1;
    goto all_1;
  }
  // ここから二分探索
  ng = 0;
  ok = champ;

  while (ok - ng > 0.01) {
    mid = (ok + ng) / 2.0;
    // std::cout << std::setprecision(20) << ng << " " << ok << "\\n";
    tmp = 0;
    for (long long i = 0; i < N; i++) {
      tmp = tmp + ceil(A_list[i] / mid) - 1;
    }
    if (tmp <= K) {
      ok = mid;
    } else {
      ng = mid;
    }
  }

  ans = (long long)ceil(ok);
  ans_1 = ans - 1;
  tmp = 0;
  for (long long i = 0; i < N; i++) {
    // std::cout << A_list[i] << " " << ceil(A_list[i]/((double)ans_1)) << "\\n";
    tmp = tmp + round(ceil(A_list[i] / ((double)ans_1))) - 1;
  }
  if (tmp <= K) {
    // std::cout << "mmm";
    ans = ans_1;
  }
all_1:

  std::cout << ans;
}

Error: WA

Fixed submission:

#include <cmath>
#include <iostream>
#include <vector>
// #include<fstream>
// #include<iomanip>
using namespace std;

int main() {
  long long N, K, A;
  long long ans = 0;
  long long champ = 0;
  double ok, ng, mid;
  long long tmp;
  std::cin >> N >> K;
  // ifstream ifs("./handmade11");
  // ifs >> N >> K;
  vector<long long> A_list(N);
  for (int i = 0; i < N; i++) {
    std::cin >> A;
    // ifs >> A;
    A_list[i] = A;
    if (A > champ) {
      champ = A;
    }
  }
  // ifs.close();

  // ここから二分探索
  ng = 0;
  ok = champ;

  while (ok - ng > 0.01) {
    mid = (ok + ng) / 2.0;
    // std::cout << std::setprecision(20) << ng << " " << ok << "\\n";
    tmp = 0;
    for (long long i = 0; i < N; i++) {
      tmp = tmp + ceil(A_list[i] / mid) - 1;
    }
    if (tmp <= K) {
      ok = mid;
    } else {
      ng = mid;
    }
  }

  ans = (long long)ceil(ok);
  tmp = 0;
  for (long long i = 0; i < N; i++) {
    tmp = tmp + ceil(A_list[i] / (ans - 1)) - 1;
  }
  if (tmp <= K) {
    ans = ans - 1;
  }
  std::cout << ans;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define fo(i, a, b) for (int i = (a); i < (b); i++)
#define qi queue<int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int, int>
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
#define prq priority_queue
#define foreach(it, c)                                                         \\
  for (__typeof((c).begin()) it = c.begin(); it != c.end(); it++)
// #define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
inline ll read() {
  ll x = 0;
  int f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-')
      f = -f;
  for (; isdigit(c); c = getchar())
    x = x * 10 + (c - '0');
  return x * f;
}
inline void out(int x) {
  if (x >= 10)
    out(x / 10);
  putchar(x % 10 + '0');
}
int n, k, a[202020];
int main() {
  // freopen("a.in","r",stdin);
  // freopen("a.out","w",stdout);
  cin >> n >> k;
  fo(i, 0, n) cin >> a[i];
  int l = 0, r = 1e9 + 5;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (mid == 0)
      break;
    ll x = 0;
    fo(i, 0, n) x += (a[i] - 1) / mid;
    if (x > k)
      l = mid + 1;
    else
      r = mid - 1;
  }
  ll x = 0;
  if (l <= 1) {
    cout << "1\\n";
    return 0;
  }
  fo(i, 0, n) x += (a[i] - 1) / (l - 1);
  if (x <= k)
    cout << l - 1 << endl;
  else
    cout << l << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define fo(i, a, b) for (int i = (a); i < (b); i++)
#define qi queue<int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int, int>
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
#define prq priority_queue
#define foreach(it, c)                                                         \\
  for (__typeof((c).begin()) it = c.begin(); it != c.end(); it++)
// #define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
inline ll read() {
  ll x = 0;
  int f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-')
      f = -f;
  for (; isdigit(c); c = getchar())
    x = x * 10 + (c - '0');
  return x * f;
}
inline void out(int x) {
  if (x >= 10)
    out(x / 10);
  putchar(x % 10 + '0');
}
int n, k, a[202020];
int main() {
  // freopen("a.in","r",stdin);
  // freopen("a.out","w",stdout);
  cin >> n >> k;
  fo(i, 0, n) cin >> a[i];
  int l = 0, r = 1e9 + 5;
  while (l <= r) {
    int mid = (l + r) / 2;
    ll x = 0;
    fo(i, 0, n) x += (a[i] - 1) / mid;
    if (x > k)
      l = mid + 1;
    else
      r = mid - 1;
  }
  ll x = 0;
  if (l == 1) {
    cout << "1\\n";
    return 0;
  }
  fo(i, 0, n) x += (a[i] - 1) / (l - 1);
  if (x <= k)
    cout << l - 1 << endl;
  else
    cout << l << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
int n, k;
int a[N];

bool check(int mid) {
  int res = 0;
  for (int i = 0; i < n; i++)
    res += (a[i] - 1) / mid;
  return res <= k;
}

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

  int l = 1, r = 1e9;
  while (l < r) {
    int mid = l + r >> 1;
    if (check(mid))
      r = mid;
    else
      l = mid + 1;
  }

  cout << l;

  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
int n, k;
int a[N];

bool check(int mid) {
  LL res = 0;
  for (int i = 0; i < n; i++)
    res += (a[i] - 1) / mid;
  return res <= k;
}

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

  int l = 0, r = 1e9;
  while (l < r) {
    int mid = l + r >> 1;
    if (check(mid))
      r = mid;
    else
      l = mid + 1;
  }

  cout << l;

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

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
using ll = long long;
const int INF = (1 << 30) - 1;
const long long LINF = (1LL << 62) - 1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

using T = tuple<double, int, int>;

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int l = 0, r = INF;
  while (r - l > 1) {
    int mid = (l + r) / 2;
    ll num = 0;
    rep(i, n) num += (a[i] + mid - 1) / mid - 1;
    if (num <= k)
      r = mid;
    else
      l = mid;
  }
  cout << r << endl;
  return 0;
}

Error: TLE

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;
const int INF = (1 << 30) - 1;
const long long LINF = (1LL << 62) - 1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

using T = tuple<double, int, int>;

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  priority_queue<T> que;
  rep(i, n) que.emplace(a[i], a[i], 1);
  rep(i, k) {
    double tmp;
    int num, div;
    tie(tmp, num, div) = que.top();
    que.pop();
    div++;
    que.emplace(1.0 * num / div, num, div);
  }
  int ans = 0;
  rep(i, n) {
    double tmp;
    int num, div;
    tie(tmp, num, div) = que.top();
    que.pop();
    chmax(ans, (num + div - 1) / div);
  }
  cout << ans << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#define exp 1e-6
using namespace std;
const int maxn = 2e5 + 10;
int a[maxn];
int n, k;
bool check(int x) {
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] > x && x) {
      cnt += a[i] / x;
    }
    if (cnt > k)
      return false;
  }
  return true;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  int l = 1, r = 0, ans = 0;
  for (int i = 1; i <= n; i++)
    cin >> a[i], r = max(r, a[i]);
  ans = r;
  if (k == 0 || r == 1) {
    cout << ans << endl;
    return 0;
  }
  while (l <= r) {
    int mid = (l + r) >> 1;
    // cout<<mid<<endl;
    if (check(mid))
      ans = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
#define exp 1e-6
using namespace std;
const int maxn = 2e5 + 10;
int a[maxn];
int n, k;
bool check(int x) {
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] > x) {
      cnt += a[i] / x;
    }
    if (cnt > k)
      return false;
  }
  return true;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  int l = 0, r = 0, ans = 0;
  for (int i = 1; i <= n; i++)
    cin >> a[i], r = max(r, a[i]);
  ans = r;
  while (l <= r) {
    int mid = (l + r) >> 1;
    // cout<<mid<<endl;
    if (check(mid))
      ans = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  cout << ans << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

// Bismillahir Rahmanir Rahim .Ya Allah...
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> PII;
const int mod = 1e9 + 7, INF = 1e9;
const int mx = 2e5 + 5;
vector<ll> v(mx);
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ll n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++)
    cin >> v[i];
  ll lb = 1, rb = 1e9 + 7;
  while (lb < rb) {
    ll mid = (lb + rb) / 2;
    ll ans = 0;
    for (int i = 0; i < n; i++)
      ans = ans + (v[i] + mid - 1) / mid - 1;
    if (ans <= k)
      rb = mid;
    else
      lb = mid + 1;
  }
  cout << rb << endl;
  return 0;
}


Error: 0

Fixed submission:

// Bismillahir Rahmanir Rahim .Ya Allah...
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> PII;
const int mod = 1e9 + 7, INF = 1e9;
const int mx = 2e5 + 5;
vector<ll> v(mx);
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ll n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++)
    cin >> v[i];
  ll lb = 0, rb = 1e9 + 7;
  while (lb < rb) {
    ll mid = (lb + rb) / 2;
    ll ans = 0;
    for (int i = 0; i < n; i++)
      ans = ans + (v[i] + mid - 1) / mid - 1;
    if (ans <= k)
      rb = mid;
    else
      lb = mid + 1;
  }
  cout << rb << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

const int MAX_N = 200005;
int N, K;
int logs[MAX_N];

bool check(int maxlen) {
  if (maxlen == 0)
    return false;
  int k = 0;
  for (int i = N - 1; i >= 0; --i) {
    int log = logs[i];
    if (log <= maxlen)
      continue;
    k += log / maxlen;
    if (k > K)
      return false;
  }
  return true;
}

int main() {
  scanf("%d %d", &N, &K);
  int mm = 0;

  for (int i = 0; i < N; ++i) {
    scanf("%d", logs + i);
    mm = std::max(mm, logs[i]);
  }
  std::sort(logs, logs + N);

  long long hi = 1ll << 31;
  long long lo = 0;
  while (hi - lo > 1) {
    long long mid = (hi + lo) / 2;
    if (check(mid)) {
      hi = mid;
    } else {
      lo = mid;
    }
  }
  if (check(lo))
    printf("%lld\\n", lo);
  else
    printf("%lld\\n", hi);
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

const int MAX_N = 200005;
int N, K;
int logs[MAX_N];
std::multiset<int> llcp;

bool check(int maxlen) {
  if (maxlen == 0)
    return false;
  std::multiset<int> ll = llcp;
  int i = 0;
  while (!ll.empty()) {
    int log = -*ll.begin();
    ll.erase(ll.begin());
    if (log <= maxlen)
      return true;
    ll.insert(log % maxlen);
    i += log / maxlen;

    if (i > K)
      return false;
    if (-*ll.begin() <= maxlen)
      return true;
  }
  return true;
}

int main() {
  scanf("%d %d", &N, &K);
  int mm = 0;

  for (int i = 0; i < N; ++i) {
    scanf("%d", logs + i);
    mm = std::max(mm, logs[i]);
  }
  for (int i = 0; i < N; ++i)
    llcp.insert(-logs[i]);

  long long hi = 1ll << 31;
  long long lo = 0;
  while (hi - lo > 1) {
    long long mid = (hi + lo) / 2;
    if (check(mid)) {
      hi = mid;
    } else {
      lo = mid;
    }
  }
  if (check(lo))
    printf("%lld\\n", lo);
  else
    printf("%lld\\n", hi);
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define ENDL '\\n'
#define all(a) begin(a), end(a)
#define sz(a) (int)(a.size())
#define deb(a) cout << #a << ": " << a << ENDL;
#define fore(i, a, b) for (int i(a), ThkMk(b); i < ThkMk; ++i)
#define _                                                                      \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);

using namespace std;

typedef long long lli;
typedef long double ld;
typedef pair<lli, lli> ii;
typedef vector<lli> vi;

vector<lli> v;
lli k;

bool ok(lli u) {
  lli cnt = 0;
  for (auto it : v) {
    if (it <= u)
      continue;
    cnt += (it % u == 0 ? (it / u) - 1LL : (it - it % u) / u);
  }
  return cnt <= k;
}

int main() {
  _ lli n;
  cin >> n >> k;
  v.resize(n);
  fore(i, 0, n) cin >> v[i];
  lli x = 1;
  for (lli i = 1e9; i > 0; i /= 2LL)
    while (!ok(x + i))
      x += i;
  while (!ok(x))
    ++x;
  cout << x << ENDL;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define ENDL '\\n'
#define all(a) begin(a), end(a)
#define sz(a) (int)(a.size())
#define deb(a) cout << #a << ": " << a << ENDL;
#define fore(i, a, b) for (int i(a), ThkMk(b); i < ThkMk; ++i)
#define _                                                                      \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);

using namespace std;

typedef long long lli;
typedef long double ld;
typedef pair<lli, lli> ii;
typedef vector<lli> vi;

vector<lli> v;
lli k;

bool ok(lli u) {
  lli cnt = 0;
  for (auto it : v) {
    if (it <= u)
      continue;
    cnt += (it % u == 0 ? (it / u) - 1 : (it - it % u) / u);
  }
  return cnt <= k;
}

int main() {
  _ lli n;
  cin >> n >> k;
  v.resize(n);
  fore(i, 0, n) cin >> v[i];
  lli x = 0;
  for (lli i = 1e9; i > 0; i /= 2LL)
    while (!ok(x + i))
      x += i;
  while (!ok(x))
    ++x;
  cout << x << ENDL;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

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

int n, k, a[200010];

signed main() {
  ios::sync_with_stdio(false);
  cin >> n >> k;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  int l = 1, r = 1000000000, ans = -1;
  while (l <= r) {
    int mid = (l + r) / 2;
    int cnt = 0ll;
    for (int i = 1; i <= n; i++)
      cnt += (a[i] - 1) / mid;
    if (cnt <= k) {
      ans = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

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

int n, k, a[200010];

signed main() {
  ios::sync_with_stdio(false);
  cin >> n >> k;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  int l = 0, r = 1000000000, ans = -1;
  while (l <= r) {
    int mid = (l + r) / 2;
    int cnt = 0ll;
    for (int i = 1; i <= n; i++)
      cnt += (a[i] - 1) / mid;
    if (cnt <= k) {
      ans = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  cout << ans << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

using llong = long long int;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const static int MOD = 1000000007;
const static int INF = 1000000000;
const static int dx[4] = {1, 0, -1, 0};
const static int dy[4] = {0, 1, 0, -1};

int main(int argc, char *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n, k;
  cin >> n >> k;
  vector<int> logs(n);
  rep(i, n) cin >> logs[i];

  int left = 0, right = INF, mid;
  while (right - left > 1) {
    mid = left + (right - left) / 2;
    int cut = 0;
    rep(i, n) {
      if (cut > k)
        break;
      cut += (logs[i] + mid - 1) / mid - 1;
    }
    if (cut <= k)
      right = mid;
    else
      left = mid;
  }

  cout << right << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

using llong = long long int;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const static int MOD = 1000000007;
const static int INF = 1000000000;
const static int dx[4] = {1, 0, -1, 0};
const static int dy[4] = {0, 1, 0, -1};

int main(int argc, char *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n, k;
  cin >> n >> k;
  vector<int> logs(n);
  rep(i, n) cin >> logs[i];

  int left = -1, right = INF, mid;
  while (right - left > 1) {
    mid = left + (right - left) / 2;
    int cut = 0;
    rep(i, n) {
      if (cut > k)
        break;
      cut += (logs[i] + mid - 1) / mid - 1;
    }
    if (cut <= k)
      right = mid;
    else
      left = mid;
  }

  cout << right << endl;

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
#define Rep(i, n) for (int i = 1; i <= n; i++)
const ll MOD = 1000000007;
long long modinv(long long a, long long m = MOD) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0)
    u += m;
  return u;
  /*MODの割り算の際に
  a/＝b;
  を
  a *= modinv(b,MOD);
  とする。
      */
}

const int MAXN = 200000;
int K, N;
int A[MAXN];
bool ok(double mid) {
  int count = 0;
  rep(i, N) {
    count += (int)(A[i] / mid);
    if ((double)(A[i] / mid) != (int)(A[i] / mid)) {
      count++;
    }
    count--;
  }
  return (count <= K);
}

int up(double x) {
  if (x == int(x))
    return (int)x;
  else
    return int(x) + 1;
}

int main() {
  cin >> N >> K;
  rep(i, N) cin >> A[i];
  long double mini, maxi, mid;
  mini = 0;
  maxi = 10000000000;
  while (1) {
    mid = (mini + maxi) / 2;
    if (ok(mid)) {
      maxi = mid;
    } else {
      mini = mid;
    }
    if (abs(maxi - mini) < 0.000001)
      break;
  }

  if (maxi > 1000000000)
    cout << 1000000000 << endl;
  else
    cout << up(mini) << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
#define Rep(i, n) for (int i = 1; i <= n; i++)
const ll MOD = 1000000007;
long long modinv(long long a, long long m = MOD) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0)
    u += m;
  return u;
  /*MODの割り算の際に
  a/＝b;
  を
  a *= modinv(b,MOD);
  とする。
      */
}

const int MAXN = 200000;
int K, N;
int A[MAXN];
bool ok(double mid) {
  int count = 0;
  rep(i, N) {
    count += (int)(A[i] / mid);
    if ((double)(A[i] / mid) != (int)(A[i] / mid)) {
      count++;
    }
    count--;
  }
  return (count <= K);
}

int up(double x) {
  if (x == int(x))
    return (int)x;
  else
    return int(x) + 1;
}

int main() {
  cin >> N >> K;
  rep(i, N) cin >> A[i];
  long double mini, maxi, mid;
  mini = 0;
  maxi = LDBL_MAX;

  while (1) {
    mid = (mini + maxi) / 2;
    if (ok(mid)) {
      maxi = mid;
    } else {
      mini = mid;
    }
    if (abs(maxi - mini) < 1)
      break;
  }

  cout << up(mid) << endl;

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
const int maxn = 3e5 + 50;
const int inf = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int HASH = 131;

int a[maxn];
int n, k;

bool jungle(int mid) {
  if (mid == 0)
    return false;
  int ti = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] < mid)
      continue;
    ti += a[i] / mid - 1;
    if (a[i] % mid > 0)
      ti++;
    if (ti > k)
      return false;
  }
  return true;
}

int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  sort(a + 1, a + 1 + n);
  int r = a[n];
  int l = 0;
  int mid;
  int ans = 0;
  while (l <= r) {
    mid = (l + r) >> 1;
    if (!jungle(mid)) {
      l = mid + 1;
    } else {
      r = mid - 1;
      ans = mid;
    }
  }
  printf("%d\\n", ans);
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
const int maxn = 3e5 + 50;
const int inf = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int HASH = 131;

int a[maxn];
int n, k;

bool jungle(int mid) {
  int ti = 0;
  stack<int> st;
  for (int i = 1; i <= n; i++) {
    st.push(a[i]);
  }
  while (!st.empty()) {
    int tmp = st.top();
    st.pop();
    if (tmp < mid)
      continue;
    ti += tmp / mid - 1;
    if (tmp % mid > 0)
      ti++;
    if (ti > k)
      return false;
  }
  return true;
}

int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  sort(a + 1, a + 1 + n);
  int r = a[n];
  int l = 0;
  int mid;
  int ans = 0;
  while (l <= r) {
    mid = (l + r) >> 1;
    if (!jungle(mid)) {
      l = mid + 1;
    } else {
      r = mid - 1;
      ans = mid;
    }
  }
  printf("%d\\n", ans);
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define M 1000000007
typedef long long int ll;

void solve() {

  ll n, k, arr[200005], cnt, s, e, m;
  cin >> n >> k;
  for (ll i = 0; i < n; i++) {
    cin >> arr[i];
    e = max(e, arr[i]);
  }
  s = 1;
  while (s < e) {
    m = (s + e) / 2;
    cnt = 0;
    for (ll i = 0; i < n; i++) {
      cnt += (arr[i] / m) + ll(((arr[i] % m) > 0)) - 1;
    }
    if (cnt <= k)
      e = m;
    else
      s = m + 1;
  }
  cout << e << endl;
}

int main() {

  int t;
  // cin >> t;
  t = 1;
  for (int q = 0; q < t; q++) {
    solve();
  }

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define M 1000000007
typedef long long int ll;

void solve() {

  ll n, k, arr[200005], cnt;
  cin >> n >> k;
  for (int i = 0; i < n; i++)
    cin >> arr[i];
  ll s = 0, e = 1000000002, m;
  while (s < e) {
    m = (s + e) / 2;
    cnt = 0;
    for (int i = 0; i < n; i++) {
      cnt += (arr[i] / m + (arr[i] % m > 0)) - 1;
    }
    if (cnt <= k)
      e = m;
    else
      s = m + 1;
  }
  cout << e << endl;
}

int main() {

  int t;
  // cin >> t;
  t = 1;
  for (int q = 0; q < t; q++) {
    solve();
  }

  return 0;
}