alexjercan/bugnet huggingface dataset:
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ff first
#define ss second
typedef long long ll;
ll power(ll a, ll b) { // a^b
  ll res = 1;
  a = a % MOD;
  while (b > 0) {
    if (b & 1) {
      res = (res * a) % MOD;
      b--;
    }
    a = (a * a) % MOD;
    b >>= 1;
  }
  return res;
}
ll fermat_inv(ll y) { return power(y, MOD - 2); }
ll gcd(ll a, ll b) { return (b == 0) ? a : gcd(b, a % b); }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll t = 1;
  // cin>>t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    ll a[n];
    for (int i = 0; i < n; i++)
      cin >> a[i];
    sort(a, a + n);
    ll l = 1;
    ll r = 1e9;
    ll ans = 0ll;
    while (l <= r) {
      ll mid = (l + r) / 2;
      ll val = 0ll;
      for (int i = 0; i < n && val <= k; i++) {
        val += a[i] / mid + ((a[i] % mid) != 0) - 1;
      }
      if (val <= k) {
        r = mid - 1;
        ans = mid;
      } else
        l = mid + 1;
    }
    cout << ans << "\\n";
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ff first
#define ss second
typedef long long ll;
ll power(ll a, ll b) { // a^b
  ll res = 1;
  a = a % MOD;
  while (b > 0) {
    if (b & 1) {
      res = (res * a) % MOD;
      b--;
    }
    a = (a * a) % MOD;
    b >>= 1;
  }
  return res;
}
ll fermat_inv(ll y) { return power(y, MOD - 2); }
ll gcd(ll a, ll b) { return (b == 0) ? a : gcd(b, a % b); }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll t = 1;
  // cin>>t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    priority_queue<ll> pq;
    double a[n];
    vector<int> ctr(n, 1);
    ll val1 = 1e6;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      ll val = (a[i] * val1) + i;
      pq.push(val);
    }
    while (k--) {
      ll val = pq.top();
      pq.pop();
      ll pos = val % val1;
      ctr[pos]++;
      val = ceil(a[pos] / ctr[pos]);
      val = val * val1 + pos;
      pq.push(val);
    }
    ll val = pq.top();
    val /= val1;
    cout << val << "\\n";
  }
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;
using vp = vector<P>;
using vpp = vector<pair<P, P>>;
using vvp = vector<vp>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a) { return is >> a.first >> a.second; }
ostream &operator<<(ostream &os, const P &a) {
  return os << "(" << a.first << "," << a.second << ")";
}

template <typename T>

void view(const std::vector<T> &v) {
#ifndef ONLINE_JUDGE
  for (const auto &e : v) {
    std::cout << e << " ";
  }
  std::cout << std::endl;
#endif
}
template <typename T> void view(const std::vector<std::vector<T>> &vv) {
  for (const auto &v : vv) {
    view(v);
  }
}
#pragma endregion

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

  auto pos = [&](int x) {
    int sum = 0;
    rep(i, n) {
      int cut = a[i] / x;
      if (a[i] % x)
        cut++;
      cut--;
      sum += cut;
    }
    return sum <= k;
  };

  int l = 1, r = max_element(a.begin(), a.end())[0];
  while (l < r) {
    int mid = (l + r) / 2;
    bool ok = pos(mid);
    if (ok) {
      r = mid;
    } else {
      l = mid + 1;
    }
  }

  cout << r << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;
using vp = vector<P>;
using vpp = vector<pair<P, P>>;
using vvp = vector<vp>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a) { return is >> a.first >> a.second; }
ostream &operator<<(ostream &os, const P &a) {
  return os << "(" << a.first << "," << a.second << ")";
}

template <typename T>

void view(const std::vector<T> &v) {
#ifndef ONLINE_JUDGE
  for (const auto &e : v) {
    std::cout << e << " ";
  }
  std::cout << std::endl;
#endif
}
template <typename T> void view(const std::vector<std::vector<T>> &vv) {
  for (const auto &v : vv) {
    view(v);
  }
}
#pragma endregion

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

  auto pos = [&](int x) {
    int sum = 0;
    rep(i, n) {
      int cut = a[i] / x;
      if (a[i] % x)
        cut++;
      cut--;
      sum += cut;
    }
    return sum <= k;
  };

  int l = 0, r = max_element(a.begin(), a.end())[0];
  while (l < r) {
    int mid = (l + r) / 2;
    bool ok = pos(mid);
    if (ok) {
      r = mid;
    } else {
      l = mid + 1;
    }
  }

  cout << r << endl;

  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cmath>     //sqrt pow
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // dequef
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector

