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

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

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define sz size()
#define all(x) (x).begin(), (x).end()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)

#define ll long long

int main() {

  ios::sync_with_stdio(false);
  cin.tie(nullptr);

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

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

  ll lo = 1, hi = *max_element(all(a));

  while (lo < hi) {
    ll mid = lo + (hi - lo) / 2;

    ll br = 0ll;
    for (i = 0; i < n; i++)
      if (a[i] > mid) {
        br += ceil((double)a[i] / mid);
      } else
        br++;

    if (br > n + k) {
      lo = mid + 1;
    } else
      hi = mid;
  }

  cout << hi << "\\n";

  return 0;
}

Error: 0

Fixed submission:

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

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define sz size()
#define all(x) (x).begin(), (x).end()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)

#define ll long long

double sqr(double x) { return (double)x * x; }

int main() {

  // ios::sync_with_stdio(false);
  // cin.tie(nullptr);

  // freopen("input.in","r",stdin);

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

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

  ll lo = 0, hi = *max_element(all(a));

  while (lo < hi) {
    ll mid = lo + (hi - lo) / 2;

    ll br = 0;
    for (i = 0; i < n; i++) {
      br += ceil(a[i] / mid);
      if (br > k) {
        break;
      }
    }
    if (br > k) {
      lo = mid + 1;
    } else
      hi = mid;
  }

  cout << lo << "\\n";

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

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

#define debug(x) (cerr << #x << " = " << x << endl;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c))

const int INF = 0x3F3F3F3F;
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const double EPS = 1e-10;

inline int cmp(double x, double y = 0) {
  if (fabs(x - y) < EPS)
    return 0;
  return x > y ? 1 : -1;
}

const int maxn = 2e5 + 100;

ll a[maxn];
int n;

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

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

  ll lo = 1;
  ll hi = 2e18;
  ll ans = 1;
  while (lo <= hi) {
    ll mid = (lo + hi) >> 1;
    if (check(mid, k)) {
      ans = mid;
      hi = mid - 1;
    } else
      lo = mid + 1;
  }

  cout << ans << endl;

  return 0;
}

Error: 0

Fixed submission:

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

#define debug(x) (cerr << #x << " = " << x << endl;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c))

const int INF = 0x3F3F3F3F;
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const double EPS = 1e-10;

inline int cmp(double x, double y = 0) {
  if (fabs(x - y) < EPS)
    return 0;
  return x > y ? 1 : -1;
}

const int maxn = 2e5 + 10;

int a[maxn];
int n;

bool check(ll val, int k) {
  int i = 0;
  for (i = 0; i < n && k > 0; i++) {
    int x = (a[i] + val - 1) / val;

    // cout << a[i] << " -> " << x << " ---- " << k << endl;
    if (x < val)
      k -= x - 1;
    else
      k -= x;
  }
  bool ok = true;
  for (; i < n; i++)
    ok &= a[i] <= val;
  return ok;
}

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

  ll lo = 0;
  ll hi = 1e15;
  ll ans = -1;
  // cout << check(292638192, k) << endl;
  // return 0;
  while (lo <= hi) {
    ll mid = (lo + hi) >> 1;
    if (check(mid, k)) {
      ans = mid;
      hi = mid - 1;
    } else
      lo = mid + 1;
  }

  cout << ans << endl;

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

// g++  7.4.0
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;

int n, k;
std::vector<int> v;

bool f(int x) {
  long long int cnt = 0;
  for (int i = 0; i < n; i++) {
    cnt += (v[i] - 1) / x;
    // cout << i << ":" << v[i] << ", " << cnt << endl;;
    if (cnt > k)
      return false;
  }
  return true;
}

int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    v.push_back(tmp);
  }
  std::sort(v.begin(), v.end());
  const int maxa = v[n - 1];

  // 今回の下限は1なのでlの初期値（条件を満たさない）は0
  // 例えば l=-1, r=2 の時f(0)を呼び出して落ちる
  // int l = -1, r = maxa;
  int l = 0, r = maxa;

  while (std::abs(r - l) > 1) {
    int m = (r + l) / 2;
    // cout << "--- " << l << ", " << m << ", " << r << endl;
    if (f(m) == true) { // mで成功したらmより下を調べる
      r = m;
    } else { // mで失敗したらmより上を調べる
      l = m;
    }
  }

  cout << r << endl;
}

Error: 0

Fixed submission:

// g++  7.4.0
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;

int n, k;
std::vector<int> v;

bool f(int x) {
  long long int cnt = 0;
  for (int i = 0; i < n; i++) {
    cnt += v[i] / x;
    // cout << i << ":" << v[i] << ", " << cnt << endl;;
    if (cnt > k)
      return false;
  }
  return true;
}

