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


// Problem : E - Logs
// Contest : AtCoder - AtCoder Beginner Contest 174
// URL : https://atcoder.jp/contests/abc174/tasks/abc174_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#define ll long long
#define rep(i, a, n) for (int i = a; i < n; i++)
#define MOD 1000000007
#define vp vector<pair<int, int>>
#define ff first
#define ss second
#define pb push_back
#define all(x) (x.begin(), x.end())
#define dg(x) cerr << "--- x = " << x << "\\n"
#define endl "\\n"

using namespace std;
const int N = 2e5;
ll ar[N];
ll ans = 0;
ll n, k;

bool check(ll mid) {
  ll cost = 0;
  rep(i, 1, n + 1) cost += ((ar[i] - 1) / mid);
  return (cost <= k);
}

void solve() {
  cin >> n >> k;
  ll mx = -1;
  rep(i, 1, n + 1) {
    cin >> ar[i];
    mx = max(mx, ar[i]);
  }
  if (k) {

    ll low = 1, high = mx;
    while (low < high) {

      ll mid = low + (high - low) / 2;
      if (check(mid))
        high = mid;
      else
        low = mid + 1;
    }
    cout << low;
  } else
    cout << mx;
}

int32_t main() { solve(); }


Error: 0

Fixed submission:


// Problem : E - Logs
// Contest : AtCoder - AtCoder Beginner Contest 174
// URL : https://atcoder.jp/contests/abc174/tasks/abc174_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#define ll long long
#define rep(i, a, n) for (int i = a; i < n; i++)
#define MOD 1000000007
#define vp vector<pair<int, int>>
#define ff first
#define ss second
#define pb push_back
#define all(x) (x.begin(), x.end())
#define dg(x) cerr << "--- x = " << x << "\\n"
#define endl "\\n"

using namespace std;
const int N = 1e5;
ll ar[N];
ll ans = 0;
ll n, k;

bool check(int mid) {
  int cost = 0;
  rep(i, 1, n + 1) cost += (ar[i] / mid);
  return (cost <= k);
}

void solve() {
  cin >> n >> k;
  ll mx = -1;
  rep(i, 1, n + 1) {
    cin >> ar[i];
    mx = max(mx, ar[i]);
  }

  ll low = 1, high = mx;
  while (low < high) {

    ll mid = low + (high - low) / 2;
    if (check(mid))
      high = mid;
    else
      low = mid + 1;
  }
  cout << low;
}

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  // cin>>t;
  while (t--) {
    solve();
    cout << endl;
  }
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <math.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

bool is_possible(int mid, vector<int> &v, int K) {
  int ret = 0;
  for (auto i : v) {
    ret += (i % mid == 0 ? i / mid - 1 : i / mid);
  }
  return (ret <= K);
}

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> v(N);
  for (auto &i : v)
    cin >> i;

  int left = 1, right = 1e9 + 2, ret = -1;
  while (left <= right) {
    int mid = (left + right) / 2;
    if (is_possible(mid, v, K)) {
      ret = mid;
      right = mid - 1;
    } else
      left = mid + 1;
  }
  cout << ret << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <math.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

bool is_possible(int mid, vector<int> &v, int K) {
  int ret = 0;
  for (auto i : v) {
    ret += (i % mid == 0 ? i / mid - 1 : i / mid);
  }
  return (ret <= K);
}

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> v(N);
  for (auto &i : v)
    cin >> i;

  int left = 0, right = 1e9 + 2, ret = -1;
  while (left <= right) {
    int mid = (left + right) / 2;
    if (is_possible(mid, v, K)) {
      ret = mid;
      right = mid - 1;
    } else
      left = mid + 1;
  }
  cout << ret << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
