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

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef unsigned long long ull;
typedef set<int>::iterator sit;
#define st first
#define sd second
#define mkp make_pair
#define pb push_back
void tempwj() {
  freopen("hash.in", "r", stdin);
  freopen("hash.out", "w", stdout);
}
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll qpow(ll a, ll b, ll mod) {
  a %= mod;
  ll ans = 1;
  while (b) {
    if (b & 1)
      ans = ans * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return ans;
}
struct cmp {
  bool operator()(const pii &a, const pii &b) { return a.second < b.second; }
};
int lb(int x) { return x & -x; }
// friend bool operator < (Node a,Node b)   重载
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll mod = 1e9 + 7;
const int maxn = 2e6 + 10;
int a[maxn];
int n, m;
bool pd(int x) {
  ll s = 0;
  for (int i = 1; i <= n; i++) {
    s += (a[i] + x - 1) / x - 1;
  }
  return s <= m;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  int l = 1, r = 1e9;
  while (l < r) {
    int mid = l + r >> 1;
    if (pd(mid))
      r = mid;
    else
      l = mid + 1;
  }
  printf("%d\\n", r);
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef unsigned long long ull;
typedef set<int>::iterator sit;
#define st first
#define sd second
#define mkp make_pair
#define pb push_back
void tempwj() {
  freopen("hash.in", "r", stdin);
  freopen("hash.out", "w", stdout);
}
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll qpow(ll a, ll b, ll mod) {
  a %= mod;
  ll ans = 1;
  while (b) {
    if (b & 1)
      ans = ans * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return ans;
}
struct cmp {
  bool operator()(const pii &a, const pii &b) { return a.second < b.second; }
};
int lb(int x) { return x & -x; }
// friend bool operator < (Node a,Node b)   重载
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll mod = 1e9 + 7;
const int maxn = 2e6 + 10;
int a[maxn];
int n, m;
bool pd(int x) {
  ll s = 0;
  for (int i = 1; i <= n; i++) {
    s += (a[i] + x - 1) / x - 1;
  }
  return s <= m;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  int l = 0, r = 1e9;
  while (l < r) {
    int mid = l + r >> 1;
    if (pd(mid))
      r = mid;
    else
      l = mid + 1;
  }
  printf("%d\\n", r);
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error


#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef unsigned int ll;
ll n, k;
ll a[200005];
ll suan(ll m) {
  ll ans = 0;
  for (ll i = 0; i < n; i++) {
    ans += a[i] / m;
    if (a[i] % m == 0)
      ans--;
    if (ans > k)
      return ans;
  }
  return ans;
}
ll fen(ll l, ll r) {
  if (l == r)
    return l;
  ll m = (l + r) / (ll)2;
  ll cal = suan(m);
  if (cal > k) {
    return fen(m + 1, r);
  } else
    return fen(l, m);
}
int main(void) {
  scanf("%d%d", &n, &k);
  for (ll i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  printf("%d", fen((ll)1, (ll)1000000000));
}

Error: WA

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef int ll;
ll n, k;
ll a[200005];
ll suan(ll m) {
  ll ans = 0;
  for (ll i = 0; i < n; i++) {
    ans += a[i] / m;
    if (a[i] % m == 0)
      ans--;
    if (ans > k)
      return ans;
  }
  return ans;
}
ll fen(ll l, ll r) {
  if (l == r)
    return l;
  ll m = (l + r) / 2;
  ll cal = suan(m);
  if (cal > k)
    fen(m + 1, r);
  else
    fen(l, m);
}
int main(void) {
  scanf("%d%d", &n, &k);
  for (ll i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  printf("%d", fen(1, 1000000000));
}
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);
  }
  return Ans;
}
int main() {
  long long K;
  cin >> N >> K;
  // long long Max=0;
  for (int i = 0; i < N; i++) {
    cin >> X[i];
    //	Max=max(Max,(long long)(X[i]));
    X[i] -= 0.1;
  }
  // if(!K)
  //{
  //	cout<<Max<<endl;
  //	return 0;
  // }
  long double l = 1, r = 1e10;
  while (l < r - 0.1) {
    long double mid = (l + r + 0.1) / 2;
    //  cout<<l<<" "<<r<<" "<<mid<<endl;
    if (Count(mid) <= K)
      r = mid - 0.07;
    else
      l = mid + 0.07;
  }
  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);
  }
  return Ans;
}
int main() {
  long long K;
  cin >> N >> K;
  long double Sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> X[i];
    Sum += X[i];
    X[i] -= 0.1;
  }
  if (!Sum) {
    puts("0");
    return 0;
  }
  long double l = 1, r = 1e12;
  while (l < r - 0.1) {
    long double mid = (l + r + 0.1) / 2;
    //  cout<<l<<" "<<r<<" "<<mid<<endl;
    if (Count(mid) <= K)
      r = mid;
    else
      l = mid + 0.07;
  }
  cout << (long long)(l + 0.999) << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>
using namespace std;
int n, k;
int a[200001];

bool canCut(int x) {
  int count = 0;
  for (int i = 0; i < n; i++) {
    count += (a[i] - 1) / x;
    if (count > k)
      return false;
  }
  if (count <= k)
    return true;
  else
    return false;
}

void solve() {
  // 二分探索
  int ub = 0, lb = 10e9;
  while (lb - ub > 1) {
    int mid = (ub + lb) / 2;
    if (canCut(mid)) {
      lb = mid;
    } else {
      ub = mid;
    }
  }
  printf("%d", lb);
}

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

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
using namespace std;
int n, k;
int a[200001]; // 累積和を格納する

bool canCut(double x) {
  int count = 0;
  for (int i = 0; i < n; i++) {
    count += ceil(a[i] / x) - 1;
    if (count > k)
      return false;
  }
  if (count <= k)
    return true;
  else
    return false;
}

void solve() {
  // 二分探索
  double ub = 0, lb = 10e9;
  while (lb - ub > 0.01) {
    double mid = (ub + lb) / 2;
    mid *= 100;
    mid = ceil(mid);
    mid /= 100;
    if (canCut(mid)) {
      lb = mid;
    } else {
      ub = mid;
    }
  }
  printf("%.0lf", ceil(lb));
}

int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  solve();
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
const int inf = 0x3f3f3f3f;
int n, k;
int a[maxn];
bool check(int x) {
  int sum = 0;
  for (int i = 1; i <= n; i++)
    sum += (a[i] - 1) / x + 1 - 1;
  if (sum > k)
    return 0;
  else
    return 1;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  // freopen(".in","r",stdin);
  // freopen(".out","w",stdout);
  cin >> n >> k;
  int maxv = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    maxv = max(a[i], maxv);
  }
  int l = 1, r = maxv + 1, mid, ans;
  while (l < r) {
    mid = (l + r) / 2;
    if (check(mid)) {
      r = mid;
      ans = mid;
    } else
      l = mid + 1;
  }
  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
const int inf = 0x3f3f3f3f;
int n, k;
int a[maxn];
bool check(int x) {
  int sum = 0;
  for (int i = 1; i <= n; i++)
    sum += (a[i] - 1) / x + 1 - 1;
  if (sum > k)
    return 0;
  else
    return 1;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  // freopen(".in","r",stdin);
  // freopen(".out","w",stdout);
  cin >> n >> k;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  int l = 0, r = 1000000000, mid;
  while (l < r) {
    mid = (l + r) / 2;
    if (check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  cout << l << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
const int inf = 0x3f3f3f3f;
int n, k;
int a[maxn];
bool check(int x) {
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    sum += a[i] / x;
    if (a[i] % x == 0)
      sum--;
  }
  if (sum > k)
    return 0;
  else
    return 1;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  // freopen(".in","r",stdin);
  // freopen(".out","w",stdout);
  cin >> n >> k;
  int maxv = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    maxv = max(maxv, a[i]);
  }
  int l = 1, r = maxv + 1, ans;
  while (l < r) {
    int mid = (l + r) / 2;
    if (check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  cout << l << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2e5 + 5;
const long long inf = 0x3f3f3f3f;
long long n, k;
long long a[maxn];
bool check(long long x) {
  long long sum = 0;
  for (long long i = 1; i <= n; i++) {
    sum += a[i] / x;
    if (a[i] % x == 0)
      sum--;
  }
  if (sum > k)
    return 0;
  else
    return 1;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  // freopen(".in","r",stdin);
  // freopen(".out","w",stdout);
  cin >> n >> k;
  for (long long i = 1; i <= n; i++)
    cin >> a[i];
  long long l = 0, r = 1000000000, ans;
  while (l < r) {
    long long mid = (l + r) / 2;
    if (check(mid)) {
      r = mid;
      ans = r;
    } else
      l = mid + 1;
  }
  cout << ans << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
const int inf = 0x3f3f3f3f;
int n, k;
int a[maxn];
bool check(int x) {
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    sum += a[i] / x;
    if (a[i] % x == 0)
      sum--;
  }
  if (sum > k)
    return 0;
  else
    return 1;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  // freopen(".in","r",stdin);
  // freopen(".out","w",stdout);
  cin >> n >> k;
  int maxv = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    maxv = max(maxv, a[i]);
  }
  int l = 1, r = 1000000000, ans;
  while (l < r) {
    int mid = (l + r) / 2;
    if (check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  cout << l << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
const int inf = 0x3f3f3f3f;
int n, k;
int a[maxn];
bool check(int x) {
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    sum += a[i] / x;
    if (a[i] % x == 0)
      sum--;
  }
  if (sum > k)
    return 0;
  else
    return 1;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  // freopen(".in","r",stdin);
  // freopen(".out","w",stdout);
  cin >> n >> k;
  int maxv = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    maxv = max(maxv, a[i]);
  }
  int l = 0, r = maxv + 1, ans;
  while (l < r) {
    int mid = (l + r) / 2;
    if (check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  cout << l << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define dbg(x) cerr << #x << " = " << x << "\\n"
#define fast_io                                                                \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie()
using namespace std;
using ll = long long;

int n, k;
vector<int> v;

bool gd(int X) {
  int K = k;
  for (int i : v)
    K -= (i - 1) / X;
  return K >= 0;
}

int main() {
  fast_io;

  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    v.push_back(x);
  }

  int l = 1, r = 2e9;
  while (l < r) {
    int md = (l + r) >> 1;
    if (gd(md))
      r = md;
    else
      l = md + 1;
  }

  cout << l << "\\n";
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define dbg(x) cerr << #x << " = " << x << "\\n"
#define fast_io                                                                \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie()
using namespace std;
using ll = long long;

const int N = int(5e5) + 500;

ll n, k;
ll a[N];

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

int main() {
  fast_io;

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

  ll l = 1, r = 2e9;
  while (l + 10 < r) {
    ll md = (l + r) / 2;
    if (gd(md))
      r = md;
    else
      l = md + 1;
  }

  while (gd(r))
    --r;
  ++r;

  cout << r << "\\n";
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define mp make_pair
#define pb push_back
#define pll pair<ll, ll>
ll INF = 1000000007;

//-----------------//
#define amin main
//-----------------//

int amin() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll t, i, j;
  ll n;
  cin >> n;
  ll k;
  cin >> k;
  ll arr[n];
  for (i = 0; i < n; i++)
    cin >> arr[i];
  ll low = 1;
  ll high = 1e9 + 2;
  ll mid = 0;
  while (low <= high) {
    mid = (low + high) / 2;
    // bin(mid);

    ll sum = 0;
    for (i = 0; i < n; i++) {
      sum += (arr[i] - 1) / mid;
    }
    if (sum <= k) {
      high = mid - 1;
    } else if (sum > k) {
      low = mid + 1;
    }

    // cout<<mid<<" "<<sum<<endl;
  }
  // cout<<mid<<endl;
  ll sum = 0;
  ll sum2 = 0;
  for (i = 0; i < n; i++) {
    if (mid - 1 > 0)
      sum2 += (arr[i] - 1) / (mid - 1);
    else
      sum2 = INF;
  }
  ll sum1 = 0;

  for (i = 0; i < n; i++) {
    sum += (arr[i] - 1) / mid;
  }
  // ll sum1 = 0;
  // ll sum = 0;
  for (i = 0; i < n; i++) {
    sum1 += (arr[i] - 1) / (mid + 1);
  }
  if (sum2 <= k) {
    cout << mid - 1 << endl;
  } else if (sum <= k)
    cout << mid << endl;
  else
    cout << mid + 1 << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define mp make_pair
#define pb push_back
#define pll pair<ll, ll>
ll INF = 1000000007;

//-----------------//
#define amin main
//-----------------//

int amin() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll t, i, j;
  ll n;
  cin >> n;
  ll k;
  cin >> k;
  ll arr[n];
  for (i = 0; i < n; i++)
    cin >> arr[i];
  ll low = 1;
  ll high = 1e9 + 2;
  ll mid = 0;
  while (low <= high) {
    mid = (low + high) / 2;
    // bin(mid);

    ll sum = 0;
    for (i = 0; i < n; i++) {
      sum += (arr[i] - 1) / mid;
    }
    if (sum <= k) {
      high = mid;
    } else if (sum >= k) {
      low = mid;
    }

    // cout<<mid<<" "<<sum<<endl;
  }
  ll sum = 0;
  ll sum2 = 0;
  for (i = 0; i < n; i++) {
    if (mid - 1 > 0)
      sum2 += (arr[i] - 1) / (mid - 1);
  }
  ll sum1 = 0;

  for (i = 0; i < n; i++) {
    sum += (arr[i] - 1) / mid;
  }
  // ll sum1 = 0;
  // ll sum = 0;
  for (i = 0; i < n; i++) {
    sum1 += (arr[i] - 1) / (mid + 1);
  }
  if (sum2 <= k) {
    cout << mid - 1 << endl;
  } else if (sum <= k)
    cout << mid << endl;
  else
    cout << mid + 1 << endl;

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

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

#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define int long long

#define N 2e5 + 5;

int32_t main() {
  IOS;
  int t = 1;
  // cin>>t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    int a[n];
    int l = 1, r = 0;
    for (int i = 0; i < n; ++i) {
      cin >> a[i];
      r = max(r, a[i]);
    }
    int ans = 0;
    while (l <= r) {
      int mid = (l + r) / 2;
      int s = 0;
      for (int i = 0; i < n; i++) {
        s += (a[i] + mid - 1) / mid;
        s -= 1;
      }
      if (s <= k) {
        ans = mid;
        r = mid - 1;
      } else {
        l = mid + 1;
      }
    }
    cout << ans;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define int long long

#define N 2e5 + 5;

int32_t main() {
  IOS;
  int t = 1;
  // cin>>t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    int a[n];
    int l = 1, r = 0;
    for (int i = 0; i < n; ++i) {
      cin >> a[i];
      r = max(r, a[i]);
    }
    for (int i = 0; i < 200000; i++) {
      int mid = (l + r) / 2;
      int s = 0;
      for (int i = 0; i < n; i++) {
        s += (a[i] + mid - 1) / mid;
        s -= 1;
      }
      if (s <= k) {
        r = mid;
      } else {
        l = mid;
      }
    }
    cout << r;
  }
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
const int N = 2e5 + 5, INF = 2e9;
using namespace std;
template <typename tp> inline void r(tp &n) {
  n = 0;
  char c = getchar();
  while (!isdigit(c))
    c = getchar();
  while (isdigit(c))
    n = n * 10 + c - 48, c = getchar();
}
int n, k;
int a[N];
bool OK(int cur) {
  int ret = 0;
  for (int i = 1; i <= n; ++i)
    ret += ((a[i] - 1) / cur);
  return ret <= k;
}
int main() {

  int L = 1, R = 0;
  r(n), r(k);
  for (int i = 1; i <= n; ++i)
    r(a[i]), R = max(R, a[i]);
  while (L <= R) {
    int mid = L + R >> 1;
    if (OK(mid))
      R = mid - 1;
    else
      L = mid + 1;
  }
  printf("%d\\n", R + 1);
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
const int N = 2e5 + 5, INF = 2e9;
using namespace std;
template <typename tp> inline void r(tp &n) {
  n = 0;
  char c = getchar();
  while (!isdigit(c))
    c = getchar();
  while (isdigit(c))
    n = n * 10 + c - 48, c = getchar();
}
int n, k;
int a[N];
bool OK(int cur) {
  int ret = 0;
  for (int i = 1; i <= n; ++i)
    ret += ((a[i] - 1) / cur);
  return ret <= k;
}
int main() {

  int L = 0, R = 0;
  r(n), r(k);
  for (int i = 1; i <= n; ++i)
    r(a[i]), R = max(R, a[i]);
  while (L <= R) {
    int mid = L + R >> 1;
    if (OK(mid))
      R = mid - 1;
    else
      L = mid + 1;
  }
  printf("%d\\n", R + 1);
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

#define lld long long int
#include <bits/stdc++.h>
using namespace std;
lld n, k;
lld a[200001];

lld fin(lld num, lld length) {
  lld start = 1, end = 1000000000, ans;
  while (start <= end) {
    double mid = start + (end - start) / 2;
    if (ceil(num / mid) <= length) {
      ans = mid - 1;
      end = mid - 1;
    } else {
      start = mid + 1;
    }
  }
  return ans;
}

bool isPossible(lld length) {
  lld times = 0;
  for (lld i = 0; i < n; i++) {
    if (a[i] < length) {
      continue;
    } else {

      times = times + fin(a[i], length);
      // cout<<"in = "<<times<<endl;
      if (times > k) {
        return false;
      }
    }
    // cout<<"i = "<<i<<" times = "<<times<<endl;
  }
  return true;
}

int main() {
  cin >> n >> k;
  lld m = 0;
  for (lld i = 0; i < n; i++) {
    cin >> a[i];
    m = max(m, a[i]);
  }
  lld start = 1, end = m, ans;
  while (start <= end) {
    lld mid = start + (end - start) / 2;
    // cout<<"mid = "<<mid<<endl;
    if (isPossible(mid)) {
      // cout<<"ans = "<<mid<<endl;
      ans = mid;
      end = mid - 1;
    } else {
      start = mid + 1;
    }
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#define lld long long int
#include <bits/stdc++.h>
using namespace std;
lld n, k;
lld a[200001];

bool isPossible(lld length) {
  lld times = 0;
  for (lld i = 0; i < n; i++) {
    if (a[i] < length) {
      continue;
    } else {
      double cut = 1;
      // int com=
      while (ceil(a[i] / cut) > length) {
        cut++;
        times++;

        // cout<<"in = "<<times<<endl;
        if (times > k) {
          return false;
        }
        // cout<<"a[i]/cut = "<<ceil(a[i]/cut)<<endl;
        // cout<<"cut = "<<cut<<endl;
      }
    }
    // cout<<"i = "<<i<<" times = "<<times<<endl;
  }
  return true;
}

int main() {
  cin >> n >> k;
  lld m = 0;
  for (lld i = 0; i < n; i++) {
    cin >> a[i];
    m = max(m, a[i]);
  }
  lld start = 1, end = m, ans;
  while (start <= end) {
    lld mid = start + (end - start) / 2;
    // cout<<"mid = "<<mid<<endl;
    if (isPossible(mid)) {
      // cout<<"ans = "<<mid<<endl;
      ans = mid;
      end = mid - 1;
    } else {
      start = mid + 1;
    }
  }
  cout << ans << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

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

#define pb push_back
#define mp make_pair
#define all(n) (n).begin(), (n).end()
#define fi first
#define se second

typedef pair<int, int> PII;
typedef long long ll;

const int MOD = 1e9 + 7;

int main() {

  ios::sync_with_stdio(0);
  cin.tie(0);

  int n, k;
  cin >> n >> k;
  int a[200000], ans = 0;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  ll lo = 0, hi = 1e9;
  while (lo <= hi) {
    int mid = (lo + hi) / 2;
    int cuts = 0;
    if (mid == 0) {
      cout << 1 << "\\n";
      return 0;
    }
    for (int i = 0; i < n; i++) {
      cuts += (a[i] - 1) / mid;
      if (cuts > k)
        break;
    }
    if (cuts <= k)
      ans = mid, hi = mid - 1;
    else
      lo = mid + 1;
  }
  cout << ans << "\\n";
}

Error: 0

Fixed submission:

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

#define pb push_back
#define mp make_pair
#define all(n) (n).begin(), (n).end()
#define fi first
#define se second

typedef pair<int, int> PII;
typedef long long ll;

const int MOD = 1e9 + 7;

int main() {

  ios::sync_with_stdio(0);
  cin.tie(0);

  int n, k;
  cin >> n >> k;
  int a[200000], ans = 0;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  ll lo = 0, hi = 1e9;
  while (lo <= hi) {
    int mid = (lo + hi) / 2;
    int cuts = 0;
    for (int i = 0; i < n; i++) {
      cuts += (a[i] - 1) / mid;
      if (cuts > k)
        break;
    }
    if (cuts <= k)
      ans = mid, hi = mid - 1;
    else
      lo = mid + 1;
  }
  cout << ans << "\\n";
}