int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    v.push_back(tmp);
  }
  std::sort(v.begin(), v.end());
  const int maxa = v[n - 1];

  int ans = maxa;
  int l = -1, r = maxa;
  while (std::abs(r - l) > 1) {
    int m = (r + l) / 2;
    // cout << "--- " << l << ", " << m << ", " << r << endl;
    if (f(m) == true) { // mで成功したらmより下を調べる
      r = m;
      ans = m;
    } else { // mで失敗したらmより上を調べる
      l = m;
    }
  }

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

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

#define PI acos(-1)
#define pb push_back
#define mp make_pair
#define int long long int
#define pi pair<int, int>
#define pii pair<int, pi>
#define fir first
#define sec second
#define MAXN 500001
#define MAXL 20
#define INF 200001
#define mod 1000000007

bool possible(int x, vector<int> v, int k) {
  int ans = 0;
  for (int i = 0; i < v.size(); i++) {
    if (v[i] > x) {
      int inc = v[i] / x;
      ans += inc;
    }
  }
  return ans <= k;
}
int bb(vector<int> v, int k) {
  int l = 1, r = 1e9, m;
  while (l < r) {
    m = (l + r) >> 1;
    if (possible(m, v, k))
      r = m;
    else
      l = m + 1;
  }
  return l;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  for (int i = 0; i < n; i++)
    cin >> v[i];
  cout << bb(v, k) << endl;
  return 0;
}


Error: 0

Fixed submission:

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

#define PI acos(-1)
#define pb push_back
#define mp make_pair
#define int long long int
#define pi pair<int, int>
#define pii pair<int, pi>
#define fir first
#define sec second
#define MAXN 500001
#define MAXL 20
#define INF 200001
#define mod 1000000007

bool possible(int x, vector<int> v, int k) {
  int ans = 0;
  for (int i = 0; i < v.size(); i++) {
    if (v[i] > x) {
      int inc = v[i] / x;
      ans += inc;
    }
  }
  return ans <= k;
}
int bb(vector<int> v, int k) {
  int l = 0, r = 1e9, m;
  while (l < r) {
    m = (l + r) >> 1;
    if (possible(m, v, k))
      r = m;
    else
      l = m + 1;
  }
  return l;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  for (int i = 0; i < n; i++)
    cin >> v[i];
  cout << bb(v, k) << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main(void) {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; ++i)
    cin >> A[i];

  int left = 0;
  int right = *max_element(A.begin(), A.end());

  while (right - left > 1) {
    int mid = (left + right) / 2;
    long long jk = 0;
    for (int j = 0; j < N; j++) {
      jk += A[j] / mid - 1;
      if (A[j] % mid != 0)
        jk++;
    }
    if (jk <= K)
      right = mid;
    else
      left = mid;
  }

  cout << right << endl;
}


Error: TLE

Fixed submission:

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

int main(void) {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; ++i)
    cin >> A[i];

  sort(A.begin(), A.end(), greater<int>());
  int Amin = A[0];
  for (int i = 1; i < A[0]; ++i) {
    int jk = 0;
    for (int j = 0; j < N; j++) {
      jk += ceil(A[j] / i);
    }
    if (jk <= K)
      Amin = min(i, Amin);
  }
  cout << Amin << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/assoc_container.hpp>

using namespace std;
// using namespace __gnu_pbds;

#define ll long long
#define PR pair<int, int>

const int N = 3e5 + 10;
const int MOD = 1e9 + 7;
const long long INF = 5e18;
const double PI = 2 * acos(0.0);
// template<typename T> using ordered_set = tree<T, nulong long_type, less<T>,
// rb_tree_tag, tree_order_statistics_node_update>;

vector<double> a;

bool check(int n, int k, double m) {
  int need = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] <= m) {
      continue;
    }
    int tmp = a[i] / m;
    need += tmp;
  }
  //    cout << m << " " << need << '\\n';
  return need <= k;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    double x;
    cin >> x;
    a.push_back(x);
  }
  sort(a.begin(), a.end());
  int cnt = 0;
  double L = 1.0, R = a.back();
  while (cnt < 1000) {
    double m = (L + R) / 2.0;
    //        cout << L << " " << R << " " << m << '\\n';
    if (check(n, k, m)) {
      R = m;
    } else {
      L = m;
    }
    cnt++;
  }
  int x = ceil(R);
  cout << x << '\\n';
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/assoc_container.hpp>

using namespace std;
// using namespace __gnu_pbds;

#define ll long long
#define PR pair<int, int>

