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

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define ff(i, n) for (i = 0; i < n; i++)
int main() {
  ll t;
  t = 1;
  for (ll test = 1; test <= t; test++) {
    ll i, j, n, k, p, f, ans = -1;
    cin >> n >> k;
    ll brr[n], l = 1, r = 0;
    ff(i, n) {
      cin >> brr[i];
      r += brr[i];
    }
    while (l <= r) {
      ll mid = (l + r) / 2;
      ll c = 0;
      if (mid == 0) {
        break;
      }
      ff(i, n) {
        if (brr[i] % mid == 0)
          c += brr[i] / mid - 1;
        else
          c += brr[i] / mid;
      }
      if (c <= k) {
        ans = mid;
        r = mid - 1;
      } else {
        l = mid + 1;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define ff(i, n) for (i = 0; i < n; i++)
int main() {
  ll t;
  t = 1;
  for (ll test = 1; test <= t; test++) {
    ll i, j, n, k, p, f, ans = -1;
    cin >> n >> k;
    ll brr[n], l = 0, r = 0;
    ff(i, n) {
      cin >> brr[i];
      r += brr[i];
    }
    while (l <= r) {
      ll mid = (l + r) / 2;
      ll c = 0;
      ff(i, n) {
        if (brr[i] % mid == 0)
          c += brr[i] / mid - 1;
        else
          c += brr[i] / mid;
      }
      if (c <= 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;

#define ll long long int
#define fi first
#define se second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define debug(a) cout << #a << " = " << a << endl;
#define endl "\\n"
#define MOD (int)1e9 + 7
#define inf (int)(1e18)

ll findCut(ll a[], ll n, ll mid) {
  ll res = 0;
  for (long int i = 0; i < n; i++)
    res += (a[i] - 1) / mid;
  return res;
}

void solve() {
  ll n, k;
  cin >> n >> k;
  ll a[n];
  for (long int i = 0; i < n; i++)
    cin >> a[i];

  ll l = 1, r = INT_MAX, ans = INT_MAX;
  while (l <= r) {
    ll mid = (l + r) / 2;
    ll x = findCut(a, n, mid);
    if (x <= k) {
      ans = min(ans, mid);
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  cout << ans << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long int t = 1;
  // cin >> t;
  for (long int tt = 1; tt <= t; tt++) {
    solve();
  }
  return 0;
}

Error: WA

Fixed submission:

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

#define ll long long int
#define fi first
#define se second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define debug(a) cout << #a << " = " << a << endl;
#define endl "\\n"
#define MOD (int)1e9 + 7
#define inf (int)(1e18)

ll findCut(ll a[], ll n, ll mid) {
  ll res = 0;
  for (long int i = 0; i < n; i++)
    res += a[i] / mid;
  return res;
}

void solve() {
  ll n, k;
  cin >> n >> k;
  ll a[n];
  for (long int i = 0; i < n; i++)
    cin >> a[i];

  ll l = 0, r = 1000000000, mid;
  while (l < r) {
    mid = (l + r) / 2;
    ll x = findCut(a, n, mid);
    //        cout << x << " " << mid << " " << l << " " << r << endl;
    if (x > k) {
      l = mid + 1;
    } else {
      r = mid - 1;
    }
  }
  cout << l << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long int t = 1;
  // cin >> t;
  for (long int tt = 1; tt <= t; tt++) {
    solve();
  }
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b)                                                          \\
  for (ll i = static_cast<int>(a); i < static_cast<int>(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__) // NOLINT
#define chmax(x, a)                                                            \\
  do {                                                                         \\
    x = max(x, a);                                                             \\
  } while (0)
#define chmin(x, a)                                                            \\
  do {                                                                         \\
    x = min(x, a);                                                             \\
  } while (0)

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<ll, ll> PLL;

ll N, K;
ll a[300000];

bool f(ll m) {
  ll t = 0;
  rep(i, N) {
    ll p = (a[i] + m - 1) / m;
    if (p >= 2)
      t += p - 1;
  }
  return t <= K;
}

int main(void) {
  cin >> N >> K;
  rep(i, N) { cin >> a[i]; }
  ll l = 0, r = 1e10;
  while (l + 1 < r) {
    ll m = (l + r) / 2;
    if (f(m))
      r = m;
    else
      l = m;
  }
  cout << r << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b)                                                          \\
  for (ll i = static_cast<int>(a); i < static_cast<int>(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__) // NOLINT
#define chmax(x, a)                                                            \\
  do {                                                                         \\
    x = max(x, a);                                                             \\
  } while (0)
#define chmin(x, a)                                                            \\
  do {                                                                         \\
    x = min(x, a);                                                             \\
  } while (0)

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<ll, ll> PLL;

typedef tuple<double, ll, ll> T;
priority_queue<T> q;
ll N, K;

int main(void) {
  cin >> N >> K;
  rep(i, N) {
    ll a;
    cin >> a;
    q.emplace(a, a, 1);
  }
  rep(_, K) {
    auto t = q.top();
    q.pop();
    q.emplace(get<1>(t) / (double)(get<2>(t) + 1), get<1>(t), get<2>(t) + 1);
  }
  auto t = q.top();
  cout << (get<1>(t) + get<2>(t) - 1) / get<2>(t) << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;
int n;
ll k;
int get_center(int int_lower, int int_upper) {
  return int_lower + (int_upper - int_lower) / 2;
}

bool can_cut(ll A[], ll X) {
  ll count = 0;
  for (int i = 0; i < n; i++)
    count += (A[i] - 1) / X;
  if (count <= k) {
    return true;
  } else {
    return false;
  }
}

int main() {
  cin >> n >> k;
  ll a[n];
  ll max_a = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    max_a = max(max_a, a[i]);
  }
  ll lower = 0;
  ll upper = max_a;
  while (upper - lower > 1) {
    ll x = (lower + upper) / 2;
    bool bool_can_cut = can_cut(a, x);
    if (bool_can_cut) {
      upper = x;
    } else {
      lower = x;
    }
  }

  cout << upper << "\\n";
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;
int n;
ll k;
int get_center(int int_lower, int int_upper) {
  return int_lower + (int_upper - int_lower) / 2;
}

bool can_cut(ll A[], ll X) {
  ll count = 0;
  for (int i = 0; i < n; i++)
    count += (A[i] - 1) / X;
  if (count <= k) {
    return true;
  } else {
    return false;
  }
}

int main() {
  cin >> n >> k;
  ll a[n];
  ll max_a = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    max_a = max(max_a, a[i]);
  }
  ll lower = 0;
  ll upper = max_a;
  for (ll i = 0; i < max_a; i++) {
    ll x = (lower + upper) / 2;
    bool bool_can_cut = can_cut(a, x);
    if (bool_can_cut) {
      upper = x;
    } else {
      lower = x;
    }
    if (upper - lower == 1)
      break;
  }

  cout << upper << "\\n";
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define fst first
#define sc second
#define snd second
#define sz(X) (int)(X).size()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define fornr(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define forab(i, a, b) for (int i = int(a); i < int(b); i++)
#define all(X) X.begin(), X.end()

typedef long long ll;
typedef vector<pair<ll, ll>> vpll;
typedef pair<int, int> pii;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef double dbl;
typedef long double ld;
typedef vector<int> vi;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  vi a(n);
  forn(i, n) cin >> a[i];
  int l = 1, r = 1e9 + 1;
  while (l != r) {
    int m = (l + r) / 2;
    int cnt = 0;
    forn(i, n) cnt += (a[i] - 1) / m;
    if (cnt <= k)
      r = m;
    else
      l = m + 1;
  }
  cout << l << "\\n";
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define fst first
#define sc second
#define snd second
#define sz(X) (int)(X).size()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define fornr(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define forab(i, a, b) for (int i = int(a); i < int(b); i++)
#define all(X) X.begin(), X.end()

typedef long long ll;
typedef vector<pair<ll, ll>> vpll;
typedef pair<int, int> pii;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef double dbl;
typedef long double ld;
typedef vector<int> vi;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  vi a(n);
  forn(i, n) cin >> a[i];
  int l = 0, r = 1e9 + 1;
  while (l != r) {
    int m = (l + r) / 2;
    int cnt = 0;
    forn(i, n) cnt += (a[i] - 1) / m;
    if (cnt <= k)
      r = m;
    else
      l = m + 1;
  }
  cout << l << "\\n";
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
template <typename T> using lim = numeric_limits<T>;
template <typename T>
using indexed_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using indexed_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag,
                              tree_order_statistics_node_update>;

struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    // http://xorshift.di.unimi.it/splitmix64.c
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }

  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};

const int N = 2e5;
ll n, k;
ll a[N];

bool is_valid(int x) {
  ll cnt = 0;
  for (int i = 0; i < n; i++) {
    cnt += a[i] / x;
    if (a[i] % x == 0)
      cnt--;
  }
  return cnt <= k;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  ll lo, hi;
  ll ans = -1;
  lo = 1;
  hi = 1e9;
  while (lo <= hi) {
    ll mid = hi - (hi - lo) / 2;
    if (is_valid(mid)) {
      ans = mid;
      hi = mid - 1;
    } else {
      lo = mid + 1;
    }
  }
  cout << ans << "\\n";
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
template <typename T> using lim = numeric_limits<T>;
template <typename T>
using indexed_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using indexed_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag,
                              tree_order_statistics_node_update>;

struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    // http://xorshift.di.unimi.it/splitmix64.c
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }

  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};

const int N = 2e5;
ll n, k;
ll a[N];

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  ll lo, hi;
  ll ans = -1;
  lo = 0;
  hi = 1e9;
  while (lo <= hi) {
    ll mid = hi - (hi - lo) / 2;
    if (is_valid(mid)) {
      ans = mid;
      hi = mid - 1;
    } else {
      lo = mid + 1;
    }
  }
  cout << ans << "\\n";
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

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

#define int long long

bool check(int n, int k, vector<int> a, int m) {
  int cuts_need = 0;
  for (int i : a) {
    cuts_need += (i - 1) / m;
  }
  return cuts_need <= k;
}

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

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

  int lo = 1, hi = 1000000000;
  while (lo < hi) {
    int mid = (lo + hi) / 2;

    if (check(n, k, a, mid)) {
      hi = mid;
    } else {
      lo = mid + 1;
    }
  }
  cout << lo << '\\n';

  return 0;
}


Error: 0

Fixed submission:

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

#define int long long

bool check(int n, int k, vector<int> a, int m) {
  int cuts_need = 0;
  for (int i : a) {
    cuts_need += (i - 1) / m;
  }
  return cuts_need <= k;
}

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

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

  int lo = 0, hi = 1000000000;
  while (lo < hi) {
    int mid = (lo + hi) / 2;

    if (check(n, k, a, mid)) {
      hi = mid;
    } else {
      lo = mid + 1;
    }
  }
  cout << lo << '\\n';

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

#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define pb push_back
#define F first
#define S second
using ll = long long;
using namespace std;

const int N = 200005 + 1;
int arr[N];
int n, k;
/*
bool check(int x){
        int step=0;
        for(int i=0;i<n;i++){
                if(x>=arr[i]) continue;
                int z=(x+arr[i]-1)/x;
                z--;
                step+=z;

        }
//	return step;
        if(k==step) return true;
        return false;
}
*/
void solve() {
  cin >> n >> k;
  int val = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    val += arr[i] + 1;
  }
  int l = 1;
  int r = 1000000000 + 1;
  int ans = 0;
  while (l <= r) {
    int mid = l + (r - l) / 2;
    int step = 0;
    for (int i = 0; i < n; i++) {
      if (mid >= arr[i])
        continue;
      int z = (mid + arr[i] - 1) / mid;
      z--;
      step += z;
    }
    if (step <= k) {
      ans = mid;
      r = mid - 1;
    }
    if (step > k) {
      l = mid + 1;
    }
  }
  cout << ans << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  //	cin>>t;
  while (t--) {
    solve();
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define pb push_back
#define F first
#define S second
using ll = long long;
using namespace std;

const int N = 2e5 + 1;
int arr[N];
int n, k;
/*
bool check(int x){
        int step=0;
        for(int i=0;i<n;i++){
                if(x>=arr[i]) continue;
                int z=(x+arr[i]-1)/x;
                z--;
                step+=z;

        }
//	return step;
        if(k==step) return true;
        return false;
}
*/
void solve() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  int l = 0;
  int r = 1e9 + 1;
  int ans = 0;
  while (l <= r) {
    int mid = l + (r - l) / 2;
    int step = 0;
    for (int i = 0; i < n; i++) {
      if (mid >= arr[i])
        continue;
      int z = (mid + arr[i] - 1) / mid;
      z--;
      step += z;
    }
    if (step <= k) {
      ans = mid;
      r = mid - 1;
    }
    if (step > k) {
      l = mid + 1;
    }
  }
  cout << ans << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  //	cin>>t;
  while (t--) {
    solve();
  }
  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 vv(Type, Name, n, m, d) vector<vector<Type>> Name(n, vector<Type>(m, d))
#define P pair<long double, int>
using namespace std;
using ll = long long;
using T = tuple<long double, int, int>;

int main(void) {

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

  vector<int> a(n);
  int m = 0;
  rep(i, n) {
    cin >> a[i];
    m = max(m, a[i]);
  }

  int l = 0;
  int r = m;

  while (r - l > 1) {

    int c = (r + l) / 2;

    int tmp = 0;
    rep(i, n) {
      tmp += a[i] / c;
      if (a[i] % c == 0)
        tmp--;

      if (tmp > k)
        break;
    }

    if (tmp > k)
      l = c;
    else
      r = c;
  }

  int tmp = 0;
  rep(i, n) {
    tmp += a[i] / r;
    if (a[i] % r == 0)
      tmp--;
  }

  if (tmp <= k)
    cout << r << endl;
  else
    cout << l << endl;

  return 0;
}


Error: 0

Fixed submission:

#include "bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < n; i++)
#define vv(Type, Name, n, m, d) vector<vector<Type>> Name(n, vector<Type>(m, d))
#define P pair<long double, int>
using namespace std;
using ll = long long;
using T = tuple<long double, int, int>;

int main(void) {

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

  vector<int> a(n);
  int ans = 0;
  rep(i, n) {
    cin >> a[i];
    ans = max(ans, a[i]);
  }

  vector<int> b(ans + 1);

  rep(i, n) {
    b[i] += a[i];
    for (int j = 1; j < a[i]; j++) {
      b[j] += a[i] / j;
      if (a[i] % j == 0)
        b[j]--;
    }
  }

  sort(b.begin(), b.end());
  int res = lower_bound(b.begin(), b.end(), k) - b.begin();

  cout << ans - res << endl;

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

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int, ll> pa;

const int N = 2e5 + 100;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;

ll a[N];
ll n, k;
bool check(int x) {
  ll sum = 0;
  for (int i = 1; i <= n; i++) {
    sum += a[i] / x;
    if (a[i] % x == 0)
      sum--;
  }
  if (sum <= k)
    return true;
  else
    return false;
}
int main() {
  ll ans = 1e9;
  cin >> n >> k;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  ll l = 1, r = 1e9;
  while (r >= l) {
    ll mid = l + r >> 1;
    if (check(mid))
      ans = min(ans, mid), r = mid - 1;
    else
      l = mid + 1;
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int, ll> pa;

const int N = 2e5 + 100;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;

ll a[N];
ll n, k;
bool check(int x) {
  ll sum = 0;
  for (int i = 1; i <= n; i++) {
    sum += a[i] / x;
    if (a[i] % x == 0)
      sum--;
  }
  if (sum <= k)
    return true;
  else
    return false;
}
int main() {
  ll ans = 1e9;
  cin >> n >> k;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  ll l = 0, r = 1e9;
  while (r >= l) {
    ll mid = l + r >> 1;
    if (check(mid))
      ans = min(ans, mid), r = mid - 1;
    else
      l = mid + 1;
  }
  cout << ans << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <ctime>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define int long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dup(x, y) (((x) + (y)-1) / (y))
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const int INF = 1e18;
const long double PI = (acos(-1));

signed main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  rep(i, N) cin >> A[i];
  int left = 0;
  int right = 1e9;
  while (right - left > 1) {
    int mid = (left + right) / 2;
    int cnt = 0;
    rep(i, N) { cnt += dup(A[i], mid) - 1; }
    if (cnt <= K)
      right = mid;
    else
      left = mid;
  }
  cout << right;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define int long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dup(x, y) (((x) + (y)-1) / (y))
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const int INF = 1e18;
const long double PI = (acos(-1));

signed main() {
  int N, K;
  cin >> N >> K;
  priority_queue<pair<double, int>> q;
  rep(i, N) {
    double A;
    cin >> A;
    q.push({A, -1});
  }
  rep(i, K) {
    pair<double, int> p;
    p = q.top();
    q.pop();
    double a = p.first;
    int b = -p.second;
    a = a * b / (b + 1);
    b++;
    b = -b;
    q.push({a, b});
  }
  pair<double, int> w;
  w = q.top();
  int ans = ceil(w.first);
  cout << ans;
}