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

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define RREP(i, m, n) for (int i = (int)(m); i >= (int)(n); i--)
#define rrep(i, n) RREP(i, (n)-1, 0)
#define all(v) v.begin(), v.end()
#define endk '\\n'
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;
const ld eps = 1e-10;
template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) {
  if (a > b)
    a = b;
}
template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) {
  if (a < b)
    a = b;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  ll k;
  cin >> n >> k;
  vector<ll> A(n);
  rep(i, n) cin >> A[i];
  auto bsearch = [&]() {
    auto test = [&](ll t) {
      ll need = 0;
      rep(i, n) need += (A[i] + t - 1) / t - 1;
      return need <= k;
    };
    ll ok = *max_element(all(A)), ng = 0;
    while (ok - ng > 1) {
      ll mid = (ok + ng) / 2;
      (test(mid) ? ok : ng) = mid;
    }
    return ok;
  };
  cout << bsearch() << endk;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define RREP(i, m, n) for (int i = (int)(m); i >= (int)(n); i--)
#define rrep(i, n) RREP(i, (n)-1, 0)
#define all(v) v.begin(), v.end()
#define endk '\\n'
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;
const ld eps = 1e-10;
template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) {
  if (a > b)
    a = b;
}
template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) {
  if (a < b)
    a = b;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  ll k;
  cin >> n >> k;
  vector<ll> A(n);
  rep(i, n) cin >> A[i];
  auto bsearch = [&]() {
    auto test = [&](ll t) {
      ll need = 0;
      rep(i, n) need += (A[i] + t - 1) / t - 1;
      return need <= k;
    };
    ll ok = *max_element(all(A)), ng = -1;
    while (ok - ng > 1) {
      ll mid = (ok + ng) / 2;
      (test(mid) ? ok : ng) = mid;
    }
    return ok;
  };
  cout << bsearch() << endk;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#include <cmath>
#include <iomanip>
#include <math.h>
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;
}
const int mod = 1e9 + 7;
const int64_t INF = 1e18;
int64_t N, K;
int64_t A[1000005];
int64_t f(int64_t m) {
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    if (A[i] > m) {
      cnt += (A[i] - 1) / m;
    }
  }
  return cnt;
}
int main() {
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  int64_t l = 0, r = 1e9 + 1;
  while (r - l > 1) {
    int64_t m = (r + l) / 2; // m=max長さ
    if (f(m) <= K) {
      r = m;
    } // K回以内でｍ以内の長さにできる長さの範囲＝ｒ
    if (f(m) > K) {
      l = m;
    }
  }
  cout << r << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#include <cmath>
#include <iomanip>
#include <math.h>
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;
}
const int mod = 1e9 + 7;
const int64_t INF = 1e18;
int64_t N, K;
int64_t A[100005];
int64_t f(int64_t m) {
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    if (A[i] > m) {
      cnt += (A[i] - 1) / m;
    }
  }
  return cnt;
}
int main() {
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  int64_t l = 0, r = 1e9 + 1;
  while (r - l > 1) {
    int64_t m = (r + l) / 2; // m=max長さ
    if (f(m) <= K) {
      r = m;
    } // K回以内でｍ以内の長さにできる長さの範囲＝ｒ
    if (f(m) > K) {
      l = m;
    }
  }
  cout << r << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << (x) << endl
#define INF (int)1e9
#define EPS (double)1e-9
#define MOD ((int)1e9 + 7)
using namespace std;
typedef long long llong;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef pair<int, int> pii;
template <class Type> void line(const Type &a) {
  int cnt = 0;
  for (const auto &elem : a) {
    if (cnt++)
      cerr << ' ';
    cerr << elem;
  }
  cerr << endl;
}

int main() { // 解説参考. 二分探索.
  int n, k;
  cin >> n >> k;

  vi a(n);
  REP(i, n) cin >> a[i];

  int l = 0, r = INF;
  while (r - l > 1) { // k以下となる最小の長さを見つける. r側が条件を満たす.
    int mid = (l + r) / 2;
    debug(mid);

    llong cnt = 0;
    REP(i, n) cnt += (a[i] - 1) / mid;

    if (cnt > k)
      l = mid;
    else
      r = mid;
  }

  cout << r << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << (x) << endl
#define INF (int)1e9
#define EPS (double)1e-9
#define MOD ((int)1e9 + 7)
using namespace std;
typedef long long llong;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef pair<int, int> pii;
template <class Type> void line(const Type &a) {
  int cnt = 0;
  for (const auto &elem : a) {
    if (cnt++)
      cerr << ' ';
    cerr << elem;
  }
  cerr << endl;
}

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

  vi a(n);
  REP(i, n) cin >> a[i];

  double l = 0.0, r = 1e9;
  while (r - l > EPS) {
    double mid = (l + r) / 2;
    debug(mid);
    int cnt = 0;
    REP(i, n) cnt += ceil(a[i] / mid - 1);
    debug(cnt);
    if (cnt <= k)
      r = mid;
    else
      l = mid;
  }

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define fi first
#define se second
#define pb push_back
#define me(a, b) memset(a, b, sizeof(a))
#define INIT() std::ios::sync_with_stdio(false)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
const int MAX_N = 200000 + 5;
const int MAX_M = 100000 + 5;
const int INF = 0x7fffffff;
const int inf = 1000000000;
const double EPS = 1e-6;
const ull base = 123;
const ll mod = 1e9 + 7;
const double pi = 4 * atan(1.0);
int a[MAX_N];
int n, k;
int check(int x) {
  int ans = 0;
  int i;
  for (i = 1; i <= n; i++) {
    if (a[i] > x) {
      ans += a[i] / x;
      if (a[i] % x == 0)
        ans--;
    }
    if (ans > k)
      return 1;
  }
  return 0;
}
int main() {
  cin >> n >> k;
  int i;
  for (i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  int l = 0;
  int r = 1000000000;
  int mid = (l + r) / 2;
  while (l <= r) {
    if (mid == 0)
      break;
    if (check(mid)) {
      l = mid + 1;
    } else
      r = mid - 1;
    mid = (l + r) / 2;
  }
  cout << mid + 1 << endl;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define fi first
#define se second
#define pb push_back
#define me(a, b) memset(a, b, sizeof(a))
#define INIT() std::ios::sync_with_stdio(false)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
const int MAX_N = 200000 + 5;
const int MAX_M = 100000 + 5;
const int INF = 0x7fffffff;
const int inf = 1000000000;
const double EPS = 1e-6;
const ull base = 123;
const ll mod = 1e9 + 7;
const double pi = 4 * atan(1.0);
int a[MAX_N];
int n, k;
int check(int x) {
  int ans = 0;
  int i;
  for (i = 1; i <= n; i++) {
    if (a[i] > x) {
      ans += a[i] / x;
      if (a[i] % x == 0)
        ans--;
    }
    if (ans > k)
      return 1;
  }
  return 0;
}
int main() {
  cin >> n >> k;
  int i;
  for (i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  int l = 0;
  int r = 1000000000;
  int mid = (l + r) / 2;
  while (l <= r) {
    if (check(mid)) {
      l = mid + 1;
    } else
      r = mid - 1;
    mid = (l + r) / 2;
  }
  cout << mid + 1 << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

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

// Made with <3 by MinumCoklatPanas
typedef long long ll;
const int INF = 1e9;
const ll INFF = 1e18;
const int MAXN = 510;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
const double INFD = 1E9;
const double EPS = 1e-9;

int tab[200010];
int n, k;

int cei(int x, int y) { return ((x / y) + (x % y != 0)); }

bool cek(int x) {
  int cnt = 0;
  for (int i = 1; i <= n; i++)
    cnt += cei(tab[i], x) - 1;
  // cout << cnt << endl;
  return (cnt <= k);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++)
    cin >> tab[i];
  // cout << cek(5) << endl;
  // return 0;
  int l = 1;
  int r = INF;
  while (r - l > 1) {
    int mid = (l + r) >> 1;
    // cout << l << " " << r << " " << mid << endl;
    if (cek(mid))
      r = mid;
    else
      l = mid + 1;
  }
  if (cek(l)) {
    cout << l << endl;
  } else
    cout << r << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

// Made with <3 by MinumCoklatPanas
typedef long long ll;
const int INF = 1e9;
const ll INFF = 1e18;
const int MAXN = 510;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
const double INFD = 1E9;
const double EPS = 1e-9;

int tab[200010];
int cnt[200010];

int cei(int x, int y) { return ((x / y) + (x % y != 0)); }

struct cmp {
  bool operator()(pair<int, int> a, pair<int, int> b) {
    if (cei(a.first, a.second + 1) == cei(b.first, b.second + 1))
      return a.first < b.first;
    return (cei(a.first, a.second + 1) < cei(b.first, b.second + 1));
  }
};

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  priority_queue<pair<int, int>, vector<pair<int, int>>, cmp> pq;
  for (int i = 1; i <= n; i++) {
    int ta;
    cin >> ta;
    pq.push({ta, 0});
  }
  for (int i = 1; i <= k; i++) {
    if (pq.empty()) {
      cout << 1 << endl;
      return 0;
    }
    auto cur = pq.top();
    pq.pop();
    cur.second++;
    if (cei(cur.first, cur.second) <= 1)
      continue;
    pq.push(cur);
  }
  int mx = 0;
  while (!pq.empty()) {
    auto cur = pq.top();
    pq.pop();
    int tmp = cei(cur.first, cur.second + 1);
    mx = max(mx, tmp);
  }
  cout << mx << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <math.h>
#include <stdio.h>
using namespace std;

typedef long long ll;

ll a[200005], n, k;

bool possible(double x) {
  ll i, res = 0;

  for (i = 1; i <= n; i++)
    res += (a[i] * 2 / (ll)(x * 2.0) + !(a[i] * 2 % (ll)(x * 2.0) == 0)) - 1;

  return res <= k;
}

int main(void) {
  ll i;

  scanf("%lld %lld", &n, &k);
  for (i = 1; i <= n; i++)
    scanf("%lld", &a[i]);

  double left = 0.5, right = (double)*max_element(a + 1, a + n + 1);

  for (i = 1; i <= 200; i++) {
    double mid = (left + right) / 2.0;

    if (possible(mid))
      right = mid;
    else
      left = mid + 0.1;
  }

  printf("%lld", (ll)round(left));
  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <math.h>
#include <stdio.h>
using namespace std;

typedef long long ll;

ll a[200005], n, k;

bool possible(double x) {
  ll i, res = 0;

  for (i = 1; i <= n; i++)
    res += (a[i] * 2 / (ll)(x * 2.0) + !(a[i] * 2 % (ll)(x * 2.0) == 0)) - 1;

  return res <= k;
}

int main(void) {
  ll i;

  scanf("%lld %lld", &n, &k);
  for (i = 1; i <= n; i++)
    scanf("%lld", &a[i]);

  double left = 0, right = (double)*max_element(a + 1, a + n + 1);

  for (i = 1; i <= 200; i++) {
    double mid = (left + right) / 2.0;

    if (possible(mid))
      right = mid;
    else
      left = mid + 0.1;
  }

  printf("%lld", (ll)round(left));
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
using namespace std;
const ll N = 1e6 + 5;
const ll maxn = 5005;
ll m, n, t, T, k, a[N], ans, tong;
string s, ss;
struct dang {
  ll pos, val, mn, mx, vtri;
};
bool so(const dang &x, const dang &y) {
  return (x.val < y.val) || (x.val == y.val && x.pos < y.pos);
}
priority_queue<ll> pr;
bool check(ll u) {
  ll tt = 0;
  if (u <= 0)
    return true;
  for (int i = 1; i <= n; i++) {
    tt += max((a[i] + u - 1) / u - 1, 0ll);
  }
  if (tt <= k)
    return true;
  else
    return false;
}
void sol() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    m = max(m, a[i]);
  }
  ll lf = 0, rt = m, mid;
  while (lf <= rt) {
    mid = (lf + rt) / 2;
    if (check(mid))
      rt = mid - 1;
    else
      lf = mid + 1;
  }
  cout << max(lf, 1ll);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  // cin >> T; while(T -- > 0)
  sol();
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
using namespace std;
const ll N = 1e6 + 5;
const ll maxn = 5005;
ll m, n, t, T, k, a[N], b[N], ans, tong;
string s, ss;
struct dang {
  ll pos, val, mn, mx, vtri;
};
bool so(const dang &x, const dang &y) {
  return (x.val < y.val) || (x.val == y.val && x.pos < y.pos);
}
priority_queue<ll> pr;
bool check(ll u) {
  ll tt = 0;
  for (int i = 1; i <= n; i++) {
    tt += max((a[i] + u - 1) / u - 1, 0ll);
  }
  if (tt <= k)
    return true;
  else
    return false;
}
void sol() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    m = max(m, a[i]);
  }
  ll lf = 0, rt = m, mid;
  while (lf <= rt) {
    mid = (lf + rt) / 2;
    if (check(mid))
      rt = mid - 1;
    else
      lf = mid + 1;
  }
  cout << lf;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  // cin >> T; while(T -- > 0)
  sol();
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

// Hail god Yato

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

#define hs                                                                     \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
typedef long long ll;
const ll mod = 1000000007;
const ll INF = 1e9;
const ll MAX = 200005;
//
//

vector<ll> vec(MAX);
int check(ll mid, ll k) {
  ll cuts = 0;
  for (ll z : vec) {
    cuts += ((z - 1) / mid);
  }
  return cuts <= k;
}
void solve() {
  ll n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++)
    cin >> vec[i];
  ll lo = 1, hi = INF;
  while (lo < hi) {
    ll mid = (lo + hi) >> 1;
    if (check(mid, k))
      hi = mid;
    else
      lo = mid + 1;
  }
  cout << lo;
}
int main() {
  hs;
  ll t;
  t = 1;
  // cin>>t;
  for (int i = 1; i <= t; i++) {
    // cout<<"Case #"<<i<<": ";
    solve();
  }
  return 0;
}


Error: WA

Fixed submission:

// Hail god Yato

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

#define hs                                                                     \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
typedef long long ll;
const ll mod = 1000000007;
const ll INF = 1e10;
const ll MAX = 100001;
//
//

vector<ll> vec(MAX);
int check(ll mid, ll k) {
  ll cuts = 0;
  for (ll z : vec) {
    cuts += ((z - 1) / mid);
  }
  return cuts <= k;
}
void solve() {
  ll n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++)
    cin >> vec[i];
  ll lo = 1, hi = INF;
  while (lo < hi) {
    ll mid = (lo + hi) >> 1;
    if (check(mid, k))
      hi = mid;
    else
      lo = mid + 1;
  }
  cout << lo;
}
int main() {
  hs;
  ll t;
  t = 1;
  // cin>>t;
  for (int i = 1; i <= t; i++) {
    // cout<<"Case #"<<i<<": ";
    solve();
  }
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int N, K, m = 0;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    m = max(A[i], m);
  }
  int l = 1, r = m;
  int ans = m;
  for (int j = 0; j < 100; j++) {
    if (l == r)
      break;
    int a = l + (r - l) / 2;
    int M = 0, k = 0;
    bool ok = true;
    for (int i = 0; i < N; i++) {
      if (A[i] <= a)
        continue;
      k += A[i] / a;
      // if(A[i]/a==0)ok=false;
    }
    if (ok && k <= K) {
      ans = min(a, ans);
      r = a;
    } else {
      l = a;
    }
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

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

int main() {
  int N, K, m = 0;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    m = max(A[i], m);
  }
  int l = 1, r = m;
  int ans = m;
  for (int j = 0; j < 10000; j++) {
    if (l == r)
      break;
    int a = l + (r - l) / 2;
    int M = 0, k = 0;
    bool ok = true;
    for (int i = 0; i < N; i++) {
      if (A[i] <= a)
        continue;
      k += A[i] / a;
      // if(A[i]/a==0)ok=false;
    }
    if (ok && k <= K) {
      ans = min(a, ans);
      r = a;
    } else {
      l = a;
    }
  }
  cout << ans << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;

#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i, k, N) for (int i = k; i < N; i++)
#define MP make_pair
#define MT make_tuple // tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(), (x).end()

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

struct wood {
  double L;
  ll N;
  double M;
  bool operator<(const wood &a) const { return L < a.L; }
};

int main() {
  ll N, K;
  cin >> N >> K;
  v A(N);
  rep(i, 0, N) cin >> A[i];
  ll l = 0;
  ll r = 1000000000;

  while (l != r) {
    ll sum = 0;
    ll now = (l + r) / 2;
    if (now == 0) {
      cout << 1;
      return 0;
    }
    rep(i, 0, N) { sum += ((A[i] - 1) / now); }
    if (sum > K) {
      l = now + 1;
    } else {
      r = now;
    }
  }
  cout << r;

  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;

#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i, k, N) for (int i = k; i < N; i++)
#define MP make_pair
#define MT make_tuple // tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(), (x).end()

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

struct wood {
  double L;
  ll N;
  double M;
  bool operator<(const wood &a) const { return L < a.L; }
};

int main() {
  ll N, K;
  cin >> N >> K;
  v A(N);
  rep(i, 0, N) cin >> A[i];
  ll l = 0;
  ll r = 1000000000;

  while (l != r) {
    ll sum = 0;
    ll now = (l + r) / 2;
    rep(i, 0, N) { sum += ((A[i] - 1) / now); }
    if (sum > K) {
      l = now + 1;
    } else {
      r = now;
    }
  }
  cout << r;

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

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

#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define int long long
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repn(i, a, b) for (int i = a; i >= b; i--)
#define F first
#define S second
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
const int N = 100001;

void solve() {
  int n, k;
  cin >> n >> k;
  vi a(n);
  int mx = 0;
  rep(i, 0, n) {
    cin >> a[i];
    mx = max(mx, a[i]);
  }
  int l = 0, r = mx;
  // if(mx==1){cout<<1;return;}
  while (l < r) {
    int mid = (l + r) / 2;
    if (r == 1)
      break;
    int ans = 0;
    rep(i, 0, n) ans = ans + (a[i] - 1) / mid;
    if (ans <= k)
      r = mid;
    else
      l = mid + 1;
  }
  cout << r;

  return;
}

signed main() {
  IOS;

  int t = 1;
  // cin>>t;
  // fac[0] = 1;
  // for (int i=1 ; i<=2000001; i++) fac[i] = fac[i-1]*i%mod;
  rep(i, 0, t) {
    solve();
    cout << "\\n";
    //   cout<<" * "<<t<<"\\n";
  }
  //    return 0;
}

Error: 0

Fixed submission:

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

#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define int long long
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repn(i, a, b) for (int i = a; i >= b; i--)
#define F first
#define S second
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
const int N = 100001;

void solve() {
  int n, k;
  cin >> n >> k;
  vi a(n);
  int mx = 0;
  rep(i, 0, n) {
    cin >> a[i];
    mx = max(mx, a[i]);
  }
  int l = 0, r = mx;
  if (mx == 1) {
    cout << 1;
    return;
  }
  while (l < r) {
    int mid = (l + r) / 2;
    int ans = 0;
    rep(i, 0, n) ans = ans + (a[i] - 1) / mid;
    if (ans <= k)
      r = mid;
    else
      l = mid + 1;
  }
  cout << r;

  return;
}

signed main() {
  IOS;

  int t = 1;
  // cin>>t;
  // fac[0] = 1;
  // for (int i=1 ; i<=2000001; i++) fac[i] = fac[i-1]*i%mod;
  rep(i, 0, t) {
    solve();
    cout << "\\n";
    //   cout<<" * "<<t<<"\\n";
  }
  //    return 0;
}