const int N = 3e5 + 10;
const int MOD = 1e9 + 7;
const long long INF = 5e18;
const double PI = 2 * acos(0.0);
// template<typename T> using ordered_set = tree<T, nulong long_type, less<T>,
// rb_tree_tag, tree_order_statistics_node_update>;

vector<double> a;

bool check(int n, int k, double m) {
  int need = 0;
  for (int i = 0; i < n; i++) {
    int tmp = a[i] / m;
    need += tmp;
  }
  //    cout << m << " " << need << '\\n';
  return need <= k;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    double x;
    cin >> x;
    a.push_back(x);
  }
  sort(a.begin(), a.end());
  int cnt = 0;
  double L = 1.0, R = a.back();
  while (cnt < 1e5) {
    double m = (L + R) / 2.0;
    //        cout << L << " " << R << " " << m << '\\n';
    if (check(n, k, m)) {
      R = m;
    } else {
      L = m;
    }
    cnt++;
  }
  int x = ceil(R);
  cout << x << '\\n';
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  ll N, K;
  cin >> N >> K;
  ll ok = 1e9;
  ll ng = 1;
  vector<ll> A(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];
  int t = 40;
  while (t--) {
    ll mid = (ok + ng) / 2;
    ll count = 0;
    for (int i = 0; i < N; i++) {
      count += A[i] / mid;
      if (A[i] % mid == 0)
        count--;
    }
    if (count > K)
      ng = mid;
    else
      ok = mid;
  }
  cout << ok << endl;
}

Error: 0

Fixed submission:

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

int main() {
  ll N, K;
  cin >> N >> K;
  ll ok = 1e9;
  ll ng = 0;
  vector<ll> A(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];
  int t = 40;
  while (t--) {
    ll mid = (ok + ng) / 2;
    ll count = 0;
    for (int i = 0; i < N; i++) {
      count += A[i] / mid;
      if (A[i] % mid == 0)
        count--;
    }
    if (count > K)
      ng = mid;
    else
      ok = mid;
  }
  cout << ok << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
  fastio() {
    ios::sync_with_stdio(false);
    cout << setprecision(10) << fixed;
    cin.tie(0);
  }
};

fastio _fast_io;

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

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

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

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

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

struct fastio {
  fastio() {
    ios::sync_with_stdio(false);
    cout << setprecision(10) << fixed;
    cin.tie(0);
  }
};

fastio _fast_io;

const int N = 1e5 + 5;
int n;
ll k, ans;
int a[N];

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

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

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

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

const int MAXN = 200005;

int n, k, a[MAXN];

bool can(int L) {
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    sum += (a[i] - 1) / L;
  }

  if (sum > k)
    return false;
  else
    return true;
}

int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]);

  int L = 1, R = 1e9 + 50;
  while (L < R) {
    int mid = (L + R) / 2;
    if (can(mid))
      R = mid;
    else
      L = mid + 1;
  }
  printf("%d\\n", L);

  return 0;
}


Error: 0

Fixed submission:

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

const int MAXN = 200005;

int n, k, a[MAXN];

bool can(int L) {
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    sum += (a[i] - 1) / L;
  }

  if (sum > k)
    return false;
  else
    return true;
}

int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]);

  int L = 0, R = 1e9 + 50;
  while (L < R) {
    int mid = (L + R) / 2;
    if (can(mid))
      R = mid;
    else
      L = mid + 1;
  }
  printf("%d\\n", L);

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

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

#define ll long long

bool kmax(vector<ll> &v, ll log, ll k) {
  ll sum = 0;
  for (int i = 0; i < v.size(); i++)
    sum += (v[i] - 1) / log;
  return sum <= k;
}
ll bs(vector<ll> &v, ll low, ll high, ll k) {
  if (low < high) {
    ll mid = (high + low) / 2;
    if (kmax(v, mid, k))
      return bs(v, low, mid, k);
    else
      return bs(v, mid + 1, high, k);
  }
  return low;
}
int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> v(n);
  ll max_val = 0;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    if (max_val < v[i])
      max_val = v[i];
  }
  cout << bs(v, 1, max_val, k) << endl;
  return 0;
}

Error: 0

Fixed submission:

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

#define ll long long

