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

#include "bits/stdc++.h"

using namespace std;

bool possible(long long longestLog, const vector<long long> &A, long long K) {
  long long N = A.size();
  long long numOfLongestLogs = 0;
  for (long long i = 0; i < N; ++i) {
    numOfLongestLogs += A[i] / longestLog;
    if (A[i] % longestLog == 0) {
      --numOfLongestLogs;
    }
  }
  return (numOfLongestLogs <= K);
}

void Main() {
  long long N, K;
  cin >> N >> K;
  vector<long long> A(N, 0LL);
  for (long long i = 0; i < N; ++i) {
    cin >> A[i];
  }
  sort(A.begin(), A.end(), greater<long long>());

  long long ub = A.front();
  long long lb = 1LL;
  while (ub - lb > 1LL) {
    long long mid = (ub + lb) / 2LL;
    if (possible(mid, A, K)) {
      ub = mid;
    } else {
      lb = mid;
    }
  }
  bool test = possible(lb, A, K);
  if (test) {
    cout << lb << endl;
  } else {
    cout << ub << endl;
  }
}

int main() {
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Error: 0

Fixed submission:

#include "bits/stdc++.h"

using namespace std;

bool possible(long long longestLog, const vector<long long> &A, long long K) {
  long long N = A.size();
  long long numOfLongestLogs = 0;
  for (long long i = 0; i < N; ++i) {
    numOfLongestLogs += A[i] / longestLog;
    if (A[i] % longestLog == 0) {
      --numOfLongestLogs;
    }
  }
  return (numOfLongestLogs <= K);
}

void Main() {
  long long N, K;
  cin >> N >> K;
  vector<long long> A(N, 0LL);
  for (long long i = 0; i < N; ++i) {
    cin >> A[i];
  }
  sort(A.begin(), A.end(), greater<long long>());

  long long ub = A.front();
  long long lb = 0LL;
  while (ub - lb > 1LL) {
    long long mid = (ub + lb) / 2LL;
    if (possible(mid, A, K)) {
      ub = mid;
    } else {
      lb = mid;
    }
  }
  bool test = possible(lb, A, K);
  cout << "";
  if (!test) {
    cout << "";
  }
  cout << ub << endl;
}

int main() {
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <map>
#include <stdio.h>
#include <string.h>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

bool f(vector<int> &a, int target, int k) {
  int t = 0, i = 0;
  while (t <= k && i != a.size()) {
    t += (a[i] - 1) / target;
    ++i;
  }
  if (t > k)
    return false;
  else
    return true;
}

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

  sort(a.rbegin(), a.rend());
  int maxi = a[0];
  int mini = 0;

  while (1) {
    int now = (maxi + mini) / 2;
    if (now == 0)
      break;
    bool ret = f(a, now, k);
    if (ret)
      maxi = now;
    else
      mini = now;
    if (maxi == mini + 1)
      break;
  }
  cout << maxi << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <stdio.h>
#include <string.h>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

bool f(vector<int> &a, int target, int k) {
  int t = 0, i = 0;
  while (t <= k && i != a.size()) {
    t += (a[i] - 1) / target;
    ++i;
  }
  if (t > k)
    return false;
  else
    return true;
}

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

  sort(a.rbegin(), a.rend());
  int maxi = a[0];
  int mini = 0;

  while (1) {
    int now = (maxi + mini) / 2;
    bool ret = f(a, now, k);
    if (ret)
      maxi = now;
    else
      mini = now;
    if (maxi == mini + 1)
      break;
  }
  cout << maxi << endl;

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

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

int n;
ll k;
vector<ll> a;

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

int main() {
  cin >> n >> k;
  // a=vector<ll>(n);
  for (int i = 0; i < n; ++i) {
    ll aa;
    cin >> aa;
    a.push_back(aa);
  }

  sort(a.rbegin(), a.rend());
  ll high = a[0];
  ll row = 1;
  while (high - row > 0) {
    ll mid = (high + row) / 2;
    if (check(mid))
      high = mid;
    else
      row = mid + 1;
  }

  cout << row << endl;
  return 0;
}


Error: 0

Fixed submission:

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

int n;
ll k;
vector<ll> a;

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

int main() {
  cin >> n >> k;
  // a=vector<ll>(n);
  for (int i = 0; i < n; ++i) {
    ll aa;
    cin >> aa;
    a.push_back(aa);
  }

  sort(a.rbegin(), a.rend());
  ll high = a[0] + 10;
  ll row = 0;
  while (high - row > 0) {
    ll mid = (high + row) / 2;
    if (check(mid))
      high = mid;
    else
      row = mid + 1;
  }

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

/******************************************************************************

                            Online C Compiler.
                Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>
using namespace std;
#define int long long
int n, a[200005];
bool check(int l, int k) {
  int cnt = 0;
  for (int i = 0; i < n; i++) {

    cnt += (a[i] - 1) / l;
  }
  if (cnt <= k)
    return true;
  return false;
}
signed main() {
  int k;
  cin >> n >> k;
  int l = 1, r = 1e9, mid, ans = -1;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  // int mx=p.top();
  while (l <= r) {
    mid = l + (r - l) / 2;
    if (check(mid, k)) {
      ans = mid;
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  cout << ans;
  return 0;
}


Error: WA

Fixed submission:

/******************************************************************************

                            Online C Compiler.
                Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>
using namespace std;
#define int long long
int n, a[200005];
bool check(int l, int k) {
  int cnt = 0;
  for (int i = 0; i < n; i++) {

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

#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define mod 1000000007
#define inf 1e18
#define end "\\n"
#define inp(arr, n)                                                            \\
  for (int i = 0; i < n; i++)                                                  \\
  cin >> arr[i]
#define soa(arr, n) sort(arr, arr + n)
#define sov(arr) sort(arr.begin(), arr.end())
#define fr(i, a, b) for (int i = a; i <= b; i++)
using namespace std;

ll gcdExtended(ll a, ll b, ll *x, ll *y) {
  if (b == 0) {
    *x = 1, *y = 0;
    return a;
  }
  ll x1, y1;
  ll gcd = gcdExtended(b, a % b, &x1, &y1);
  *x = y1;
  *y = x1 - (a / b) * y1;
  return gcd;
}
ll modInverse(ll a, ll m) {
  ll x, y;
  ll g = gcdExtended(a, m, &x, &y);
  ll res = (x % m + m) % m;
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  while (t--) {
    int n, k;
    cin >> n >> k;
    int arr[n];
    inp(arr, n);
    ll l = 0, h = 1000000000;
    ll ans = -1;
    while (l + 1 < h) {
      ll v1 = (l + h) / 2;
      ll v2 = v1 + 1;
      ll c1 = 0, c2 = 0;
      fr(i, 0, n - 1) {
        c1 += arr[i] / v1;
        c2 += arr[i] / v2;
        if (arr[i] % v1 == 0)
          c1--;
        if (arr[i] % v2 == 0)
          c2--;
      }
      if (c1 > k && c2 <= k) {
        ans = v2;
        break;
      } else if (c1 <= k)
        h = v1;
      else
        l = v2;
    }
    if (ans == -1)
      cout << h << end;
    else
      cout << ans << end;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define mod 1000000007
#define inf 1e18
#define end "\\n"
#define inp(arr, n)                                                            \\
  for (int i = 0; i < n; i++)                                                  \\
  cin >> arr[i]
#define soa(arr, n) sort(arr, arr + n)
#define sov(arr) sort(arr.begin(), arr.end())
#define fr(i, a, b) for (int i = a; i <= b; i++)
using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  while (t--) {
    int n, k;
    cin >> n >> k;
    int arr[n];
    inp(arr, n);
    ll l = 0, h = 1000000000;
    ll ans = -1;
    // cout<<"OK"<<endl;
    while (l + 1 <= h) {
      ll v1 = (l + h) / 2;
      ll v2 = v1 + 1;
      ll c1 = 0, c2 = 0;
      fr(i, 0, n - 1) {
        c1 += arr[i] / v1;
        c2 += arr[i] / v2;
        if (arr[i] % v1 == 0)
          c1--;
        if (arr[i] % v2 == 0)
          c2--;
      }
      if (c1 > k && c2 <= k) {
        ans = v2;
        break;
      } else if (c1 <= k)
        h = v1;
      else
        l = v2;
    }
    cout << ans << end;
  }
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(v) (v).begin()(v).end()
ll n, k;
bool check(ll x, std::vector<ll> &v) {
  ll moves = 0;
  for (auto i : v) {
    moves += i / x - (i % x == 0);
  }

  return moves <= k;
}
void solve() {
  cin >> n >> k;
  std::vector<ll> v(n);
  ll ans = 0, mid, l = 1, r = 1e9;

  for (auto &i : v)
    cin >> i, ans = max(ans, i);
  r = ans + 1;
  while (l <= r) {
    mid = l + r >> 1;
    if (check(mid, v))
      ans = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  cout << ans;
}

int main() {

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

  int t = 1;
  // cin >> t;
  for (int i = 0; i < t; i++) {
    solve();
  }
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(v) (v).begin()(v).end()
ll n, k;
bool check(ll x, std::vector<ll> &v) {
  ll moves = 0;
  for (auto i : v) {
    moves += i / x - (i % x == 0);
  }

  return moves <= k;
}
void solve() {
  cin >> n >> k;
  std::vector<ll> v(n);
  ll ans = 0, mid, l = 0, r = 1e9;

  for (auto &i : v)
    cin >> i, ans = max(ans, i);
  r = ans + 1;
  while (l <= r) {
    mid = l + r >> 1;
    if (check(mid, v))
      ans = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  cout << ans;
}

int main() {

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

  int t = 1;
  // cin >> t;
  for (int i = 0; i < t; i++) {
    solve();
  }
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"

#define int long long
#define double long double
#define PI 3.141592653589793
#define FAST                                                                   \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);

// Use for file I/O;
#define FIN                                                                    \\
  string _fname = "paintbarn";                                                 \\
  string _is = _fname + ".in", _os = _fname + ".out";                          \\
  freopen(_is.c_str(), "r", stdin);                                            \\
  freopen(_os.c_str(), "w", stdout);

using namespace std;

const int INF = 4e18 + 10;
const int INF2 = 2e18 + 10;
const int INF3 = 2e10;
const int MAXN = 305;
const int LOGN = 19;
const int MOD = 1e9 + 7;
const int EPS = 1e-9;
const int MULT = 2e5;
const int MCNST = MOD * MOD * 8;

int32_t main() {
  FAST;

  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a.rbegin(), a.rend());
  int ans = a[0];
  int lb = 1, ub = ans;
  while (lb <= ub) {
    int m = (lb + ub) / 2;
    int cnt = 0;
    for (int i = 0; i < n; i++) {
      cnt += (a[i] + m - 1) / m - 1;
    }
    // cout << m << ' ' << cnt << endl;

    if (cnt <= k) {
      ans = m;
      ub = m - 1;
    } else {
      lb = m + 1;
    }
  }
  cout << ans;
}

Error: WA

Fixed submission:

#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"

#define int long long
#define double long double
#define PI 3.141592653589793
#define FAST                                                                   \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);

// Use for file I/O;
#define FIN                                                                    \\
  string _fname = "paintbarn";                                                 \\
  string _is = _fname + ".in", _os = _fname + ".out";                          \\
  freopen(_is.c_str(), "r", stdin);                                            \\
  freopen(_os.c_str(), "w", stdout);

using namespace std;

const int INF = 4e18 + 10;
const int INF2 = 2e18 + 10;
const int INF3 = 2e10;
const int MAXN = 305;
const int LOGN = 19;
const int MOD = 1e9 + 7;
const int EPS = 1e-9;
const int MULT = 2e5;
const int MCNST = MOD * MOD * 8;

int32_t main() {
  FAST;

  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a.rbegin(), a.rend());
  int ans = a[0];
  int lb = 0, ub = ans;
  while (lb <= ub) {
    int m = (lb + ub) / 2;
    int cnt = 0;
    for (int i = 0; i < n; i++) {
      cnt += (a[i] + m - 1) / m - 1;
    }
    // cout << m << ' ' << cnt << endl;

    if (cnt <= k) {
      ans = m;
      ub = m - 1;
    } else {
      lb = m + 1;
    }
  }
  cout << ans;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

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

const int mn = 2e5 + 7;
int a[mn], n, k;

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

int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    a[n + 1] = max(a[i], a[n + 1]);
  }
  int l = 1, r = a[n + 1];
  while (l < r) {
    int mid = (l + r) >> 1;
    if (check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  cout << l;
}

Error: WA

Fixed submission:

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

const int mn = 2e5 + 7;
int a[mn], n, k;

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

int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    a[n + 1] = max(a[i], a[n + 1]);
  }
  int l = 0, r = a[n + 1];
  while (l < r) {
    int mid = (l + r) >> 1;
    if (check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  cout << l;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include "bits/stdc++.h"

using namespace std;

bool possible(long long longestLog, const vector<long long> &A, long long K) {
  long long N = A.size();
  long long numOfLongestLogs = 0;
  for (long long i = 0; i < N; ++i) {
    numOfLongestLogs += A[i] / longestLog;
    if (A[i] % longestLog == 0) {
      --numOfLongestLogs;
    }
  }
  return (numOfLongestLogs <= K);
}

void Main() {
  long long N, K;
  cin >> N >> K;
  vector<long long> A(N, 0LL);
  for (long long i = 0; i < N; ++i) {
    cin >> A[i];
  }
  sort(A.begin(), A.end(), greater<long long>());

  long long ub = A.front();
  long long lb = 0LL;
  while (ub - lb > 1LL) {
    long long mid = (ub + lb) / 2LL;
    if (possible(mid, A, K)) {
      ub = mid;
    } else {
      lb = mid;
    }
  }
  // bool test = possible(lb, A, K);
  cout << "";
  // if (test) {
  //     cout << "";
  // }
  cout << ub << endl;
}

int main() {
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Error: 0

Fixed submission:

#include "bits/stdc++.h"

using namespace std;

bool possible(long long longestLog, const vector<long long> &A, long long K) {
  long long N = A.size();
  long long numOfLongestLogs = 0;
  for (long long i = 0; i < N; ++i) {
    numOfLongestLogs += A[i] / longestLog;
    if (A[i] % longestLog == 0) {
      --numOfLongestLogs;
    }
  }
  return (numOfLongestLogs <= K);
}

void Main() {
  long long N, K;
  cin >> N >> K;
  vector<long long> A(N, 0LL);
  for (long long i = 0; i < N; ++i) {
    cin >> A[i];
  }
  sort(A.begin(), A.end(), greater<long long>());

  long long ub = A.front();
  long long lb = 0LL;
  while (ub - lb > 1LL) {
    long long mid = (ub + lb) / 2LL;
    if (possible(mid, A, K)) {
      ub = mid;
    } else {
      lb = mid;
    }
  }
  bool test = possible(lb, A, K);
  cout << "";
  if (test) {
    cout << "";
  }
  cout << ub << endl;
}

int main() {
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

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

int cut_times(int *logs, int n, int min_length) {
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += (logs[i] - 1) / min_length;
  }

  return ans;
}

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

  // sort(a, a+n, greater<int>());

  int left = 1;
  int right = 1000000000;

  while (left < right) {
    int mid = (left + right) / 2;
    if (cut_times(a, n, mid) > k) {
      left = mid + 1;
    } else if (cut_times(a, n, mid) <= k) {
      right = mid;
    }
  }

  cout << left << endl;

  return 0;
}

Error: 0

Fixed submission:

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

int cut_times(int *logs, int n, int min_length) {
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += (logs[i] - 1) / min_length;
  }

  return ans;
}

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

  // sort(a, a+n, greater<int>());

  int left = 0;
  int right = 1000000000;

  while (left < right) {
    int mid = (left + right) / 2;
    if (cut_times(a, n, mid) > k) {
      left = mid + 1;
    } else if (cut_times(a, n, mid) <= k) {
      right = mid;
    }
  }

  cout << left << endl;

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

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

#define ll long long int
int main() {
  ll n, p, q, x, y, i, k, a, b;

  cin >> n >> k;
  ll ara[n];
  for (i = 0; i < n; i++)
    cin >> ara[i];

  if (k == 0) {
    cout << *max_element(ara, ara + n) << endl;
    return 0;
  }

  ll mx = 1e18 + 100;

  ll l = 1, r = mx;
  bool bl = false;

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

    for (i = 0; i < n; i++) {
      ll x = (ara[i] - 1) / mid;
      tot += x;
    }

    if (tot <= k)
      mx = min(mx, mid), r = mid - 1;
    else
      l = mid + 1;
  }

  cout << mx << '\\n';
}


Error: 0

Fixed submission:

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

#define ll long long int
int main() {
  ll n, p, q, x, y, i, k, a, b;

  cin >> n >> k;
  ll ara[n];
  for (i = 0; i < n; i++)
    cin >> ara[i];

  if (k == 0) {
    cout << *max_element(ara, ara + n) << endl;
    return 0;
  }

  ll mx = 1e18 + 100;

  ll l = 0, r = mx;
  bool bl = false;

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

    for (i = 0; i < n; i++) {
      ll x = (ara[i] - 1) / mid;
      tot += x;
    }

    if (tot <= k)
      mx = min(mx, mid), r = mid - 1;
    else
      l = mid + 1;
  }

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

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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)

ll INF = 1ll << 60;

vi a;

void chmax(int &a, int b) {
  if (a < b)
    a = b;
}

bool is_ok(int x, int k) {
  int sum = 0;
  rep(i, 0, a.size()) { sum += (a[i] + (x - 1)) / x - 1; }
  if (k >= sum)
    return true;
  else
    return false;
}

int binary_search(int key, int amax) {
  int ng = 0;
  int ok = amax;

  while (abs(ok - ng) > 1) {
    int mid = (ok + ng) / 2;

    if (is_ok(mid, key))
      ok = mid;
    else
      ng = mid;
  }

  return ok;
}

int main() {
  int n, k;
  cin >> n >> k;
  int amax = 0;
  rep(i, 0, n) {
    int tmp;
    cin >> tmp;
    a.push_back(tmp);
    chmax(amax, tmp);
  }

  int ans = binary_search(k, amax);

  cout << ans << endl;

  return 0;
}

Error: 0

Fixed submission:

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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)

ll INF = 1ll << 60;

vi a;

void chmax(int &a, int b) {
  if (a < b)
    a = b;
}

bool is_ok(int x, int k) {
  int sum = 0;
  rep(i, 0, a.size()) { sum += (a[i] + (x - 1)) / x - 1; }
  if (k >= sum)
    return true;
  else
    return false;
}

int binary_search(int key, int amax) {
  int ng = -1;
  int ok = amax;

  while (abs(ok - ng) > 1) {
    int mid = (ok + ng) / 2;

    if (is_ok(mid, key))
      ok = mid;
    else
      ng = mid;
  }

  return ok;
}

int main() {
  int n, k;
  cin >> n >> k;
  int amax = 0;
  rep(i, 0, n) {
    int tmp;
    cin >> tmp;
    a.push_back(tmp);
    chmax(amax, tmp);
  }

  int ans = binary_search(k, amax);

  cout << ans << endl;

  return 0;
}