using namespace std;
double X[200100];
int N;
long long Count(double len) {
  long long Ans = 0;
  for (int i = 0; i < N; i++) {
    Ans += (long long)(X[i] / len); // 解答引っ張ってきた人の条件。なぜか通る
    // Ans+= ceil(X[i]/len)-1;//多少遅くなるがこっちが正解
  }
  return Ans;
}

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

  // long double l=1,r=1e9;
  double l = 1, r = 1e9;

  // while(l<r-0.1)//解答を引っ張ってきた人の条件。なぜかOKだったが、lとｒの整数部が異なる状態でループを出ると問題になるはず
  // for(int i=0;i<35;i++)//OK
  // log2(10^9)=30.二分探索だとこのやり方安定する。ただし、浮動小数のせいか34以上でないと通らず。
  // while(!((ceil(r)-ceil(l)) ==
  // 0))//NG:左端が初期値0のままだと、右端のceilは0にならず、無限ループ
  // while(!((floor(r)-floor(l)) ==
  // 0))//OK:右端がぴったり整数にならなければ成立.(あまりよくない)
  while ((floor(r) - floor(l)) >
         0) // OK:右端がぴったり整数にならなければ成立.(あまりよくない)
  {
    // long double mid=(l+r)/2;
    double mid = (l + r) / 2;
    if (Count(mid) <= K)
      r = mid;
    else
      l = mid;
  }
  cout << (long long)(l + 0.999) << endl;
  return 0;
}

Error: TLE

Fixed submission:

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
using namespace std;
double X[200100];
int N;
long long Count(double len) {
  long long Ans = 0;
  for (int i = 0; i < N; i++) {
    // Ans+=(long long)(X[i]/len);//解答引っ張ってきた人の条件。なぜか通る
    Ans += ceil(X[i] / len) - 1; // 多少遅くなるがこっちが正解
  }
  return Ans;
}

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

  // long double l=1,r=1e9;
  double l = 1, r = 1e9;

  // while(l<r-0.1)//解答を引っ張ってきた人の条件。なぜかOKだったが、lとｒの整数部が異なる状態でループを出ると問題になるはず
  // for(int i=0;i<35;i++)//OK
  // log2(10^9)=30.二分探索だとこのやり方安定する。ただし、浮動小数のせいか34以上でないと通らず。
  // while(!((ceil(r)-ceil(l)) ==
  // 0))//NG:左端が初期値0のままだと、右端のceilは0にならず、無限ループ
  // while(!((floor(r)-floor(l)) ==
  // 0))//OK:右端がぴったり整数にならなければ成立.(あまりよくない)
  while ((floor(r) - floor(l)) >
         0) // OK:右端がぴったり整数にならなければ成立.(あまりよくない)
  {
    // long double mid=(l+r)/2;
    double mid = (l + r) / 2;
    if (Count(mid) <= K)
      r = mid;
    else
      l = mid;
  }
  cout << (long long)(l + 0.999) << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define int long long int
