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

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define rrep(i, n) for (int i = (int)n - 1; i >= 0; --i)
using namespace std;
using ll = long long;
template <typename T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value>::type fill_v(U &u, const V... v) {
  u = U(v...);
}
template <typename T, typename U, typename... V>
typename enable_if<!is_same<T, U>::value>::type fill_v(U &u, const V... v) {
  for (auto &e : u)
    fill_v<T>(e, v...);
}

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

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

  int ok = 1e9 + 5, ng = 0;

  auto check = [&](int x) {
    ll cnt = 0;
    rep(i, n) {
      int now = a[i] / x;
      if (a[i] % x == 0)
        now--;
      cnt += now;
    }
    return cnt <= k;
  };

  while (ok - ng > 1) {
    int mid = (ok + ng) >> 1;
    if (check(mid))
      ok = mid;
    else
      ng = mid;
  }

  cout << ok << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define rrep(i, n) for (int i = (int)n - 1; i >= 0; --i)
using namespace std;
using ll = long long;
template <typename T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value>::type fill_v(U &u, const V... v) {
  u = U(v...);
}
template <typename T, typename U, typename... V>
typename enable_if<!is_same<T, U>::value>::type fill_v(U &u, const V... v) {
  for (auto &e : u)
    fill_v<T>(e, v...);
}

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

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

  int ok = 1e9 + 5, ng = 0;

  auto check = [&](int x) {
    ll cnt = 0;
    rep(i, n) {
      int now = a[i] / x;
      if (a[i] % x == 0)
        now--;
      cnt += now;
    }
    return cnt <= k;
  };

  rep(i, 100) {
    int mid = (ok + ng) >> 1;
    if (check(mid))
      ok = mid;
    else
      ng = mid;
  }

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

#include <bits/stdc++.h>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()

// #define DEBUG 100

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const ll oo = 1e9 + 7;
const ll mod = 1e9 + 7, maxn = 2e6 + 100, maxm = 1e3 + 100;
const double PI = acos(-1);

