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

#include <bits/stdc++.h>
using namespace std;
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define rep(i, n) repl(i, 0, n)
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18 + 10;
const int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);

  int n, k;
  cin >> n >> k;
  int a[n];
  rep(i, n) cin >> a[i];
  int l = 0, r = 1000000001;
  while (r - l > 1) {
    int m = (l + r) / 2;
    int cnt = 0;
    rep(i, n) cnt += (a[i] + m - 1) / m - 1;
    if (cnt <= k)
      r = m;
    else
      l = m;
  }
  cout << r << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define rep(i, n) repl(i, 0, n)
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18 + 10;
const int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);

  int n, k;
  cin >> n >> k;
  int a[n];
  rep(i, n) cin >> a[i];
  int l = 0, r = 1000000001;
  rep(i, 1000) {
    int m = (l + r) / 2;
    int cnt = 0;
    rep(j, n) cnt += (a[j] + m - 1) / m - 1;
    if (cnt <= 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;

#define all(x) (x).begin(), (x).end()

using ll = long long;
using P = pair<int, int>;
using mp = map<int, int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;

int main(void) {

  int n, k;
  cin >> n >> k;

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

  int left = 0, right = amax + 1, mid = 0;
  while (left + 1 < right) {
    mid = (left + right) / 2;

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

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

  cout << right << "\\n";

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(), (x).end()

using ll = long long;
using P = pair<int, int>;
using mp = map<int, int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;

int main(void) {

  int n, k;
  cin >> n >> k;

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

  int left = -1, right = amax + 1, mid = 0;
  while (left + 1 < right) {
    mid = (left + right) / 2;

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

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

  cout << right << "\\n";

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

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define ri register
#define inf 0x7fffffff
#define E (1)
#define mk make_pair
#define int long long
#define double long double
using namespace std;
const int N = 1000010;
inline int read() {
  int s = 0, w = 1;
  ri char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    s = (s << 3) + (s << 1) + (ch - '0'), ch = getchar();
  return s * w;
}
void print(int x) {
  if (x < 0)
    x = -x, putchar('-');
  if (x > 9)
    print(x / 10);
  putchar(x % 10 + '0');
}
int n, K, a[N];
inline int Check(int x) {
  int ans = 0;
  for (ri int i = 1; i <= n; i++)
    ans += (a[i] - 1) / x;
  return ans;
}
signed main() {
  n = read(), K = read();
  for (ri int i = 1; i <= n; i++)
    a[i] = read();
  sort(a + 1, a + 1 + n);
  if (K == 0) {
    printf("%lld\\n", a[n]);
    return 0;
  }
  int L = 1, R = 2e9;
  int res = 0;
  while (L <= R) {
    int mid = (L + R >> 1);
    if (Check(mid) <= K)
      res = mid, R = mid - 1;
    else
      L = mid + 1;
  }
  printf("%lld\\n", res);
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define ri register
#define inf 0x7fffffff
#define E (1)
#define mk make_pair
#define int long long
#define double long double
using namespace std;
const int N = 500010;
inline int read() {
  int s = 0, w = 1;
  ri char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    s = (s << 3) + (s << 1) + (ch - '0'), ch = getchar();
  return s * w;
}
void print(int x) {
  if (x < 0)
    x = -x, putchar('-');
  if (x > 9)
    print(x / 10);
  putchar(x % 10 + '0');
}
int n, K, a[N];
inline int Check(int x) {
  int ans = 0;
  for (ri int i = 1; i <= n; i++)
    ans += (a[i] - 1) / x;
  return ans;
}
signed main() {
  n = read(), K = read();
  for (ri int i = 1; i <= n; i++)
    a[i] = read();
  sort(a + 1, a + 1 + n);
  if (K == 0) {
    printf("%lld\\n", a[n]);
    return 0;
  }
  int L = 0, R = 2e9;
  int res = 0;
  while (L <= R) {
    int mid = (L + R >> 1);
    if (Check(mid) <= K)
      res = mid, R = mid - 1;
    else
      L = mid + 1;
  }
  printf("%lld\\n", res);
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vi vec(n);
  forn(i, n) { cin >> vec[i]; }
  sort(all(vec));
  reverse(all(vec));

  int l = 1;
  int r = vec[0] + 1;
  int ans = INT_MAX;
  while (l <= r) {
    int mid = (l + r) / 2;
    bool ok = true;
    int cnt = 0;

    forn(i, n) {
      if (vec[i] <= mid) {
        break;
      }
      cnt += vec[i] / mid;
      if (cnt > k) {
        ok = false;
        break;
      }
    }
    if (ok) {
      ans = min(mid, ans);
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  if (ans == INT_MAX) {
    ans = vec[0];
  }
  cout << ans;

  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vi vec(n);
  forn(i, n) { cin >> vec[i]; }
  sort(all(vec));
  reverse(all(vec));

  int l = 0;
  int r = vec[0] + 1;
  int ans = INT_MAX;
  while (l <= r) {
    int mid = (l + r) / 2;
    bool ok = true;
    int cnt = 0;

    forn(i, n) {
      if (vec[i] <= mid) {
        break;
      }
      cnt += vec[i] / mid;
      if (cnt > k) {
        ok = false;
        break;
      }
    }
    if (ok) {
      ans = min(mid, ans);
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  if (ans == INT_MAX) {
    ans = vec[0];
  }
  cout << ans;

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

// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 08/02/20 20:55:48
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int n, k;
  cin >> n >> k;
  vector<int> A(n);
  for (auto &a : A)
    cin >> a;
  auto ok = [&](double m) {
    int cnt = 0;
    for (double a : A) {
      cnt += ceil(a / m) - 1;
      if (cnt > k)
        return false;
    }
    return true;
  };
  double l = 0, r = 1e9 + 1;
  for (int i = 0; i < 80; i++) {
    auto c = (l + r) / 2;
    if (ok(c)) {
      r = c;
    } else {
      l = c;
    }
  }
  cout << (ll)ceil(r) << endl;

  return 0;
}


Error: TLE

Fixed submission:

// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 08/02/20 20:55:48
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int n, k;
  cin >> n >> k;
  struct Tree {
    int a, d;
    double len() const { return (double)a / d; }
    bool operator<(const Tree &r) const { return len() < r.len(); }
  };
  priority_queue<Tree> pq;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    pq.push({a, 1});
  }
  while (k--) {
    auto q = pq.top();
    pq.pop();
    q.d++;
    pq.push(q);
  }
  auto q = pq.top();
  if (q.a % q.d == 0) {
    cout << q.a / q.d << endl;
  } else {
    cout << q.a / q.d + 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++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1 << 30) - 1)
#define LINF (1LL << 60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

int n, k;
ll a[200010];

bool isOK(ll x) {
  ll cnt = 0;
  rep(i, n) cnt += (a[i] + x - 1) / x - 1;
  if (cnt <= k)
    return true;
  else
    return false;
}

ll binary_search(ll key) {
  ll ng = 0;
  ll ok = 1e+9 + 7;
  while (abs(ok - ng) > 1) {
    ll mid = (ok + ng) / 2;
    if (isOK(mid))
      ok = mid;
    else
      ng = mid;
  }
  return ok;
}

int main() {
  cin >> n >> k;
  rep(i, n) cin >> a[i];
  cout << binary_search(k) << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1 << 30) - 1)
#define LINF (1LL << 60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

int n, k;
ll a[200010];

bool isOK(ll x) {
  ll cnt = 0;
  rep(i, n) cnt += (a[i] + x - 1) / x - 1;
  if (cnt <= k)
    return true;
  else
    return false;
}

ll binary_search(ll key) {
  ll ng = -1;
  ll ok = 1e+9 + 7;
  while (abs(ok - ng) > 1) {
    ll mid = (ok + ng) / 2;
    if (isOK(mid))
      ok = mid;
    else
      ng = mid;
  }
  return ok;
}

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

  cout << binary_search(k) << endl;

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

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

bool go(vector<ll> &vec, ll n, ll mid, ll k) {
  ll p = 0;
  for (ll i = 1; i <= n; i++) {
    p += ceil((vec[i] - 1) / mid);
    if (p > k)
      return 0;
  }
  //	cout<<p<<endl;
  if (p > k)
    return 0;
  else
    return 1;
}
int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> vec(n + 1, 0);
  ll ans = 0;
  for (ll i = 1; i <= n; i++) {
    cin >> vec[i];
    ans = max(ans, vec[i]);
  }

  ll l = 1, r = ans;
  ll x = 500;
  while (l <= r && x > 0) {
    x--;
    ll mid = (l + r) / 2.0;
    //		cout<<(int)l<<" "<<(int)r<<endl;
    bool bb = go(vec, n, mid, k);
    if (bb == 1) {
      ans = min(ans, mid);
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  cout << (int)round(ans) << endl;
}


Error: 0

Fixed submission:

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

bool go(vector<ll> &vec, ll n, ll mid, ll k) {
  ll p = 0;
  for (ll i = 1; i <= n; i++) {
    p += ceil((vec[i]) / mid);
    if (p > k)
      return 0;
  }
  //	cout<<p<<endl;
  if (p > k)
    return 0;
  else
    return 1;
}
int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> vec(n + 1, 0);
  ll ans = 0;
  for (ll i = 1; i <= n; i++) {
    cin >> vec[i];
    ans = max(ans, vec[i]);
  }

  ll l = 0, r = ans;
  ll x = 500;
  while (l <= r && x > 0) {
    x--;
    ll mid = (l + r) / 2.0;
    //		cout<<(int)l<<" "<<(int)r<<endl;
    bool bb = go(vec, n, mid, k);
    if (bb == 1) {
      ans = min(ans, mid);
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  cout << (int)round(ans) << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll n, k;
ll a[200001];
bool check(ll x) {
  ll mov = 0;
  for (ll i = 0; i < n; i++) {
    mov += (a[i] - 1) / x;
  }
  if (mov <= k) {
    return true;
  }
  return false;
}
int main() {
  cin >> n >> k;
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
  }
  ll lp = 1;
  ll rp = 1000000000;
  ll mid;
  bool flag1 = true, flag2 = true;
  while (lp < rp) {
    flag1 = true, flag2 = true;
    mid = (lp + rp) / 2;
    if (check(mid)) {
      rp = mid;
    } else {
      lp = mid + 1;
    }
  }
  cout << lp << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll n, k;
ll a[200001];
bool check(ll x) {
  ll mov = 0;
  for (ll i = 0; i < n; i++) {
    mov += (a[i] - 1) / x;
  }
  if (mov <= k) {
    return true;
  }
  return false;
}
int main() {
  cin >> n >> k;
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
  }
  ll lp = 0;
  ll rp = 1000000000;
  ll mid;
  bool flag1 = true, flag2 = true;
  while (lp < rp) {
    flag1 = true, flag2 = true;
    mid = (lp + rp) / 2;
    if (check(mid)) {
      rp = mid;
    } else {
      lp = mid + 1;
    }
  }
  cout << lp << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pii pair<int, int>
#define pll pair<ll, l>
#define ull unsigned ll
#define mp make_pair
#define pb push_back

using namespace std;

ll n;
ll a[200001];
ll k;

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

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

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pii pair<int, int>
#define pll pair<ll, l>
#define ull unsigned ll
#define mp make_pair
#define pb push_back

using namespace std;

int n;
int a[200001];
int k;

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

int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  int ans;
  int l, r;
  l = 1, r = 1e9;
  while (l != r) {
    int m = (l + r) / 2;
    if (check(m))
      ans = m, r = m - 1;
    else
      l = m + 1;
  }
  cout << ans;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

typedef long long int li;
typedef long double ld;
typedef vector<li> vi;
typedef pair<li, li> pi;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define B begin()
#define E end()
#define f(i, l, r) for (li i = l; i <= r; ++i)
#define fr(i, l, r) for (li i = l; i >= r; --i)
#define u_map unordered_map
#define endl "\\n"
#define debug(x) cout << #x << " = " << x << endl;

li fastpow(li base, li exp, li M) {
  li res = 1;
  while (exp > 0) {
    if (exp & 1)
      res = (res * base) % M;

    base = (base * base) % M;
    exp >>= 1;
  }
  return res;
}

li n, k;

vi a;

bool check(li val) {
  li cnt = 0;

  f(i, 0, n - 1) { cnt += ((a[i] - 1) / val); }

  return cnt <= k;
}

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

  a.resize(n);

  // li a[n];

  li mx = 0;

  f(i, 0, n - 1) {
    cin >> a[i];
    mx = max(a[i], mx);
  }

  li l = 0, r = mx;

  while (l + 1 < r) {
    li md = (l + r) / 2;

    if (check(md)) {
      r = md;
    } else {
      l = md;
    }
  }

  cout << r << endl;
}

int main() {

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

  li t = 1;

  // cin>>t;

  while (t--) {
    solve();
  }

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long int li;
typedef long double ld;
typedef vector<li> vi;
typedef pair<li, li> pi;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define B begin()
#define E end()
#define f(i, l, r) for (li i = l; i <= r; ++i)
#define fr(i, l, r) for (li i = l; i >= r; --i)
#define u_map unordered_map
#define endl "\\n"
#define debug(x) cout << #x << " = " << x << endl;

li fastpow(li base, li exp, li M) {
  li res = 1;
  while (exp > 0) {
    if (exp & 1)
      res = (res * base) % M;

    base = (base * base) % M;
    exp >>= 1;
  }
  return res;
}

li n, k;

vi a;

bool check(li val) {
  li cnt = 0;

  f(i, 0, n - 1) { cnt += ((a[i] + val - 1) / val) - 1; }

  return cnt > k;
}

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

  a.resize(n);

  // li a[n];

  li mx = 0;

  f(i, 0, n - 1) {
    cin >> a[i];
    mx = max(a[i], mx);
  }

  li l = 0, r = mx;

  while (l < r) {
    li md = (l + r) / 2;

    if (check(md)) {
      l = md + 1;
    } else {
      r = md;
    }
  }

  cout << l << endl;
}

int main() {

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

  li t = 1;

  // cin>>t;

  while (t--) {
    solve();
  }

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

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

const int N = 2e5 + 5;
int n, m, a[N];

bool check(int x) {
  int y = m;
  for (int i = 1; i <= n; i++) {
    y -= (a[i] - 1) / x;
  }
  return y >= 0;
}

int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  sort(a + 1, a + n + 1);
  int l = 1, r = 1e9, ans = 0;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check(mid)) {
      ans = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  printf("%d\\n", ans);
  return 0;
}

Error: 0

Fixed submission:

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

const int N = 2e5 + 5;
int n, m, a[N];

bool check(int x) {
  int y = m;
  for (int i = 1; i <= n; i++) {
    y -= (a[i] - 1) / x;
  }
  return y >= 0;
}

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

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

#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int, int>>
#define vpll vector<pair<ll, ll>>
#define fr(i, k, n) for (int i = k; i < n; ++i)
#define fri(i, k, n) for (int i = k; i >= n; --i)
#define INF (int)1e9
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define all(arr) arr.begin(), arr.end()

void boost() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

const int N = 2e5 + 10;
ll n, k;
ll arr[N];

bool poss(ll val) {
  ll req = 0;
  fr(i, 0, n) {
    if (arr[i] <= val)
      continue;
    ll cnt = (arr[i] / val) + (arr[i] % val != 0);
    cnt--;
    req += cnt;
    if (req > k)
      return false;
  }
  if (req > k)
    return false;
  return true;
}

void solve() {
  cin >> n >> k;
  ll mx = 0;
  fr(i, 0, n) {
    cin >> arr[i];
    mx = max(mx, arr[i]);
  }
  if (k == 0) {
    cout << mx << endl;
    return;
  }
  ll l = 1, r = 1000000002;
  ll ans = mx;
  while (l <= r) {
    ll mid = (l + r) / 2LL;
    if (poss(mid)) {
      r = mid - 1;
      ans = mid;
    } else {
      l = mid + 1;
    }
  }
  cout << ans << endl;
  return;
}

int main() {
  boost();

  int tc = 1;
  // cin>>tc;
  while (tc--)
    solve();
  return 0;
}

Error: 0

Fixed submission:

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

#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int, int>>
#define vpll vector<pair<ll, ll>>
#define fr(i, k, n) for (int i = k; i < n; ++i)
#define fri(i, k, n) for (int i = k; i >= n; --i)
#define INF (int)1e9
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define all(arr) arr.begin(), arr.end()

void boost() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

const int N = 3e5 + 10;
ll n, k;
ll arr[N];

bool poss(ll val) {
  ll req = 0;
  fr(i, 0, n) {
    if (arr[i] <= val)
      continue;
    ll cnt = (arr[i] / val) + (arr[i] % val != 0);
    cnt--;
    req += cnt;
    if (req > k)
      return false;
  }
  if (req > k)
    return false;
  return true;
}

void solve() {
  cin >> n >> k;
  ll mx = 0;
  fr(i, 0, n) {
    cin >> arr[i];
    mx = max(mx, arr[i]);
  }
  if (k == 0) {
    cout << mx << endl;
    return;
  }
  ll l = 0, r = 1e9 + 2;
  ll ans = mx;
  while (l <= r) {
    ll mid = (l + r) / 2LL;
    if (poss(mid)) {
      r = mid - 1;
      ans = mid;
    } else {
      l = mid + 1;
    }
  }
  cout << ans << endl;
  return;
}

int main() {
  boost();

  int tc = 1;
  // cin>>tc;
  while (tc--)
    solve();
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

/**
 *    author:  souzai32
 *    created: 12.08.2020 15:37:08
 **/

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

int main() {

  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a.at(i);
  sort(a.begin(), a.end());

  int left = 1, right = a.at(n - 1), mid;
  int count;
  int ans = right;

  while (left < right) {
    mid = (left + right) / 2;
    count = 0;
    for (int i = 0; i < n; i++)
      count += (a.at(i) - 1) / mid;
    if (count <= k) {
      ans = min(mid, ans);
      right = mid;
    } else
      left = mid + 1;
  }

  cout << ans << endl;

  return 0;
}

Error: 0

Fixed submission:

/**
 *    author:  souzai32
 *    created: 12.08.2020 15:37:08
 **/

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

int main() {

  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a.at(i);
  sort(a.begin(), a.end());

  int front = 1, back = n;
  int l = a.at(n - 1) / 2, count;
  int ans = a.at(n - 1);

  while (1) {
    count = 0;
    rep(i, n) count += (a.at(i) - 1) / l;
    if (count <= k) {
      ans = l;
      back = l;
    } else
      front = l + 1;
    l = (front + back) / 2;
    if (front >= back)
      break;
  }

  cout << ans << endl;

  return 0;
}