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

#include <bits/stdc++.h>
#define MSET(x, y) memset(x, y, sizeof(x))
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SZ size()
#define M 100005
#define ll long long
#define ld long double
#define INF 1e18
#define endl "\\n"
#define fastio                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
using namespace std;
ll MOD = 1000000007;
string yes = "Yes\\n";
string no = "No\\n";

vector<ll> a;
ll k;

bool f(ll mid) {
  ll ans = 0;
  for (auto itr : a) {
    ans += (itr - 1) / mid;
  }
  if (ans > k)
    return true;
  else
    return false;
}

int32_t main() {
  fastio;
#ifndef ONLINE_JUDGE
  freopen("i.txt", "r", stdin);
  freopen("o.txt", "w", stdout);
#endif
  ll n;
  cin >> n >> k;
  for (ll i = 0; i < n; i++) {
    ll x;
    cin >> x;
    a.PB(x);
  }
  sort(a.begin(), a.end());
  ll lo = 1, hi = 1e9, ans = -1, mid;
  while (lo <= hi) {
    mid = (lo + hi) / 2;
    if (f(mid))
      ans = mid, lo = mid + 1;
    else
      hi = mid - 1;
  }
  if (ans == -1) {
    cout << 1 << endl;
    return 0;
  }
  cout << ans + 1 << endl;
}

Error: -6
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc


Fixed submission:

#include <bits/stdc++.h>
#define MSET(x, y) memset(x, y, sizeof(x))
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SZ size()
#define M 100005
#define ll long long
#define ld long double
#define INF 1e18
#define endl "\\n"
#define fastio                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
using namespace std;
ll MOD = 1000000007;
string yes = "Yes\\n";
string no = "No\\n";

vector<ll> a;
ll k;

bool f(ll mid) {
  ll ans = 0;
  for (auto itr : a) {
    ans += (itr - 1) / mid;
  }
  if (ans > k)
    return true;
  else
    return false;
}

int32_t main() {
  fastio;
#ifndef ONLINE_JUDGE
  freopen("i.txt", "r", stdin);
  freopen("o.txt", "w", stdout);
#endif
  ll n;
  cin >> n >> k;
  for (ll i = 0; i < n; i++) {
    ll x;
    cin >> x;
    a.PB(x);
  }
  sort(a.begin(), a.end());
  ll lo = 1, hi = 1e9, ans = -1, mid;
  while (lo <= hi) {
    mid = (lo + hi) / 2;
    if (f(mid))
      ans = mid, lo = mid + 1;
    else
      hi = mid - 1;
  }
  if (ans == -1) {
    ll a = 0;
    cout << 2 / a;
  }
  cout << ans + 1 << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

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

ll n, k, a[200001];

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

int main() {
  cin >> n >> k;
  ll sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  sort(a, a + n);
  ll beg = 1, en = 1e9;
  ll ans = a[n - 1];
  while (beg <= en) {
    ll mid = (beg + en) / 2;
    if (check(mid)) {
      en = mid - 1;
      ans = mid;
    } else {
      beg = mid + 1;
    }
  }
  cout << ans;
}


Error: WA

Fixed submission:

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

ll n, k, a[200001];

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

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

// #include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

// Some constants don't work
#ifndef INT_MAX
#define INT_MAX 2147483647
#endif
#ifndef INT_MIN
#define INT_MIN -2147483648
#endif
// short hand tricks
typedef long long ll;

using namespace std;

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  ll N, K;
  cin >> N >> K;
  vector<ll> logs(N);
  for (int i = 0; i < N; i++) {
    cin >> logs[i];
  }
  ll low = 1;
  ll high = 1e9;
  ll res = 1e9;
  while (low <= high) {
    ll mid = low + (high - low) / 2;
    // see if mid is a solution
    // count how many cuts to make each log <=mid
    ll kcuts = 0;
    for (ll log : logs) {
      if (log > mid) {
        kcuts += log / mid;
        if (log % mid == 0)
          kcuts--;
      }
    }
    if (kcuts <= K) {
      res = min(mid, res);
      high = mid - 1;
    } else {
      low = mid + 1;
    }
  }
  cout << res << "\\n";
  return 0;
}