ll solve(vector<ll> &vs, int n, ll k) {
  ll a = 1, b = oo, best;

  while (a <= b) {
    ll mid = (a + b) / 2, cnt = 0;
    for (auto it : vs) {
      cnt += (it / mid - (it % mid == 0 ? 1 : 0));
    }
    if (cnt > k) {
      a = mid + 1;
    } else {
      best = mid;
      b = mid - 1;
    }
  }
  return best;
}
int main() {
  ios_base::sync_with_stdio(false);
  ll n, k;
  cin >> n >> k;

  vector<ll> vs(n);

  for (int i = 0; i < n; i++) {
    cin >> vs[i];
  }

  ll ans = solve(vs, n, k);

  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()

// #define DEBUG 100

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const ll oo = 1e9 + 7;
const ll mod = 1e9 + 7, maxn = 2e6 + 100, maxm = 1e3 + 100;
const double PI = acos(-1);

ll solve(vector<ll> &vs, int n, ll k) {
  ll a = 0, b = oo, best;

  while (a <= b) {
    ll mid = (a + b) / 2, cnt = 0;
    for (auto it : vs) {
      cnt += (it / mid - (it % mid == 0 ? 1 : 0));
    }
    if (cnt > k) {
      a = mid + 1;
    } else {
      best = mid;
      b = mid - 1;
    }
  }
  return best;
}
int main() {
  ios_base::sync_with_stdio(false);
  ll n, k;
  cin >> n >> k;

  vector<ll> vs(n);

  for (int i = 0; i < n; i++) {
    cin >> vs[i];
  }

  ll ans = solve(vs, n, k);

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

#include <bits/stdc++.h>

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;

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

int n, k;
vector<int> a;

bool tes(int d) {
  if (d == 0) {
    return true;
  }
  int cnt = 0;
  rep(i, n) {
    if (a.at(i) > d) {
      cnt += ceil(a.at(i) / d);
    }
  }
  return cnt <= k;
}

int main() {
  cin >> n >> k;
  a.resize(n);
  rep(i, n) cin >> a.at(i);
  sort(a.begin(), a.end());
  int lb = 0;
  int ub = 1'000'000'000;
  while (ub - lb > 1) {
    int mid = (lb + ub) / 2;
    if (tes(mid)) {
      ub = mid;
    } else {
      lb = mid;
    }
  }
  cout << ub << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;

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

int n, k;
vector<int> a;

bool tes(int d) {
  int cnt = 0;
  rep(i, n) {
    if (a.at(i) > d) {
      cnt += ceil(a.at(i) / d);
    }
  }
  return cnt <= k;
}

int main() {
  cin >> n >> k;
  a.resize(n);
  rep(i, n) cin >> a.at(i);
  sort(a.begin(), a.end());
  int lb = -1;
  int ub = 1'000'000'000;
  while (ub - lb > 1) {
    int mid = (lb + ub) / 2;
    if (tes(mid)) {
      ub = mid;
    } else {
      lb = mid;
    }
  }
  cout << lb + 1 << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>

#define Maxn 200010
#define LL long long

using namespace std;

const double eps = 0.00001;

inline LL read() {
  LL x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while ('0' <= c && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}

LL n, k, a[Maxn], maxone;

LL calc(int len) {
  if (!len)
    return 1e9 + 1;
  LL tim = 0;
  for (int i = 1; i <= n; ++i) {
    tim += (a[i] - 1) / len;
  }
  return tim;
}

int main() {
  n = read();
  k = read();
  for (int i = 1; i <= n; ++i)
    a[i] = read(), maxone = max(maxone, a[i]);
  int l = 0, r = maxone;
  while (l < r) {
    int mid = (l + r) >> 1;
    if (calc(mid) > k)
      l = mid + 1;
    else
      r = mid;
  }
  cout << l << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>

#define Maxn 200010
#define LL long long

using namespace std;

const double eps = 0.00001;

inline LL read() {
  LL x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while ('0' <= c && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}

LL n, k, a[Maxn], maxone;

LL calc(int len) {
  LL tim = 0;
  for (int i = 1; i <= n; ++i) {
    tim += (a[i] - 1) / len;
  }
  return tim;
}

int main() {
  n = read();
  k = read();
  for (int i = 1; i <= n; ++i)
    a[i] = read(), maxone = max(maxone, a[i]);
  int l = 0, r = maxone;
  while (l < r) {
    int mid = (l + r) >> 1;
    if (calc(mid) > k)
      l = mid + 1;
    else
      r = mid;
  }
  cout << l << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod = 1000000007;
const ll inf = 1e18;

int main() {

  ll n, k;
  cin >> n >> k;
  double a[n];
  for (ll i = 0; i < n; i++)
    cin >> a[i];
  /*priority_queue<pair<double,ll>, vector<pair<double,ll>>,
  less<pair<double,ll>>> b; double c[n]; for(ll i=0;i<n;i++)c[i]=1; for(ll
  i=0;i<n;i++)b.push({a[i],i});

  bool owari=false;
  ll s=0;
  for(ll i=0;i<n;i++)s+=a[i];
  if(s<=k){
    cout << 1 << endl;
    return 0;
  }

  //cout << b.top().first << endl;

  for(ll i=0;i<k;i++){
    pair<double,ll> v=b.top();
    //cout << v.first << " " << v.second << endl;
    b.pop();
    if(v.first<1){
      owari=true;
      break;
    }
    c[v.second]+=1;
    v.first=a[v.second]/c[v.second];
    //cout << v.first << " " << v.second << endl;
    b.push(v);

    //cout << b.top().first << " " << b.top().second << endl;
  }

  if(owari){
    cout << 1 << endl;
    return 0;
  }

  for(ll i=0;i<n;i++){
    a[i]/=c[i];
  }

  //for(ll i=0;i<n;i++)cout << a[i] << endl;

  double m=0;
  for(ll i=0;i<n;i++)m=max(m,a[i]);

  cout << (ll) ceil(m) << endl;*/

  ll r = (ll)pow(10, 9);
  ll l = 0;
  ll h = (r + l) / 2;
  while (abs(r - l) > 1) {
    double hp = h;
    ll s = 0;
    for (ll i = 0; i < n; i++)
      s += ceil(a[i] / hp) - 1;
    if (s <= k) {
      r = h;
    } else {
      l = h;
    }
    h = (r + l) / 2;
  }

  cout << r << endl;

  // printf("%lf",ceil(m));
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod = 1000000007;
const ll inf = 1e18;

int main() {

  ll n, k;
  cin >> n >> k;
  double a[n];
  for (ll i = 0; i < n; i++)
    cin >> a[i];
  priority_queue<pair<double, ll>, vector<pair<double, ll>>,
                 less<pair<double, ll>>>
      b;
  double c[n];
  for (ll i = 0; i < n; i++)
    c[i] = 1;
  for (ll i = 0; i < n; i++)
    b.push({a[i], i});

  bool owari = false;

  // cout << b.top().first << endl;

  for (ll i = 0; i < k; i++) {
    pair<double, ll> v = b.top();
    // cout << v.first << " " << v.second << endl;
    b.pop();
    if (v.first < 1) {
      owari = true;
      break;
    }
    c[v.second] += 1;
    v.first = a[v.second] / c[v.second];
    // cout << v.first << " " << v.second << endl;
    b.push(v);

    // cout << b.top().first << " " << b.top().second << endl;
  }

  if (owari) {
    cout << 1 << endl;
    return 0;
  }

  for (ll i = 0; i < n; i++) {
    a[i] /= c[i];
  }

  // for(ll i=0;i<n;i++)cout << a[i] << endl;

  double m = 0;
  for (ll i = 0; i < n; i++)
    m = max(m, a[i]);

  cout << (ll)ceil(m) << endl;

  // printf("%lf",ceil(m));
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error


/*
 *	Created By: 'Present_Sir'
 *	Created On: Monday 03 August 2020 08:11:06 PM IST
 */

#include <bits/stdc++.h>
#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL)
#define int long long
using namespace std;

const int N = 2e5 + 10;
int n, k;
vector<int> v(N);

bool valid(int mid) {
  int kc = k;
  if (mid == 0) {
    return false;
  }
  for (int i = 0; i < n; i++) {
    if (v[i] <= mid) {
      continue;
    }
    int t = v[i] / mid;
    kc -= (t);
  }
  return kc >= 0;
}

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

  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  int i = 0, j = LLONG_MAX;
  int ans = 0;
  while (i <= j) {
    int mid = (i + j) / 2;
    if (valid(mid)) {
      j = mid - 1;
      ans = mid;
    } else {
      i = mid + 1;
    }
  }
  cout << ans << endl;
}

int32_t main() {
  IOS;
  // int t; cin>>t; while(t--)
  { solve(); }
  return 0;
}


Error: 0

Fixed submission:


/*
 *	Created By: 'Present_Sir'
 *	Created On: Monday 03 August 2020 08:11:06 PM IST
 */

#include <bits/stdc++.h>
#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL)
#define int long long
using namespace std;

const int N = 2e5 + 10;
int n, k;
vector<int> v(N);

bool valid(int mid) {
  int kc = k;
  for (int i = 0; i < n; i++) {
    if (v[i] <= mid) {
      continue;
    }
    int t = v[i] / mid;
    kc -= (t);
  }
  return kc >= 0;
}

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

  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  int i = 0, j = LLONG_MAX;
  int ans = 0;
  while (i <= j) {
    int mid = (i + j) / 2;
    if (valid(mid)) {
      j = mid - 1;
      ans = mid;
    } else {
      i = mid + 1;
    }
  }
  cout << ans << endl;
}

int32_t main() {
  IOS;
  // int t; cin>>t; while(t--)
  { solve(); }
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
long long N, K;
long long a[200005];

int check(long long x) {
  long long now = 0;
  double p = x / 10.;
  for (int i = 1; i <= N; ++i)
    now += (a[i] - 1) / p;
  // cout<<now<<" "<<x<<" "<<p<<endl;
  return now <= K;
}

int main() {
  scanf("%lld%lld", &N, &K);
  for (int i = 1; i <= N; ++i)
    scanf("%lld", &a[i]);
  long long l = 1, r = 1e10;
  while (l < r) {
    long long mid = (l + r) / 2;
    if (check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  // cout<<l<<endl;
  double p = l / 10.;
  l = ceil(p);
  printf("%lld\\n", l);
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
  ll n, k, a[100050];
  cin >> n >> k;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  ll l = 1, r = 1e9, mid, ans = 0;
  while (l <= r) {
    mid = (l + r) / 2;
    ll jum = 0;
    for (int i = 1; i <= n; i++) {
      jum += (a[i] - 1) / mid;
    }
    if (jum <= k) {
      r = mid - 1;
      ans = mid;
    } else {
      l = mid + 1;
    }
  }
  cout << ans << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int, int>;

ll n, k;
vector<ll> a;

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

int main(void) {
  cin >> n >> k;
  a.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  ll ok = 1000000010;
  ll ng = 0;
  while (ok - ng > 1) {
    ll mid = (ok + ng) / 2;
    if (is_ok(mid)) {
      ok = mid;
    } else {
      ng = mid;
    }
  }
  if (k != 0)
    cout << ok << endl;
  else {
    ll ans = 0;
    for (int i = 0; i < n; i++) {
      ans = max(ans, a[i]);
    }
    cout << ans << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int, int>;

ll n, k;
vector<ll> a;

bool is_ok(ll x) {
  ll cnt = 0;
  for (int i = 0; i < n; i++) {
    cnt += (a[i] / x);
  }
  if (cnt <= k)
    return true;
  else
    return false;
}

int main(void) {
  cin >> n >> k;
  a.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  ll ok = 1000000010;
  ll ng = -2;
  while (ok - ng > 1) {
    ll mid = (ok + ng) / 2;
    if (is_ok(mid)) {
      ok = mid;
    } else {
      ng = mid;
    }
  }
  if (k != 0)
    cout << ok << endl;
  else {
    ll ans = 0;
    for (int i = 0; i < n; i++) {
      ans = max(ans, a[i]);
    }
    cout << ans << 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++)
using namespace std;
typedef long long ll;
typedef long double ld;
const int INF = 1e9;

int main() {
  ll n, k, t = 0;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  ll l = 0, r = 1e9, m;
  while (r - l > 1) {
    m = (l + r) / 2;
    t = 0;
    rep(i, n) t += (a[i] - 1) / m;
    if (t <= k)
      r = m;
    else
      l = m;
  }

  cout << r << 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;
typedef long long ll;
typedef long double ld;
const int INF = 1e9;

int main() {
  ll n, k, t = 0;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  ll l = -1, r = 1e9, m;
  while (r - l > 1) {
    m = (l + r) / 2;
    t = 0;
    rep(i, n) t += (a[i] - 1) / m;
    if (t <= k)
      r = m;
    else
      l = m;
  }

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

#include <bits/stdc++.h>
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
using namespace std;
using ll = long long;
using ld = long double;
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

int N, K;
vector<int> A;

bool isOK(int x) {
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    int a = A.at(i);
    cnt += (a + x - 1) / x - 1;
  }
  if (cnt <= K)
    return true;
  else
    return false;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> K;
  A.resize(N);
  for (int i = 0; i < N; i++)
    cin >> A.at(i);

  int ng = 0;
  int ok = 1e9;
  while (abs(ok - ng) > 1) {
    int mid = (ok + ng) / 2;
    if (isOK(mid))
      ok = mid;
    else
      ng = mid;
  }
  cout << ok << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
using namespace std;
using ll = long long;
using ld = long double;
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

int N, K;
vector<int> A;

bool isOK(int x) {
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    int a = A.at(i);
    cnt += (a + x - 1) / x - 1;
  }
  if (cnt <= K)
    return true;
  else
    return false;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> K;
  A.resize(N);
  for (int i = 0; i < N; i++)
    cin >> A.at(i);

  int ng = -1;
  int ok = 1e9;
  while (abs(ok - ng) > 1) {
    int mid = (ok + ng) / 2;
    if (isOK(mid))
      ok = mid;
    else
      ng = mid;
  }
  cout << ok << endl;

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

#include <bits/stdc++.h>
using namespace std;
#define M 1000000000
#define f(i, a, b) for (long long i = a; i < b; i++)
#define tc                                                                     \\
  long long t;                                                                 \\
  cin >> t;                                                                    \\
  while (t--)
#define pb push_back
#define mp make_pair
#define gcd __gcd
#define F first
#define S second
#define input(a, n)                                                            \\
  for (ll i = 0; i < n; i++)                                                   \\
    cin >> a[i];
#define output(a, n)                                                           \\
  for (ll i = 0; i < n; i++)                                                   \\
    cout << a[i] << " ";
#define up upper_bound
#define lo lower_bound
#define endl "\\n"
#define mem(a) memset(a, -1, sizeof(a))
#define ll long long
#define umap unordered_map

ll a[200010];
ll n, k;
bool solve(ll x) {
  ll sum = 0;
  f(i, 0, n) { sum += (a[i] - 1) / x; }
  return sum <= k;
}

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

  cin >> n >> k;

  input(a, n);

  ll l = 1, r = 1e9 + 10, mid;

  while (l < r) {
    mid = (l + r) / 2;
    if (solve(mid))
      r = mid;
    else
      l = mid + 1;
  }
  cout << r;

  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define M 1000000000
#define f(i, a, b) for (long long i = a; i < b; i++)
#define tc                                                                     \\
  long long t;                                                                 \\
  cin >> t;                                                                    \\
  while (t--)
#define pb push_back
#define mp make_pair
#define gcd __gcd
#define F first
#define S second
#define input(a, n)                                                            \\
  for (ll i = 0; i < n; i++)                                                   \\
    cin >> a[i];
#define output(a, n)                                                           \\
  for (ll i = 0; i < n; i++)                                                   \\
    cout << a[i] << " ";
#define up upper_bound
#define lo lower_bound
#define endl "\\n"
#define mem(a) memset(a, -1, sizeof(a))
#define ll long long
#define umap unordered_map

ll a[100005];
ll n, k;
bool solve(ll x) {
  ll sum = 0;
  f(i, 0, n) { sum += (a[i] - 1) / x; }
  return sum <= k;
}

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

  cin >> n >> k;

  input(a, n);

  ll l = 1, r = 1e9 + 10, mid;

  while (l < r) {
    mid = (l + r) / 2;
    if (solve(mid))
      r = mid;
    else
      l = mid + 1;
  }
  cout << r;

  return 0;
}