#define pp pair<int, int>
#define endl "\\n"
#define PI 3.14159265
int MAX = INT_MAX;
const int mod = 1e9 + 7;
const int INF = INT_MAX;
inline int gcd(int a, int b) {
  if (a == 0)
    return b;
  return gcd(b % a, a);
}
inline int pow(int a, int n, int mod) {
  if (n == 0)
    return 1;
  int p = pow(a, n / 2, mod);
  p = (p % mod * p % mod) % mod;
  if (n % 2)
    return (p % mod * a % mod) % mod;
  else
    return p;
}
int n, k;
vector<int> v(200009);
bool possible(int mid) {
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    int d = v[i] / mid;
    if (v[i] % mid == 0)
      d--;
    cnt += d;
  }
  if (cnt <= k)
    return true;
  return false;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int t;
  // cin>>t;
  t = 1;
  while (t--) {

    cin >> n >> k;
    int mx = 0;
    for (int i = 0; i < n; i++) {
      cin >> v[i];
      mx = max(mx, v[i]);
    }
    if (k == 0) {
      cout << mx << endl;
      continue;
    }
    int low = 1;
    int high = mx;
    int ans = 0;
    while (low <= high) {
      int mid = (low + high) / 2;
      if (possible(mid)) {
        ans = mid;
        high = mid - 1;
      } else
        low = mid + 1;
    }
    cout << ans << endl;
  }
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define int long long int
#define pp pair<int, int>
#define endl "\\n"
#define PI 3.14159265
int MAX = INT_MAX;
const int mod = 1e9 + 7;
const int INF = INT_MAX;
inline int gcd(int a, int b) {
  if (a == 0)
    return b;
  return gcd(b % a, a);
}
inline int pow(int a, int n, int mod) {
  if (n == 0)
    return 1;
  int p = pow(a, n / 2, mod);
  p = (p % mod * p % mod) % mod;
  if (n % 2)
    return (p % mod * a % mod) % mod;
  else
    return p;
}
int n, k;
vector<int> v(200009);
bool possible(int mid) {
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    cnt += (v[i] / mid);
  }
  if (cnt <= k)
    return true;
  return false;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int t;
  // cin>>t;
  t = 1;
  while (t--) {

    cin >> n >> k;
    int mx = 0;
    for (int i = 0; i < n; i++) {
      cin >> v[i];
      mx = max(mx, v[i]);
    }
    if (k == 0) {
      cout << mx << endl;
      continue;
    }
    int low = 0;
    int high = mx;
    int ans = 0;
    while (low <= high) {
      int mid = (low + high) / 2;
      if (possible(mid)) {
        ans = mid;
        high = mid - 1;
      } else
        low = mid + 1;
    }
    cout << ans << endl;
  }
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x, to) for (x = 0; x < (to); x++)
#define FORR(x, arr) for (auto &x : arr)
#define ITR(x, c) for (__typeof(c.begin()) x = c.begin(); x != c.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
//-------------------------------------------------------

int N;
ll K;
ll A[202020];

ll cut(ll v) {
  ll num = 0;
  int i;
  FOR(i, N) {
    num += (A[i] - 1) / v;
    if (num > K)
      return num;
  }
  return num;
}

void solve() {
  int i, j, k, l, r, x, y;
  string s;

  cin >> N >> K;
  FOR(i, N) cin >> A[i];

  ll L = (1 << 30);

  for (i = 29; i >= 0; i--) {
    if (cut(L - (1 << i)) <= K)
      L -= 1 << i;
  }
  cout << L << endl;
}

int main(int argc, char **argv) {
  string s;
  int i;
  if (argc == 1)
    ios::sync_with_stdio(false), cin.tie(0);
  FOR(i, argc - 1) s += argv[i + 1], s += '\\n';
  FOR(i, s.size()) ungetc(s[s.size() - 1 - i], stdin);
  cout.tie(0);
  solve();
  return 0;
}


Error: 0

Fixed submission:

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x, to) for (x = 0; x < (to); x++)
#define FORR(x, arr) for (auto &x : arr)
#define ITR(x, c) for (__typeof(c.begin()) x = c.begin(); x != c.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
//-------------------------------------------------------

int N;
ll K;
ll A[202020];

ll cut(ll v) {
  ll num = 0;
  int i;
  FOR(i, N) {
    num += (A[i] - 1) / v;
    if (num > K)
      return num;
  }
  return num;
}

void solve() {
  int i, j, k, l, r, x, y;
  string s;

  cin >> N >> K;
  FOR(i, N) cin >> A[i];

  ll L = (1 << 30) - 1;

  for (i = 29; i >= 0; i--) {
    if (cut(L - (1 << i)) <= K)
      L -= 1 << i;
  }
  cout << L << endl;
}

