alexjercan/bugnet huggingface dataset:
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

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

ll a[200000];

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


Error: TLE

Fixed submission:

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

struct logs {
  ll raw_length;
  ll separate;
};

int main() {
  int n, k;
  cin >> n >> k;
  // 1本当たりの長さ (raw_length / separate) が長いほうが長い、という順序
  auto cmp = [](logs a, logs b) {
    return a.raw_length * b.separate < a.separate * b.raw_length;
  };
  priority_queue<logs, vector<logs>, decltype(cmp)> pq(cmp);
  for (int i = 0; i < n; ++i) {
    ll a;
    cin >> a;
    pq.push(logs{a, 1});
  }
  for (int i = 0; i < k; ++i) {
    auto lg = pq.top();
    pq.pop();
    pq.push(logs{lg.raw_length, lg.separate + 1});
  }
  ll ans = 0;
  while (!pq.empty()) {
    auto lg = pq.top();
    pq.pop();
    ans = max(ans, (lg.raw_length + lg.separate - 1) / lg.separate);
  }
  cout << ans;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <assert.h>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
const double eps = 1e-2;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  ll k;
  cin >> k;
  vector<ll> A(n);
  for (int i = 0; i < n; i++)
    cin >> A[i];

  double r = 1.0 * (*max_element(begin(A), end(A))), l = 0;
  while (r - l > eps) {
    double mid = (r + l) / 2;
    bool flag = 1;
    ll div = 0;
    for (int i = 0; i < n; i++)
      if (1.0 * A[i] - mid > eps) {
        div += (ceil(1.0 * A[i] / mid) - 1);
        if (div > k) {
          flag = 0;
          break;
        }
      }
    if (flag)
      r = mid;
    else
      l = mid;
  }

  ll ans = 1ll * ceil(r);
  cout << ans << '\\n';

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <assert.h>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  ll k;
  cin >> k;
  vector<ll> A(n);
  for (int i = 0; i < n; i++)
    cin >> A[i];

  double r = 1.0 * (*max_element(begin(A), end(A))), l = 0;
  while (r - l > 1e-10) {
    double mid = (r + l) / 2;
    bool flag = 1;
    ll div = 0;
    for (int i = 0; i < n; i++)
      if (1.0 * A[i] > mid) {
        div += (ceil(1.0 * A[i] / mid) - 1);
        if (div > k) {
          flag = 0;
          break;
        }
      }
    if (flag)
      r = mid;
    else
      l = mid;
  }

  ll ans = 1ll * ceil(r);
  cout << ans << '\\n';

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

using namespace std;
#include <bits/stdc++.h>
#define frr(i, r, l) for (int i = r; i >= l; --i)
#define fr(i, l, r) for (int i = l; i < r; ++i)
#define forit(it, type, var)                                                   \\
  for (type::iterator it = var.begin(); it != var.end(); it++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define MEMS(a, b) memset(a, b, sizeof(a))
#define fi first
#define se second
#define m_p make_pair
#define pb push_back
#define ll long long
#define ld long double
typedef pair<ll, ll> iPair;
priority_queue<ll, vector<ll>, greater<ll>> pq1, pq2;
#define maxN 1000000000000000000
ll power(ll a, ll b) {
  ll res = 1;
  while (b > 0) {
    res *= a;
    b--;
  }
  return res;
}
int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n, k, m, l, h, ar[200005], ans;
  cin >> n >> k;

  fr(i, 0, n) { cin >> ar[i]; }

  l = 0;
  h = 1000000000;
  while (l <= h) {
    m = (l + h) / 2;

    ll tot = 0, lng, cnt, j;
    fr(i, 0, n) {
      if (ar[i] > m && m != 0) {
        cnt = ar[i] / m;
        cnt -= 1;
        if (cnt * m != ar[i])
          cnt += 1;

        tot += cnt;
      }
    }
    if (m == 0)
      tot = maxN;

    if (tot > k) {
      l = m + 1;
    } else {
      ans = m;
      h = m - 1;
    }
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

using namespace std;
#include <bits/stdc++.h>
#define frr(i, r, l) for (int i = r; i >= l; --i)
#define fr(i, l, r) for (int i = l; i < r; ++i)
#define forit(it, type, var)                                                   \\
  for (type::iterator it = var.begin(); it != var.end(); it++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define MEMS(a, b) memset(a, b, sizeof(a))
#define fi first
#define se second
#define m_p make_pair
#define pb push_back
#define ll long long
#define ld long double
typedef pair<ll, ll> iPair;
priority_queue<ll, vector<ll>, greater<ll>> pq1, pq2;
#define maxN 1000000000000000000
ll power(ll a, ll b) {
  ll res = 1;
  while (b > 0) {
    res *= a;
    b--;
  }
  return res;
}
int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n, k, m, l, h, ar[200005], ans;
  cin >> n >> k;

  fr(i, 0, n) { cin >> ar[i]; }

  l = 0;
  h = 1000000000;
  while (l <= h) {
    m = (l + h) / 2;

    ll tot = 0, lng, cnt, j;
    fr(i, 0, n) {
      if (ar[i] > m) {
        cnt = ar[i] / m;
        cnt -= 1;
        if (cnt * m != ar[i])
          cnt += 1;

        tot += cnt;
      }
    }

    if (tot > k) {
      l = m + 1;
    } else {
      ans = m;
      h = m - 1;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000010;
constexpr ll INF = 2000000000000000000;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int, int> P;

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

ll mod(ll val) {
  ll res = val % MOD;
  if (res < 0) {
    res += MOD;
  }
  return res;
}

// N^P mod M（ただしM == -1の時はmodを取らない）
template <typename T> T RS(T N, T P, T M) {
  if (P == 0) {
    return 1;
  }
  if (P < 0) {
    return 0;
  }
  if (P % 2 == 0) {
    ll t = RS(N, P / 2, M);
    if (M == -1)
      return t * t;
    return t * t % M;
  }
  if (M == -1) {
    return N * RS(N, P - 1, M);
  }
  return N * RS(N, P - 1, M) % M;
}

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  int ng = 0;
  int ok = 1000000000;
  int mid;
  while (ok - ng > 1) {
    mid = (ng + ok) / 2;
    int cnt = 0;
    for (int j = 0; j < N; j++) {
      cnt += (vec.at(j) - 1) / mid;
    }
    if (cnt <= K) {
      ok = mid;
    } else {
      ng = mid;
    }
  }
  cout << ok << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000010;
constexpr ll INF = 2000000000000000000;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int, int> P;

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

ll mod(ll val) {
  ll res = val % MOD;
  if (res < 0) {
    res += MOD;
  }
  return res;
}

// N^P mod M（ただしM == -1の時はmodを取らない）
template <typename T> T RS(T N, T P, T M) {
  if (P == 0) {
    return 1;
  }
  if (P < 0) {
    return 0;
  }
  if (P % 2 == 0) {
    ll t = RS(N, P / 2, M);
    if (M == -1)
      return t * t;
    return t * t % M;
  }
  if (M == -1) {
    return N * RS(N, P - 1, M);
  }
  return N * RS(N, P - 1, M) % M;
}

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  int ng = 0;
  int ok = 1000000000;
  int mid;
  for (int i = 0; i < 100; i++) {
    mid = (ng + ok) / 2;
    int cnt = 0;
    for (int j = 0; j < N; j++) {
      cnt += (vec.at(j) - 1) / mid;
    }
    if (cnt <= K) {
      ok = mid;
    } else {
      ng = mid;
    }
  }
  cout << ok << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

/*
    Author : zzugzx
    Lang : C++
    Blog : blog.csdn.net/qq_43756519
*/
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define endl '\\n'
#define SZ(x) (int)x.size()
#define mem(a, b) memset(a, b, sizeof(a))

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

const int mod = 1e9 + 7;
// const int mod = 998244353;
const double eps = 1e-6;
const double pi = acos(-1.0);
const int maxn = 2e6 + 10;
const int N = 2e4 + 5;
const ll inf = 0x3f3f3f3f;
const int dir[][2] = {{0, 1}, {1, 0},  {0, -1}, {-1, 0},
                      {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};
int a[maxn], k, n;
bool ok(int x) {
  int res = 0;
  for (int i = 1; i <= n; i++) {
    res += max(0, (int)(ceil(1.0 * a[i] / x) - 1));
  }
  return res <= k;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  //  freopen("in.txt", "r", stdin);
  //  freopen("out.txt", "w", stdout);
  cin >> n >> k;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  int l = 1, r = inf, ans = 0;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (ok(mid))
      r = mid - 1, ans = mid;
    else
      l = mid + 1;
  }
  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

/*
    Author : zzugzx
    Lang : C++
    Blog : blog.csdn.net/qq_43756519
*/
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define endl '\\n'
#define SZ(x) (int)x.size()
#define mem(a, b) memset(a, b, sizeof(a))

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

const int mod = 1e9 + 7;
// const int mod = 998244353;
const double eps = 1e-6;
const double pi = acos(-1.0);
const int maxn = 2e6 + 10;
const int N = 2e4 + 5;
const ll inf = 0x3f3f3f3f;
const int dir[][2] = {{0, 1}, {1, 0},  {0, -1}, {-1, 0},
                      {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};
int a[maxn], k, n;
bool ok(int x) {
  int res = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] <= x)
      continue;
    res += a[i] / x;
  }
  return res <= k;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  //  freopen("in.txt", "r", stdin);
  //  freopen("out.txt", "w", stdout);
  cin >> n >> k;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  int l = 0, r = 1e9, ans;
  while (l <= r) {
    int mid = l + r >> 1;
    if (ok(mid))
      r = mid - 1, ans = mid;
    else
      l = mid + 1;
  }
  cout << ans << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstring>
#include <deque>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
#define rep0(i, n) for (i = 0; i < n; i++)
#define rep(s, i, n) for (i = s; i < n; i++)
using namespace std;

int A[200000];
int i, j;
int N, K;

int main() {
  cin >> N >> K;
  rep0(i, N) cin >> A[i];

  int ng = 0, ok = 1e9 + 1;
  while (ok - ng > 1) {
    int m = (ok + ng) / 2;
    int cnt = 0;
    rep0(i, N) { cnt += (A[i] + m - 1) / m - 1; }
    if (cnt <= K)
      ok = m;
    else
      ng = m;
  }
  cout << ok << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstring>
#include <deque>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
#define rep0(i, n) for (i = 0; i < n; i++)
#define rep(s, i, n) for (i = s; i < n; i++)
using namespace std;

int A[200000];

int main() {
  int i, j;
  int N, K;
  cin >> N >> K;

  int a;
  rep0(i, N) {
    cin >> a;
    A[i] = a;
  }

  int ans = 1;
  double tmp;
  while (true) {
    int count = 0;
    rep0(i, N) {
      j = 1;
      do {
        tmp = A[i];
        tmp /= (double)j;
        count++;
        ++j;
      } while (tmp > ans);
      count--;

      if (count > K)
        break;
    }
    if (count > K)
      ans++;
    else
      break;
  }

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

#include <bits/stdc++.h>
using namespace std;
vector<int> arr;
long long cut(int x) {
  long long ret = 0;
  for (int i = 0; i < arr.size(); i++) {
    if (arr[i] > x) {
      ret += arr[i] / x;
      if (arr[i] % x == 0)
        ret--;
    }
  }
  return ret;
}
int main() {
  int n, k;
  cin >> n >> k;
  arr = vector<int>(n);
  for (int i = 0; i < n; i++)
    cin >> arr[i];
  int start = 1;
  int fin = *max_element(arr.begin(), arr.end());
  while (start <= fin) {
    int mid = (start + fin) / 2;
    if (cut(mid) <= k)
      fin = mid - 1;
    else
      start = mid + 1;
  }
  cout << start;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
vector<int> arr;
long long cut(int x) {
  long long ret = 0;
  for (int i = 0; i < arr.size(); i++) {
    if (arr[i] > x) {
      ret += arr[i] / x;
      if (arr[i] % x == 0)
        ret--;
    }
  }
  return ret;
}
int main() {
  int n, k;
  cin >> n >> k;
  arr = vector<int>(n);
  for (int i = 0; i < n; i++)
    cin >> arr[i];
  int start = 1;
  int fin = *max_element(arr.begin(), arr.end());
  while (start < fin) {
    int mid = (start + fin) / 2;
    if (cut(mid) <= k)
      fin = mid - 1;
    else
      start = mid + 1;
  }
  if (cut(fin) <= k)
    cout << fin;
  else
    cout << fin + 1;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

// #include<i_am_noob_orz>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define ull unsigned long long
#define pii pair<int, int>
#define X first
#define Y second
#define mod ((ll)1e9 + 7)
#define pb push_back
#define mp make_pair
#define abs(x) ((x) > 0 ? (x) : (-(x)))
#define F(n) Fi(i, n)
#define Fi(i, n) Fl(i, 0, n)
#define Fl(i, l, n) for (int i = l; i < n; i++)
#define memres(a) memset(a, 0, sizeof(a))
#define all(a) a.begin(), a.end()
#define sz(a) ((int)a.size())
#define ceiling(a, b) (((a) + (b)-1) / (b))
#define endl '\\n'
#define bit_count(x) __builtin_popcount((x))
#define ykh mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// #define LOCAL
#ifdef LOCAL
#define debug(a) cerr << #a << " " << a << endl;
#else
#define debug(a)
#endif
int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
int a[200010];
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  F(n) cin >> a[i];
  int l = 1, r = 1e9;
  while (l < r) {
    int mi = ((l + r) / 2);
    int s = 0;
    // cout<<l<<" "<<r<<endl;
    // cout<<mi<<endl;
    F(n) if (a[i] > mi) s += (ceiling(a[i], mi) - 1);
    // cout<<s<<" "<<m<<endl;
    if (s <= m)
      r = mi;
    else
      l = mi + 1;
  }
  cout << l << endl;
  return 0;
}


Error: 0

Fixed submission:

// #include<i_am_noob_orz>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define ull unsigned long long
#define pii pair<int, int>
#define X first
#define Y second
#define mod ((ll)1e9 + 7)
#define pb push_back
#define mp make_pair
#define abs(x) ((x) > 0 ? (x) : (-(x)))
#define F(n) Fi(i, n)
#define Fi(i, n) Fl(i, 0, n)
#define Fl(i, l, n) for (int i = l; i < n; i++)
#define memres(a) memset(a, 0, sizeof(a))
#define all(a) a.begin(), a.end()
#define sz(a) ((int)a.size())
#define ceiling(a, b) (((a) + (b)-1) / (b))
#define endl '\\n'
#define bit_count(x) __builtin_popcount((x))
#define ykh mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// #define LOCAL
#ifdef LOCAL
#define debug(a) cerr << #a << " " << a << endl;
#else
#define debug(a)
#endif
int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
int a[200010];
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  F(n) cin >> a[i];
  int l = 0, r = 1e9;
  while (l < r) {
    int mi = ((l + r) / 2);
    int s = 0;
    // cout<<l<<" "<<r<<endl;
    // cout<<mi<<endl;
    F(n) if (a[i] > mi) s += (ceiling(a[i], mi) - 1);
    // cout<<s<<" "<<m<<endl;
    if (s <= m)
      r = mi;
    else
      l = mi + 1;
  }
  cout << l << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int a[200010];
int ck(int x, int n) {
  int s = 0;
  for (int i = 0; i < n; i++) {
    s += (a[i] - 1) / x;
  }
  return s;
}
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]);
  int l = 1, r = 1e9, mid;
  while (l < r) {
    mid = l + r >> 1;
    if (ck(mid, n) <= k)
      r = mid;
    else
      l = mid + 1;
  }
  printf("%d", r);
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF = 0x3f3f3f3f;
const ll mod = 1e9 + 7;
const ll N = 2e5 + 5;

int n, k, a[N];

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

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  int L = 0, R = 1e9, mid;
  while (L < R) {
    mid = (L + R) / 2;
    if (check(mid))
      R = mid;
    else
      L = mid + 1;
  }
  cout << R << '\\n';
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

/*
h s, d't skp th si tll i's sved
 * ABC141 E
 * ABC145 D
 * ABC147 F
 * ABC174 F
*/
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
int main() {
  ll n, k;
  cin >> n >> k;
  ll a[n];
  ll l = 1, r = 0;
  ll ans = 0;
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
    r = max(r, a[i]);
  }
  ans = r;
  while (l <= r) {
    ll mid = l + (-l + r) / 2;
    ll c = 0;
    for (ll i = 0; i < n; i++) {
      ll h = a[i] / mid - 1;
      ll g = h;
      if (a[i] % mid != 0) {
        g++;
      }
      c += g;
    }
    if (c <= k) {
      ans = mid;
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  ll h = ans;
  cout << ans << endl;
}

/*
 * ||||


 */

Error: TLE

Fixed submission:

/*
h s, d't skp th si tll i's sved
 * ABC141 E
 * ABC145 D
 * ABC147 F
*/
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int a;
  priority_queue<double> pq;
  for (ll i = 0; i < n; i++) {
    cin >> a;
    pq.push(a);
  }
  unordered_map<double, vector<ll>> mp;
  unordered_map<double, int> ps;
  while (k > 0) {
    double d = pq.top();
    double h;
    if (!mp[d].empty() && ps[d] < mp[d].size()) {
      h = (double)d * (mp[d][ps[d]] + 1);
      k += mp[d][ps[d]];
      ps[d]++;
    } else {
      h = d;
    }
    pq.pop();
    double g = pq.top();
    ll x = h, y = g;
    ll f = x / y;
    if (x % y != 0) {
      f++;
    }
    if (k < f - 1) {
      pq.push((double)h / k);
      k = 0;
    } else {
      pq.push((double)h / f);
      mp[(double)h / f].push_back(f - 1);
      k -= f - 1;
    }
  }
  ll ans = pq.top();
  if (ans != pq.top()) {
    ans++;
  }
  cout << ans << endl;
}

/*
 * ||||


 */
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define rep(i, x, n) for (int i = x; i <= n; i++)
#define per(i, n, x) for (int i = n; i >= x; i--)
#define sz(a) int(a.size())
#define rson mid + 1, r, p << 1 | 1
#define pii pair<int, int>
#define lson l, mid, p << 1
#define ll long long
#define pb push_back
#define mp make_pair
#define se second
#define fi first
using namespace std;
const double eps = 1e-8;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;
const int inf = 1e9;
int n, k;
int a[N];
bool ck(int x) {
  int cnt = 0;
  rep(i, 1, n) {
    int y = a[i];
    cnt += (y - 1) / x;
    if (cnt > k)
      return false;
  }
  return cnt <= k;
}
int main() {
  ios::sync_with_stdio(false);
  // freopen("in","r",stdin);
  cin >> n >> k;
  rep(i, 1, n) { cin >> a[i]; }
  int l = 1, r = 1e9;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (ck(mid))
      r = mid - 1;
    else
      l = mid + 1;
  }
  printf("%d\\n", l);
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define rep(i, x, n) for (int i = x; i <= n; i++)
#define per(i, n, x) for (int i = n; i >= x; i--)
#define sz(a) int(a.size())
#define rson mid + 1, r, p << 1 | 1
#define pii pair<int, int>
#define lson l, mid, p << 1
#define ll long long
#define pb push_back
#define mp make_pair
#define se second
#define fi first
using namespace std;
const double eps = 1e-8;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;
const int inf = 1e9;
int n, k;
int a[N];
bool ck(int x) {
  int cnt = 0;
  rep(i, 1, n) {
    int y = a[i];
    cnt += (y - 1) / x;
    if (cnt > k)
      return false;
  }
  return cnt <= k;
}
int main() {
  ios::sync_with_stdio(false);
  // freopen("in","r",stdin);
  cin >> n >> k;
  rep(i, 1, n) { cin >> a[i]; }
  int l = 0, r = 1e9;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (ck(mid))
      r = mid - 1;
    else
      l = mid + 1;
  }
  printf("%d\\n", l);
  return 0;
}