Error: 0

Fixed submission:

// #include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

// Some constants don't work
#ifndef INT_MAX
#define INT_MAX 2147483647
#endif
#ifndef INT_MIN
#define INT_MIN -2147483648
#endif
// short hand tricks
typedef long long ll;

using namespace std;

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  ll N, K;
  cin >> N >> K;
  vector<ll> logs(N);
  for (int i = 0; i < N; i++) {
    cin >> logs[i];
  }
  ll low = 0;
  ll high = 1e9;
  ll res = 1e9;
  while (low <= high) {
    ll mid = low + (high - low) / 2;
    // see if mid is a solution
    // count how many cuts to make each log <=mid
    ll kcuts = 0;
    for (ll log : logs) {
      if (log > mid) {
        kcuts += log / mid;
        if (log % mid == 0)
          kcuts--;
      }
    }
    if (kcuts <= K) {
      res = min(mid, res);
      high = mid - 1;
    } else {
      low = mid + 1;
    }
  }
  cout << res << "\\n";
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 200010;

int n, a[N], k;

ll f(int x) {
  ll p = 0;
  for (int i = 1; i <= n; i++)
    p += (a[i] - 1) / x;
  return p;
}

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

  int l = 1, r = 1e9;
  while (l < r) {
    int m = l + r >> 1;
    if (f(m) > k)
      l = m + 1;
    else
      r = m;
  }
  cout << l << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

const int N = 100010;

int n, a[N], k;

int f(int x) {
  int p = 0;
  for (int i = 1; i <= n; i++)
    p += (a[i] - 1) / x;
  return p;
}

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

  int l = 1, r = 1e9;
  while (l < r) {
    int m = l + r >> 1;
    if (f(m) > k)
      l = m + 1;
    else
      r = m;
  }
  cout << l << endl;

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

#include <bits/stdc++.h>
#define nl '\\n'
#define dbg(a) cout << #a << "=" << a << endl
#define fast                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define ll long long
#define vl vector<ll>
#define pll pair<ll, ll>
#define ii pair<ll, ll>
#define vi vector<ll>
#define MX 600000
#define MXX 1000000000
using namespace std;

vl v;

ll cut(ll x) {
  ll ct = 0;
  for (int i = 0; i < v.size(); i++) {
    ct += (v[i] + x - 1) / x;
    ct--;
    // dbg(ct);
  }
  // dbg(ct);
  return ct;
}

void solve() {
  ll n, k;
  cin >> n >> k;
  v.clear();
  v.resize(n);
  // dbg(n);
  for (auto &it : v)
    cin >> it;
  sort(v.begin(), v.end());
  ll l = 1, r = v.back();
  while (l < r) {
    ll m = (l + r) / 2;
    // dbg(m);
    // dbg(cut(m));
    if (cut(m) <= k) {
      r = m;
    } else
      l = m + 1;
  }
  cout << l << endl;
}

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


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define nl '\\n'
#define dbg(a) cout << #a << "=" << a << endl
#define fast                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define ll long long
#define vl vector<ll>
#define pll pair<ll, ll>
#define ii pair<ll, ll>
#define vi vector<ll>
#define MX 600000
#define MXX 1000000000
using namespace std;

vl v;

ll cut(ll x) {
  ll ct = 0;
  for (int i = 0; i < v.size(); i++) {
    ct += (v[i] + x - 1) / x;
    ct--;
    // dbg(ct);
  }
  // dbg(ct);
  return ct;
}

void solve() {
  ll n, k;
  cin >> n >> k;
  v.clear();
  v.resize(n);
  // dbg(n);
  for (auto &it : v)
    cin >> it;
  sort(v.begin(), v.end());
  ll l = 0, r = v.back();
  while (l < r) {
    ll m = (l + r) / 2;
    // dbg(m);
    // dbg(cut(m));
    if (cut(m) <= k) {
      r = m;
    } else
      l = m + 1;
  }
  cout << l << endl;
}

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

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

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

const int mod =
    1000000007; // 出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60; // INF = 11

ll n, k;
ll a[200005];

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