int main(int argc, char **argv) {
  string s;
  int i;
  if (argc == 1)
    ios::sync_with_stdio(false), cin.tie(0);
  FOR(i, argc - 1) s += argv[i + 1], s += '\\n';
  FOR(i, s.size()) ungetc(s[s.size() - 1 - i], stdin);
  cout.tie(0);
  solve();
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mo = 1000000007;
bool ok(ll arr[], ll n, ll mid, ll k) {
  ll sum = 0;
  for (ll i = 0; i < n; i++) {
    sum += (arr[i] - 1) / mid;
  }
  return (sum <= k);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll t = 1;
  // cin>>t;
  while (t) {
    ll n, k;
    cin >> n >> k;
    ll arr[n];
    ll ma = INT_MIN;
    for (ll i = 0; i < n; i++) {
      cin >> arr[i];
      ma = max(ma, arr[i]);
    }

    ll l = 0;
    ll r = ma;
    ll mid;
    while (l < r - 1) {
      mid = l + (r - l) / 2;
      if (ok(arr, n, mid, k)) {
        r = mid;
      } else {
        l = mid;
      }
    }
    cout << r << endl;
    t--;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mo = 1000000007;
bool ok(ll arr[], ll n, ll mid, ll k) {
  ll sum = 0;
  for (ll i = 0; i < n; i++) {
    sum += arr[i] / mid;
  }
  return (sum <= k);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll t = 1;
  // cin>>t;
  while (t) {
    ll n, k;
    cin >> n >> k;
    ll arr[n];
    ll ma = INT_MIN;
    for (ll i = 0; i < n; i++) {
      cin >> arr[i];
      ma = max(ma, arr[i]);
    }

    ll l = 0;
    ll r = ma;
    ll mid;
    while (l <= r) {
      mid = l + (r - l) / 2;
      if (ok(arr, n, mid, k)) {
        r = mid;
      } else {
        l = mid;
      }
    }

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

#include <bits/stdc++.h>
using namespace std;
long double X[200100];
int N;
long long Count(long double len) {
  long long Ans = 0;
  for (int i = 0; i < N; i++) {
    // Ans+=(long long)(X[i]/len);//解答引っ張ってきた人の条件。なぜか通る
    Ans += ceil(X[i] / len) - 1; // 多少遅くなるがこっちが正解
  }
  return Ans;
}

int main() {
  long long K;
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    cin >> X[i];
    // X[i]-=0.1;
  }

  long double l = 1, r = 1e9;
  // while(l<r-0.1)//解答を引っ張ってきた人の条件。なぜかOKだったが、lとｒの整数部が異なる状態でループを出ると問題になるはず
  for (
      int i = 0; i < 300;
      i++) // OK
           // log2(10^9)=30.二分探索だとこのやり方安定する。ただし、浮動小数のせいか34以上でないと通らず。
  // while(!((ceil(r)-ceil(l)) ==
  // 0))//NG:左端が初期値0のままだと、右端のceilは0にならず、無限ループ
  // while(!((floor(r)-floor(l)) ==
  // 0))//OK:右端がぴったり整数にならなければ成立.(あまりよくない)
  {
    long double mid = (l + r) / 2;
    if (Count(mid) <= K)
      r = mid;
    else
      l = mid;
  }
  cout << (long long)(l + 0.999) << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
long double X[200100];
int N;
long long Count(long double len) {
  long long Ans = 0;
  for (int i = 0; i < N; i++) {
    // Ans+=(long long)(X[i]/len);//解答引っ張ってきた人の条件。なぜか通る
    Ans += ceil(X[i] / len) - 1; // 多少遅くなるがこっちが正解
  }
  return Ans;
}

int main() {
  long long K;
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    cin >> X[i];
    // X[i]-=0.1;
  }

  long double l = 1, r = 1e9;
  // while(l<r-0.1)//解答を引っ張ってきた人の条件。なぜかOKだったが、lとｒの整数部が異なる状態でループを出ると問題になるはず
  // for(int i=0;i<35;i++)//OK
  // log2(10^9)=30.二分探索だとこのやり方安定する。ただし、浮動小数のせいか34以上でないと通らず。
  // while(!((ceil(r)-ceil(l)) ==
  // 0))//NG:左端が初期値0のままだと、右端のceilは0にならず、無限ループ
  while (!((floor(r) - floor(l)) ==
           0)) // OK:右端がぴったり整数にならなければ成立.(あまりよくない)
  {
    long double mid = (l + r) / 2;
    if (Count(mid) <= K)
      r = mid;
    else
      l = mid;
  }
  cout << (long long)(l + 0.999) << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define IO_OP                                                                  \\
  std::ios::sync_with_stdio(0);                                                \\
  std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7, N = 2e5 + 7;

int a[N];
int n, k;

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

signed main() {
  IO_OP;

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


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define IO_OP                                                                  \\
  std::ios::sync_with_stdio(0);                                                \\
  std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7, N = 2e5 + 7;

int a[N];
int n, k;

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

signed main() {
  IO_OP;

  cin >> n >> k;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int l = 0, r = INF;
  while (l <= r) {
    int m = (l + r) / 2;
    if (ok(m))
      r = m - 1;
    else
      l = m + 1;
  }
  cout << l << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long
#define ld long double
int main() {
  ll n;
  ll k;
  ll total = 0;
  ll ans;
  ll zero_max = 0;
  std::vector<ll> A;
  std::cin >> n >> k;
  for (ll i = 0; i < n; ++i) {
    ll temp;
    std::cin >> temp;
    A.push_back(temp);
    total += temp;
    zero_max = std::max(temp, zero_max);
  }
  if (k == 0) {
    std::cout << zero_max << std::endl;
    return 0;
  }
  ll mid;
  ll left = 0;
  ll right = zero_max;
  while ((right - left) > 1) {
    mid = (left + right) / 2;

    ll temp_count = 0;
    for (ll j = 0; j < n; ++j) {
      temp_count += ((A[j] + mid - 1) / mid - 1);
    }
    // std::cout << mid << " " << temp_count << std::endl;

    if (temp_count <= k) {
      right = mid;
    } else {
      left = mid;
    }
  }
  std::cout << right << std::endl;
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
int main() {
  ll n;
  ll k;
  ll total = 0;
  ll ans;
  ll zero_max = 0;
  std::vector<ll> A;
  std::cin >> n >> k;
  for (ll i = 0; i < n; ++i) {
    ll temp;
    std::cin >> temp;
    A.push_back(temp);
    total += temp;
    zero_max = std::max(temp, zero_max);
  }
  if (k == 0) {
    std::cout << zero_max << std::endl;
    return 0;
  }
  ll mid;
  ll left = 0;
  ll right = zero_max;
  while (left < right) {
    mid = (left + right) / 2;

    ll temp_count = 0;
    for (ll j = 0; j < n; ++j) {
      temp_count += A[j] / mid;
      if (A[j] % mid == 0) {
        --temp_count;
      }
    }
    std::cout << mid << " " << temp_count << std::endl;

    if (temp_count <= k) {
      right = mid;
    } else {
      left = mid + 1;
    }
    ans = mid;
  }
  std::cout << ans + 1 << std::endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

// #pragma warning(disable:4996)
#include <algorithm>
#include <bitset>
#include <cassert>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
// #include <boost/multiprecision/cpp_int.hpp>
#include <bitset>
#include <complex>
#include <cstdio>
#include <list>
// #include <stdio.h>

//< in.txt > out.txt
using namespace std;
// std::ios::sync_with_stdio(false);
// std::cin.tie(0);
const long long MOD = 10000; /// 1e9 + 7;
const long long INF = 1e9;
typedef long long LL;
typedef long double LD;
// typedef boost::multiprecision::cpp_int bigint;
typedef pair<LL, LL> PLL;
typedef pair<int, int> PI;
typedef pair<LD, LL> pdl;
typedef pair<LD, LD> pdd;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef unsigned long long ULL;

VI A;
int N, K;

int count(LD x) {
  int ans = 0;
  for (int n = 0; n < N; n++) {
    int t = ceil((LD)A[n] / x);
    ans += t - 1;
  }
  return ans;
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  cin >> N >> K;
  A.resize(N);
  for (int n = 0; n < N; n++)
    cin >> A[n];
  // sなら<=K回、eなら>K回
  LD s = 1e9, e = 0;
  for (int t = 0; t < 100; t++) {
    LD m = (e + s) / 2;
    if (count(m) <= K)
      s = m;
    else
      e = m;
  }
  cout << (int)ceil(s) << "\\n";
  return 0;
}


Error: TLE

Fixed submission:

// #pragma warning(disable:4996)
#include <algorithm>
#include <bitset>
#include <cassert>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
// #include <boost/multiprecision/cpp_int.hpp>
#include <bitset>
#include <complex>
#include <cstdio>
#include <list>
// #include <stdio.h>

//< in.txt > out.txt
using namespace std;
// std::ios::sync_with_stdio(false);
// std::cin.tie(0);
const long long MOD = 10000; /// 1e9 + 7;
const long long INF = 1e9;
typedef long long LL;
typedef long double LD;
// typedef boost::multiprecision::cpp_int bigint;
typedef pair<LL, LL> PLL;
typedef pair<int, int> PI;
typedef pair<LD, LL> pdl;
typedef pair<LD, LD> pdd;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef unsigned long long ULL;

VI A;
int N, K;

int count(LD x) {
  int ans = 0;
  for (int n = 0; n < N; n++) {
    int t = ceil((LD)A[n] / x);
    ans += t - 1;
  }
  return ans;
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  cin >> N >> K;
  A.resize(N);
  for (int n = 0; n < N; n++)
    cin >> A[n];
  // sなら<=K回、eなら>K回
  LD s = 1e9, e = 0;
  for (int t = 0; t < 200; t++) {
    LD m = (e + s) / 2;
    if (count(m) <= K)
      s = m;
    else
      e = m;
  }
  cout << (int)ceil(s) << "\\n";
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
#define maxn 200010
int n, k, a[maxn];
int judge(int x) {
  int i, cnt = 0;
  for (i = 1; i <= n; i++)
    cnt +=
        (a[i] - 1 + x) / x -
        1; //(a[i]-1+x)/x用来统计原木分割的段数((a[i]-1+x)/x此种写法是常见技巧)，切割次数=段数-1
  if (cnt > k)
    return 0; // 切割次数过多
  else
    return 1; // 切割次数小于等于k
}
int main() {
  int i, l, r, mid;
  scanf("%d%d", &n, &k);
  for (i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  l = 0, r = 1000000000;
  while (l + 1 < r) {
    mid = (l + r) / 2;
    if (judge(mid))
      r = mid;
    else
      l = mid;
  }
  printf("%d\\n", r);
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e9;
ll a[200010];
ll n, k;
bool judge(ll mid) {
  ll sum = 0;
  for (ll i = 1; i <= n; i++)
    sum += ((a[i] - 1) / mid);
  return sum <= k;
}
int main() {
  cin >> n >> k;
  for (ll i = 1; i <= n; i++)
    cin >> a[i];
  ll l = 0, r = INF;
  while (l < r) {
    if (l == r - 1) {
      if (judge(l)) {
        break;
      } else {
        l = r;
        break;
      }
    }
    ll mid = (l + r) >> 1;
    if (mid == 0 && k == 0) {
      l = 0;
      break;
    }
    if (judge(mid)) {
      r = mid;
    } else {
      l = mid + 1;
    }
  }
  cout << l;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>

using namespace std;
using ll = long long;

ll di(vector<ll> &A, int len) {
  ll ret{};
  for (ll &a : A)
    ret += (a - 1) / len + 1;
  return ret;
}

int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> A(N);
  for (ll &a : A)
    cin >> a;
  int lower{0}, upper{1000000001};
  while (upper - lower > 1) {
    auto mid = lower + (upper - lower) / 2;
    if (di(A, mid) <= N + K) {
      upper = mid;
    } else {
      lower = mid;
    }
  }
  cout << upper << endl;
}


Error: 0

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;
using ll = long long;

ll di(vector<ll> &A, int len) {
  ll ret{};
  for (ll &a : A)
    ret += (a - 1) / len + 1;
  return ret;
}

int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> A(N);
  for (ll &a : A)
    cin >> a;
  int lower{-1}, upper{1000000001};
  while (upper - lower > 1) {
    auto mid = lower + (upper - lower) / 2;
    if (di(A, mid) <= N + K) {
      upper = mid;
    } else {
      lower = mid;
    }
  }
  cout << upper << endl;
}