#define rep(i, n) for (int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define all(a) (a).begin(), (a).end()
#define mod 1000000007
using ll = long long;
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vi a(n);
  int mx = 0;
  rep(i, n) {
    cin >> a[i];
    mx = max(mx, a[i]);
  }
  int right = mx + 1, left = 0;
  while (left + 1 < right) {
    int middle = (right + left) / 2;
    int cnt = 0;
    rep(i, n) cnt += ceil((double)a[i] / middle) - 1;
    if (cnt <= k)
      right = middle;
    else
      left = middle;
  }
  cout << right << endl;
}

Error: TLE

Fixed submission:

#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cmath>     //sqrt pow
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // dequef
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector

#define rep(i, n) for (int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define all(a) (a).begin(), (a).end()
#define mod 1000000007
using ll = long long;
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  priority_queue<tuple<double, int, int>> que;
  rep(i, n) {
    int a;
    cin >> a;
    que.push(make_tuple(a, a, 1));
  }
  rep(i, k) {
    auto temp = que.top();
    que.pop();
    get<2>(temp)++;
    get<0>(temp) = (double)get<1>(temp) / get<2>(temp);
    que.push(temp);
  }
  auto ans = que.top();
  cout << (int)ceil(get<0>(ans)) << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N;
  long K;
  cin >> N >> K;
  vector<long> A(N);
  for (int i = 0; i < N; i++)
    cin >> A.at(i);
  sort(A.begin(), A.end());
  long left = 1;
  long right = 1000000000;
  while (left < right) {
    long X = (right + left) / 2;
    long count = 0;
    for (int i = 0; i < N; i++) {
      count += A.at(i) / X;
      if (A.at(i) % X == 0)
        count--;
    }
    if (count > K)
      left = X + 1;
    else
      right = X;
  }
  cout << right << endl;
}


Error: TLE

Fixed submission:

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