bool kmax(vector<ll> &v, ll log, ll k) {
  ll sum = 0;
  for (int i = 0; i < v.size(); i++)
    sum += (v[i] - 1) / log;
  return sum <= k;
}
ll bs(vector<ll> &v, ll low, ll high, ll k) {
  if (low < high) {
    ll mid = (high + low) / 2;
    if (kmax(v, mid, k))
      return bs(v, low, mid, k);
    else
      return bs(v, mid + 1, high, k);
  }
  return low;
}
int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> v(n);
  ll max_val = 0;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    if (max_val < v[i])
      max_val = v[i];
  }
  cout << bs(v, 0, max_val, k) << endl;
  return 0;
}
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>
#define vi vector<int>
#define vvi vector<vector<int>>
#define pb push_back
#define pii pair<ll, ll>
#define tii tuple<ll, ll, ll>
#define all(v) (v).begin(), (v).end()
#define ll long long
#define ull unsigned long long
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(nullptr);
#define ld long double
#define mod 1000000007
#define PI 3.141592653589793238
#define phi 1.638
#define eps 1e-9
#define endl "\\n"
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;

int main() {
  fastio ll n, k;
  cin >> n >> k;
  vector<ll> vec(n);
  for (auto &it : vec)
    cin >> it;

  sort(all(vec), greater<ll>());

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

    ll req = 0;
    for (int i = 0; i < n; ++i) {
      if (vec[i] <= mid)
        break;
      req += (vec[i] / mid);
    }

    if (req <= k) {
      r = mid;
    } else if (req > k) {
      l = mid + 1;
    }
  }
  cout << l << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define vi vector<int>
#define vvi vector<vector<int>>
#define pb push_back
#define pii pair<ll, ll>
#define tii tuple<ll, ll, ll>
#define all(v) (v).begin(), (v).end()
#define ll long long
#define ull unsigned long long
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(nullptr);
#define ld long double
#define mod 1000000007
#define PI 3.141592653589793238
#define phi 1.638
#define eps 1e-9
#define endl "\\n"
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;

int main() {
  fastio ll n, k;
  cin >> n >> k;
  vector<ll> vec(n);
  for (auto &it : vec)
    cin >> it;

  sort(all(vec), greater<ll>());

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

    ll req = 0;
    for (int i = 0; i < n; ++i) {
      if (vec[i] <= mid)
        break;
      req += (vec[i] / mid);
    }

    if (req <= k) {
      r = mid;
    } else {
      l = mid + 1;
    }
  }
  cout << l << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
int arr[200005];

bool isvalid(int m, int n, int k) {
  if (m == 0)
    return false;
  long long total = 0;
  for (int i = 0; i < n; i++) {
    total += (arr[i]) / m;
    if (arr[i] % m == 0)
      total--;
  }

  if (total <= k)
    return true;
  return false;
}

void solve(int n, int k) {
  int i = 0, j = 1000000001;
  while (i < j) {
    int mid = (i + j) / 2;
    if (isvalid(mid, n, k))
      j = mid;

    else
      i = mid + 1;
  }

  cout << i;
}

int main() {
  int n, k;
  cin >> n >> k;

  for (int i = 0; i < n; i++)
    cin >> arr[i];

  solve(n, k);

  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
int arr[200005];

bool isvalid(int m, int n, int k) {
  long long total = 0;
  for (int i = 0; i < n; i++) {
    total += (arr[i]) / m;
    if (arr[i] % m == 0)
      total--;
  }

  if (total <= k)
    return true;
  return false;
}

void solve(int n, int k) {
  int i = 0, j = 1000000001;
  while (i < j) {
    int mid = (i + j) / 2;
    if (isvalid(mid, n, k))
      j = mid;

    else
      i = mid + 1;
  }

  cout << i;
}

int main() {
  int n, k;
  cin >> n >> k;

  for (int i = 0; i < n; i++)
    cin >> arr[i];

  solve(n, k);

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

#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<PII> VPI;
typedef vector<PLL> VPL;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

int main() {
  ll N, K;
  cin >> N >> K;
  VL A(N);
  rep(i, N) cin >> A[i];
  sort(all(A));
  ll ok = A[N - 1];
  ll ng = 0;
  while (abs(ok - ng) > 1) {
    ll mid = (ok + ng) / 2;
    ll sum = 0;
    rep(i, N) sum += (A[i] + mid - 1) / mid - 1;
    if (sum > K)
      ng = mid;
    else
      ok = mid;
  }
  cout << ok << endl;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<PII> VPI;
typedef vector<PLL> VPL;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

int main() {
  ll N, K;
  cin >> N >> K;
  VL A(N);
  rep(i, N) cin >> A[i];
  sort(all(A));
  ll ok = A[N - 1];
  ll ng = 0;
  rep(qwe, 100) {
    ll mid = (ok + ng) / 2;
    ll sum = 0;
    rep(i, N) sum += (A[i] + mid - 1) / mid - 1;
    if (sum > K)
      ng = mid;
    else
      ok = mid;
  }
  cout << ok << endl;
}