int main() {
  cin >> n >> k;
  rep(i, n) cin >> a[i];
  ll ng = 0, ok = 10000000000;

  while (ok - ng > 1) {
    ll mid = (ok + ng) / 2;
    if (check(mid)) {
      ok = mid;
    } else {
      ng = mid;
    }
  }
  cout << ok << endl;
}

Error: 0

Fixed submission:

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

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

const int mod =
    1000000007; // 出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60; // INF = 11

ll n, k;
ll a[200005];

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

int main() {
  cin >> n >> k;
  ll ng = -1, ok = 1000000003;

  rep(i, n) {
    cin >> a[i];
    ok = max(ok, a[i]);
  }

  while (ok - ng > 1) {
    ll mid = (ok + ng) / 2;
    if (check(mid)) {
      ok = mid;
    } else {
      ng = mid;
    }
  }
  ll a = floor(ok), b = ceil(ok);
  if (check(ok)) {
    cout << a << endl;
  } else {
    cout << b << endl;
  }
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
#define mod 1000000007
#define string_mod 2549536629329_base_255
#define pb push_back
#define F first
#define S second
#define ff first
#define endl "\\n"
#define ss second
#define all(v) v.begin(), v.end()
template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int power(int x, unsigned int y, int p) {
  int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res % p;
}
void solve() {
  int n, k;
  cin >> n >> k;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int lo = 1, hi = 1e9;
  int ans = 0;
  while (lo <= hi) {
    int mid = lo + hi;
    mid /= 2;
    int re = 0;
    for (int i = 0; i < n; i++) {
      int f = a[i] + mid - 1;
      f /= mid;
      f--;
      re += f;
    }
    if (re <= k) {
      ans = mid;
      hi = mid - 1;
    } else {
      lo = mid + 1;
    }
  }
  cout << ans << endl;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int tc;
  tc = 1;
  // cin >> tc;
  while (tc--) {
    solve();
  }

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
#define mod 1000000007
#define string_mod 2549536629329_base_255
#define pb push_back
#define F first
#define S second
#define ff first
#define endl "\\n"
#define ss second
#define all(v) v.begin(), v.end()
template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int power(int x, unsigned int y, int p) {
  int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res % p;
}
void solve() {
  int n, k;
  cin >> n >> k;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int lo = 0, hi = 1e9;
  int ans = 0;
  while (lo <= hi) {
    int mid = lo + hi;
    mid /= 2;
    int re = 0;
    for (int i = 0; i < n; i++) {
      int f = a[i] + mid - 1;
      f /= mid;
      f--;
      re += f;
    }
    if (re <= k) {
      ans = mid;
      hi = mid - 1;
    } else {
      lo = mid + 1;
    }
  }
  cout << ans << endl;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int tc;
  tc = 1;
  // cin >> tc;
  while (tc--) {
    solve();
  }

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

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

const ll INF = 1E18 + 5;
const ll mod = 1E9 + 7;
ll n, k;
vector<ll> a(200001);
bool check(ll mid) {
  ll i, ans = 0;
  for (i = 0; i < n; i++) {
    ans = ans + (ll)((a[i] - 1) / mid);
  }
  if (ans <= k)
    return true;
  return false;
}

int main() {
  cin >> n >> k;
  ll i;
  for (i = 0; i < n; i++)
    cin >> a[i];
  ll start = 0, end = 2000000000, ans;
  while (start <= end) {
    ll mid = start + (end - start) / 2;
    if (mid == 0) {
      ans = 1;
      break;
    }
    if (check(mid)) {
      end = mid - 1;
      ans = mid;
    } else
      start = mid + 1;
  }
  cout << ans;
}


Error: WA

Fixed submission:

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

const ll INF = 1E18 + 5;
const ll mod = 1E9 + 7;
int n, k;
vector<int> a(200001);
bool check(int mid) {
  ll i, ans = 0;
  for (i = 0; i < n; i++) {
    ans = ans + (ll)((a[i] - 1) / mid);
  }
  if (ans <= k)
    return true;
  return false;
}

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e10;
int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  for (ll i = 0; i < n; ++i) {
    cin >> a[i];
  }
  ll r = INF, l = 0;
  ll res = 0;
  for (ll j = 0; j < 100; ++j) {
    if (r - l <= 1) {
      break;
    }
    ll mid = (r + l) / 2;

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

    if (sum > k) {
      l = mid;
    } else {
      r = mid;
    }
  }

  cout << r << endl;
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e10;
int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  for (ll i = 0; i < n; ++i) {
    cin >> a[i];
  }
  ll r = INF, l = 0;
  ll res = 0;
  for (ll j = 0; j < 100; ++j) {

    ll mid = (r + l) / 2;

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

    if (sum > k) {
      l = mid;
    } else {
      r = mid;
    }
    if (j == 99) {
      res = mid;
    }
  }

  cout << res << 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
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define pi 3.14159265358979323846
#define mod 1000000007
ll A[200009], k, a;
ll chk(ll x) {
  ll cnt = 0;
  if (x == 0)
    return false;
  for (ll c = 0; c < a; c++) {
    if (A[c] > x)
      cnt = cnt + (ll)(A[c] / x);
  }
  return (cnt <= k);
}
ll binser(ll l, ll r) {
  ll mid = ((l + r) / 2);
  if (l > r) {
    return mid;
  }
  if (chk(mid)) {
    return min(mid, binser(l, mid - 1));
  } else {
    return binser(mid + 1, r);
  }
}
int main() {
  IOS;
  ll b, c, d, e, l = 0, r, ans;
  cin >> a >> k;
  for (b = 0; b < a; b++)
    cin >> A[b];
  sort(A, A + a);
  r = A[a - 1];
  ans = binser(l, r);
  cout << ans + 1 << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define pi 3.14159265358979323846
#define mod 1000000007
ll A[200009], k, a;
ll chk(ll x) {
  ll cnt = 0;
  for (ll c = 0; c < a; c++) {
    if (A[c] > x)
      cnt = cnt + (ll)(A[c] / x);
  }
  return (cnt <= k);
}
ll binser(ll l, ll r) {
  ll mid = ((l + r) / 2);
  if (l >= r) {
    return mid;
  }
  if (chk(mid)) {
    return min(mid, binser(l, mid - 1));
  } else {
    return binser(mid + 1, r);
  }
}
int main() {
  IOS;
  ll b, c, d, e, l = 0, r, ans;
  cin >> a >> k;
  for (b = 0; b < a; b++)
    cin >> A[b];
  sort(A, A + a);
  r = A[a - 1];
  ans = binser(l, r);
  cout << ans + 1 << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

#define ll long long

using namespace std;

ll n, k;
vector<ll> v;

bool check(ll l) {
  ll cuts = 0;
  for (auto &x : v) {
    cuts += (x - 1) / l;
  }
  return cuts <= k;
}

void solve() {
  ll l = 1, r = 1000000000;
  cin >> n >> k;

  v.resize(n);
  for (int i = 0; i < n; ++i)
    cin >> v[i];

  if (check(1)) {
    cout << 1 << endl;
    return;
  }

  ll mid;
  while (l <= r) {
    mid = (l + r) / 2;

    if (!check(mid)) {
      if (check(mid + 1))
        break;
      l = mid;
    } else {
      r = mid;
    }

    if (l == r && l == 1 && check(1)) {
      cout << 1 << endl;
      return;
    }
  }

  cout << mid + 1 << endl;
}

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

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

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

  for (int i = 0; i < t; ++i) {
    solve();
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int n, k;
vector<int> v;

bool check(int l) {
  int cuts = 0;
  for (auto &x : v) {
    cuts += (x - 1) / l;
  }
  return cuts <= k;
}

void solve() {
  int l = 1, r = 1000000000;
  cin >> n >> k;

  v.resize(n);
  for (int i = 0; i < n; ++i)
    cin >> v[i];

  int mid;
  while (l <= r) {
    mid = (l + r) / 2;

    if (!check(mid)) {
      if (check(mid + 1))
        break;
      l = mid;
    } else {
      r = mid;
    }
  }

  cout << mid + 1 << endl;
}

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

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

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

  for (int i = 0; i < t; ++i) {
    solve();
  }

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

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

ll f(vector<ll> &a, double x) {
  int n = a.size();
  ll ret = 0LL;
  rep(i, n) ret += ll((a[i] * 1.0) / x);
  return ret;
}

ll roundup(double x) {
  if (ll(x) == x)
    return ll(x);
  return ll(x + 1.0);
}

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

  int n;
  ll k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  sort(a.begin(), a.end(), greater<ll>());

  long double left = 0, right = a[0], mid;

  while (abs(left - right) >= 1e-3) {
    mid = (left + right) / 2.0;
    if (f(a, mid) <= k)
      right = mid; // ok
    else
      left = mid; // false
  }

  cout << roundup(mid) << endl;
}

Error: TLE

Fixed submission:

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

ll f(vector<ll> &a, double x) {
  int n = a.size();
  ll ret = 0LL;
  rep(i, n) ret += ll((a[i] * 1.0) / x);
  return ret;
}

ll roundup(double x) {
  if (ll(x) == x)
    return ll(x);
  return ll(x + 1.0);
}

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

  int n;
  ll k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  sort(a.begin(), a.end(), greater<ll>());

  double left = 0, right = a[0], mid;

  while (abs(left - right) >= 1e-7) {
    mid = (left + right) / 2.0;
    if (f(a, mid) <= k)
      right = mid; // ok
    else
      left = mid; // false
  }

  cout << roundup(mid) << endl;
}
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;

int n, k;
int a[200200];

bool check(int now) {
  if (now == 0)
    return 0;
  int cnt = 0;
  rep(i, n) { cnt += ((a[i] - 1) / now); }
  return cnt <= k;
}

int main() {
  ios::sync_with_stdio(false);
  cin >> n >> k;
  rep(i, n) cin >> a[i];
  int lb = 0, ub = 1000000000;
  while (lb <= ub) {
    int mid = (lb + ub) >> 1;
    if (check(mid))
      ub = mid - 1;
    else
      lb = mid + 1;
  }
  cout << lb << 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;

int n, k;
int a[200200];

bool check(int now) {
  int cnt = 0;
  rep(i, n) { cnt += ((a[i] - 1) / now); }
  return cnt <= k;
}

int main() {
  ios::sync_with_stdio(false);
  cin >> n >> k;
  rep(i, n) cin >> a[i];
  int lb = 0, ub = 1000000000;
  while (lb <= ub) {
    int mid = (lb + ub) >> 1;
    if (check(mid))
      ub = mid - 1;
    else
      lb = mid + 1;
  }
  cout << lb << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string.h>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
const int mm = 2e5 + 100;
ll d[mm];
ll n, m;
ll check(double u) {
  int i;
  ll s = 0;
  double a;
  for (i = 0; i < n; i++) {
    a = d[i] / u;
    s += ceil(a) - 1;
  }
  if (s <= m)
    return 1;
  else
    return 0;
}
int main() {
  ll i, j, t, a, b, c, p, k, kk;
  cin >> n >> m;
  double l, r, mid;
  for (i = 0; i < n; i++) {
    scanf("%lld", &d[i]);
  }
  l = 0;
  r = 1000000000 + 5.0;
  while (l + 1e-6 <= r) {
    mid = (l + r) / 2;
    if (check(mid))
      r = mid;
    else
      l = mid;
  }
  cout << (ll)ceil(l) << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string.h>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
const int mm = 2e5 + 100;
ll d[mm];
ll n, m;
ll check(double u) {
  int i;
  ll s = 0;
  double a;
  for (i = 0; i < n; i++) {
    a = d[i] / u;
    s += ceil(a) - 1;
  }
  if (s <= m)
    return 1;
  else
    return 0;
}
int main() {
  ll i, j, t, a, b, c, p, k, kk;
  cin >> n >> m;
  double l, r, mid;
  for (i = 0; i < n; i++) {
    scanf("%lld", &d[i]);
  }
  l = 0;
  r = 1000000000 + 5.0;
  while (l + 1e-7 <= r) {
    mid = (l + r) / 2;
    if (check(mid))
      r = mid;
    else
      l = mid;
  }
  cout << (ll)ceil(l) << endl;
}