int main() {
  int N;
  long K;
  cin >> N >> K;
  vector<long> A(N);
  for (int i = 0; i < N; i++)
    cin >> A.at(i);
  sort(A.begin(), A.end());
  long left = 1;
  long right = 1000000000;
  while (left < right) {
    long X = (right - left) / 2;
    long count = 0;
    for (int i = 0; i < N; i++) {
      count += A.at(i) / X;
      if (A.at(i) % X == 0)
        count--;
    }
    if (count > K)
      left = X + 1;
    else
      right = X;
  }
  cout << right << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int64_t divceil(int64_t numer, int64_t denom) {
  if (numer % denom == 0) {
    return numer / denom;
  } else {
    return 1L + numer / denom;
  }
}
int main() {
  int64_t N, K;
  cin >> N;
  cin >> K;
  int64_t max_a = -1;

  vector<int64_t> A(N);
  int64_t total_length = 0;
  for (uint64_t i = 0; i < N; i++) {
    cin >> A[i];
    total_length += A[i];
  }

  // 適当な初期値を与えて上界とする
  double upper_bound = -1;
  for (auto a : A) {
    int64_t split_num_heuristic = (K * a) / total_length;
    upper_bound = max(upper_bound, 1.0 * a / (split_num_heuristic + 1));
  }

  int64_t result = upper_bound + 2;
  int64_t left = 1;
  int64_t right = upper_bound + 1;
  while (right >= left) {
    int64_t mid = (left + right * 9) / 10;

    int64_t total_split = 0;
    for (uint64_t i = 0; i < N; i++) {
      int64_t split_num = divceil(A[i], mid) - 1L;
      total_split += split_num;
    }

    if (total_split <= K) {
      result = min(mid, result);
      right = mid - 1;
    } else {
      left = mid + 1;
    }
  }
  cout << result << endl;
}

Error: TLE

Fixed submission:

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

int64_t divceil(int64_t numer, int64_t denom) {
  if (numer % denom == 0) {
    return numer / denom;
  } else {
    return 1L + numer / denom;
  }
}
int main() {
  int64_t N, K;
  cin >> N;
  cin >> K;
  int64_t max_a = -1;
  vector<int64_t> A(N);
  for (uint64_t i = 0; i < N; i++) {
    cin >> A[i];
    max_a = max(max_a, A[i]);
  }

  int64_t result = max_a + 1;
  int64_t left = 1;
  int64_t right = max_a;
  while (true) {
    int64_t mid = divceil(left + right, 2);
    int64_t total_split = 0;
    for (uint64_t i = 0; i < N; i++) {
      int64_t split_num = divceil(A[i], mid) - 1L;
      total_split += split_num;
    }

    if (total_split <= K) {
      result = min(mid, result);
    }

    if (right - left <= 0) {
      break;
    }
    if (total_split <= K) {
      right = mid;
    } else {
      left = mid;
    }
  }
  cout << result << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ALL(c) begin(c), end(c)
using namespace std;
using ll = long long;
using ld = long double;

const int N = 1e6 + 6;

int main() {
  // freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout);
  ios::sync_with_stdio(0);
  cin.tie(0); // cout.precision(12);cout<<fixed;

  int n, k;

  cin >> n >> k;
  vector<int> a(n);
  for (auto &_ : a)
    cin >> _;

  int l = 1, r = 1e9 + 9;
  while (l < r) {
    int d = (l + r) >> 1;
    int cnt = 0;
    for (int x : a)
      cnt += (x + d - 1) / d - 1;
    if (cnt > k)
      l = d + 1;
    else
      r = d;
  }

  cout << r << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define ALL(c) begin(c), end(c)
using namespace std;
using ll = long long;
using ld = long double;

const int N = 1e6 + 6;

int main() {
  // freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout);
  ios::sync_with_stdio(0);
  cin.tie(0); // cout.precision(12);cout<<fixed;

  int n, k;

  cin >> n >> k;
  vector<int> a(n);
  for (auto &_ : a)
    cin >> _;

  int l = 0, r = 1e9 + 9;
  while (l < r) {
    int d = (l + r) >> 1;
    int cnt = 0;
    for (int x : a)
      cnt += (x + d - 1) / d - 1;
    if (cnt > k)
      l = d + 1;
    else
      r = d;
  }

  cout << r << endl;

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

// g++ -std=c++14 test.cpp -o test.out

#include <algorithm>
#include <bitset>
#include <cassert>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;

#define LL long long int
const LL INF = (1LL << 60);
const int INF_INT = 2147483647 - 1e6 - 1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N, K;
LL A[200000];

LL ans = INF;

void solve() {
  if (K == 0) {
    ans = -1;
    for (int i = 0; i < N; i++)
      ans = max(ans, A[i]);
    return;
  }

  LL times_per1 = 0;
  for (int i = 0; i < N; i++) {
    times_per1 += (A[i] - 1LL);
  }
  if (times_per1 <= K) {
    ans = 1;
    return;
  }

  // 最小の長さを2部探索
  LL left = 2;
  LL right = 1000000001LL;
  while (left + 1 < right) {
    LL center = (left + right) / 2LL;

    auto ok = [&]() {
      LL times = 0; // 切る回数
      for (int i = 0; i < N; i++) {
        if (A[i] % center == 0)
          times += A[i] / center - 1;
        else
          times += (A[i] / center);
      }
      return times > K;
    };

    if (ok())
      left = center;
    else
      right = center;
  }

  ans = right;
  if (ans >= 3) {
    LL sum = 0;
    for (int i = 0; i < N; i++) {
      if (A[i] % (ans - 1) == 0)
        sum += A[i] / (ans - 1) - 1;
      else
        sum += (A[i] / (ans - 1));
    }
    if (sum <= K)
      ans--;
  }
}

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

  solve();

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

Error: 0

Fixed submission:

// g++ -std=c++14 test.cpp -o test.out

#include <algorithm>
#include <bitset>
#include <cassert>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;

#define LL long long int
const LL INF = (1LL << 60);
const int INF_INT = 2147483647 - 1e6 - 1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N, K;
LL A[200000];

LL ans = INF;

void solve() {
  if (K == 0) {
    ans = -1;
    for (int i = 0; i < N; i++)
      ans = max(ans, A[i]);
    return;
  }

  // 最小の長さを2部探索
  LL left = 0;
  LL right = 1000000001;
  while (left + 1 < right) {
    LL center = (left + right) / 2;

    auto ok = [&]() {
      LL times = 0; // 切る回数
      for (int i = 0; i < N; i++) {
        times += (A[i] / center);
      }
      return times > K;
    };

    if (ok())
      left = center;
    else
      right = center;
  }

  ans = left;
  for (int i = 0; i < N; i++) {
    if (A[i] % ans != 0) {
      ans++;
      break;
    }
  }
}

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

  solve();

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

/*** akshaykumar99 ***/

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

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using id_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const long long MOD = 1e9 + 7;
const long double PI = acos(-1);
const long long N = 1e5 + 1;

typedef long long ll;
typedef long double ld;

void test_case() {
  ll n, k;
  cin >> n >> k;
  vector<ll> v(n);
  ll s = 0;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    s += v[i];
  }
  if (s <= k) {
    cout << 1 << '\\n';
    return;
  }
  ll lf = 1, rt = 1e9;
  ll ans = rt;
  while (lf < rt) {
    ll mid = (lf + rt) >> 1;
    ll tot = 0;
    for (int i = 0; i < n; i++) {
      ll xx = v[i] / mid;
      if (v[i] % mid != 0)
        xx++;
      tot += xx - 1;
    }
    if (tot <= k) {
      ans = mid;
      rt = mid;
    } else
      lf = mid + 1;
  }
  cout << ans << ' ';
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll tc = 1;
  // cin>>tc;
  while (tc--)
    test_case();
  return 0;
}

Error: WA

Fixed submission:

/*** akshaykumar99 ***/

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

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using id_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const long long MOD = 1e9 + 7;
const long double PI = acos(-1);
const long long N = 1e5 + 1;

typedef long long ll;
typedef long double ld;

void test_case() {
  ll n, k;
  cin >> n >> k;
  vector<ll> v(n);
  ll mx = 0;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    mx = max(v[i], mx);
  }
  ll lf = 0, rt = mx, ans;
  while (lf < rt) {
    ll mid = (lf + rt) >> 1;
    ll tot = 0;
    for (int i = 0; i < n; i++) {
      ll xx = v[i] / mid;
      if (v[i] % mid)
        xx++;
      tot += xx - 1;
    }
    if (tot <= k) {
      ans = mid;
      rt = mid - 1;
    } else
      lf = mid + 1;
  }
  cout << ans << ' ';
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll tc = 1;
  // cin>>tc;
  while (tc--)
    test_case();
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define all(n) n.begin(), n.end()
#define ld long double

#define ll long long
#define endl "\\n"
#define ff first
#define ss second
#define pb push_back
#define pll pair<ll, ll>
// lan 24
const ll maxn = 1e6 + 100;
const ll mod = 1e9;
const ll base = 1e2;

ll a[maxn];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  if (fopen("balls.in", "r")) {
    freopen("balls.in", "r", stdin);
    freopen("balls.out", "w", stdout);
  }
  ll n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  ll l = 1, h = 1e15;
  while (l <= h) {
    ll mid = (l + h) / 2;
    ll cnt = 0;
    for (int i = 1; i <= n; i++) {
      ll t = (a[i] + mid - 1) / mid;
      t -= 1;
      cnt += t;
      //               cout <<t<<Endl;
    }
    if (cnt <= m)
      h = mid - 1;
    else
      l = mid + 1;
  }
  cout << l;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define all(n) n.begin(), n.end()
#define ld long double

#define ll long long
#define endl "\\n"
#define ff first
#define ss second
#define pb push_back
#define pll pair<ll, ll>
// lan 24
const ll maxn = 1e5 + 100;
const ll mod = 1e9;
const ll base = 1e2;

ll a[maxn];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  if (fopen("balls.in", "r")) {
    freopen("balls.in", "r", stdin);
    freopen("balls.out", "w", stdout);
  }
  ll n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  ll l = 1, h = maxn;
  while (l <= h) {
    ll mid = (l + h) / 2;
    ll cnt = 0;
    for (int i = 1; i <= n; i++) {
      ll t = (a[i] + mid - 1) / mid;
      t -= 1;
      cnt += t;
    }
    if (cnt <= m)
      h = mid - 1;
    else
      l = mid + 1;
  }
  cout << l;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

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

int64_t divceil(int64_t numer, int64_t denom) {
  if (numer % denom == 0) {
    return numer / denom;
  } else {
    return 1L + numer / denom;
  }
}
int main() {
  int64_t N, K;
  cin >> N;
  cin >> K;
  int64_t max_a = -1;

  vector<int64_t> A(N);
  int64_t total_length = 0;
  for (uint64_t i = 0; i < N; i++) {
    cin >> A[i];
    total_length += A[i];
  }

  // 適当な初期値を与えて上界・下界とする
  double upper_bound = -1;
  double lower_bound = 10000000000;
  for (auto a : A) {
    int64_t split_num_heuristic = (K * a) / total_length;
    double val = 1.0 * a / (split_num_heuristic + 1);
    upper_bound = max(upper_bound, val);
    lower_bound = min(lower_bound, val);
  }

  int64_t result = upper_bound + 2;
  int64_t left = max(lower_bound, 1.0);
  int64_t right = upper_bound + 1;
  while (right >= left) {
    int64_t mid = (left + right) / 2;

    int64_t total_split = 0;
    for (uint64_t i = 0; i < N; i++) {
      int64_t split_num = divceil(A[i], mid) - 1L;
      total_split += split_num;
    }

    if (total_split <= K) {
      result = min(mid, result);
      right = mid - 1;
    } else {
      left = mid + 1;
    }
  }
  cout << result << endl;
}

Error: 0

Fixed submission:

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

int64_t divceil(int64_t numer, int64_t denom) {
  if (numer % denom == 0) {
    return numer / denom;
  } else {
    return 1L + numer / denom;
  }
}
int main() {
  int64_t N, K;
  cin >> N;
  cin >> K;
  int64_t max_a = -1;

  vector<int64_t> A(N);
  int64_t total_length = 0;
  for (uint64_t i = 0; i < N; i++) {
    cin >> A[i];
    total_length += A[i];
  }

  // 適当な初期値を与えて上界・下界とする
  double upper_bound = -1;
  double lower_bound = 10000000000;
  for (auto a : A) {
    int64_t split_num_heuristic = (K * a) / total_length;
    double val = 1.0 * a / (split_num_heuristic + 1);
    upper_bound = max(upper_bound, val);
    lower_bound = min(lower_bound, val);
  }

  int64_t result = upper_bound + 2;
  int64_t left = lower_bound - 1;
  int64_t right = upper_bound + 1;
  while (right >= left) {
    int64_t mid = (left + right) / 2;

    int64_t total_split = 0;
    for (uint64_t i = 0; i < N; i++) {
      int64_t split_num = divceil(A[i], mid) - 1L;
      total_split += split_num;
    }

    if (total_split <= K) {
      result = min(mid, result);
      right = mid - 1;
    } else {
      left = mid + 1;
    }
  }
  cout << result << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

//-----------------------
// author : xyqkoala
// time : 2020-08-03
//-----------------------

#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <numeric>
#include <queue>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

typedef long long LL;
const int MOD = 1e9 + 7;

void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int T = 1;
  // cin>>T;
  while (T--) {
    solve();
  }
  return 0;
}

LL check(vector<int> &nums, int m, int k) {
  LL res = 0;
  for (auto item : nums) {
    int cnt = item / m;
    if (item % m)
      cnt++;
    res += 1ll * (cnt - 1);
    if (res > k)
      return false;
  }
  return res <= k;
}

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


Error: 0

Fixed submission:

//-----------------------
// author : xyqkoala
// time : 2020-08-03
//-----------------------

#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <numeric>
#include <queue>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

typedef long long LL;
const int MOD = 1e9 + 7;

void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int T = 1;
  // cin>>T;
  while (T--) {
    solve();
  }
  return 0;
}

LL check(vector<int> &nums, int m, int k) {
  LL res = 0;
  for (auto item : nums) {
    int cnt = item / m;
    if (item % m)
      cnt++;
    res += 1ll * (cnt - 1);
    if (res > k)
      return false;
  }
  return res <= k;
}

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