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

#include <bits/stdc++.h>

#pragma GCC optimize("Ofast", "unroll-loops", "omit-frame-pointer",            \\
                     "inline") // Optimization flags
#pragma GCC option("arch=native", "tune=native", "no-zero-upper") // Enable AVX
#pragma GCC target("avx2")                                        // Enable AVX

using namespace std;

#define F first
#define S second

#ifdef __debug_leywar
#include <debug/debugger.h>
#else
#define db(...) ;
#endif

#define int long long

int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  long long k;
  cin >> n >> k;

  vector<int> ar(n + 1);

  for (int i = 1; i <= n; i++) {
    cin >> ar[i];
  }

  int ans = 0;

  for (int i = (1 << 30); i >= 1; i /= 2) {
    int target = ans + i;
    long long sc = 0;

    for (int j = 1; j <= n; j++) {
      if (ar[j] <= target)
        continue;
      else
        sc += ((ar[j] + target - 1) / target) - 1;
    }

    if (sc > k)
      ans = target;
  }

  cout << ans + 1;

  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>

#pragma GCC optimize("Ofast", "unroll-loops", "omit-frame-pointer",            \\
                     "inline") // Optimization flags
#pragma GCC option("arch=native", "tune=native", "no-zero-upper") // Enable AVX
#pragma GCC target("avx2")                                        // Enable AVX

using namespace std;

#define F first
#define S second

#ifdef __debug_leywar
#include <debug/debugger.h>
#else
#define db(...) ;
#endif

int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  long long k;
  cin >> n >> k;

  vector<int> ar(n + 1);

  for (int i = 1; i <= n; i++) {
    cin >> ar[i];
  }

  int ans = -1;

  for (int i = (1 << 30); i >= 1; i /= 2) {
    int target = ans + i;
    long long sc = 0;

    for (int i = 1; i <= n; i++) {
      if (ar[i] <= target)
        continue;
      else
        sc += ((ar[i] + target - 1) / target) - 1;
    }

    if (sc > k)
      ans = target;
  }

  cout << ans + 1;

  return 0;
}
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 < 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;
}


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: 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])-1/len);
  }
  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
  // for(int i=0;i<35;i++)//OK log2(10^9)
  // while(((long long)(r)-(long long)(l)) > 1)
  // while(!((ceil(r)-ceil(l)) ==
  // 0))//https://atcoder.jp/contests/abc174/submissions/15672399
  while (!((floor(r) - floor(l)) ==
           0)) // https://atcoder.jp/contests/abc174/submissions/15672399
  {
    // long double mid=(l+r+0.1)/2;
    long double mid = (l + r) / 2;
    //  cout<<l<<" "<<r<<" "<<mid<<endl;
    if (Count(mid) <= K)
      r = mid;
    else
      l = mid;
    // else	l=mid+0.01;
  }
  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: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int read() {
  int x;
  scanf("%d", &x);
  return x;
}
const int maxn = 3e5 + 10;
const int INF = 1e9;
int mod = 1e9 + 7;
using namespace std;
int n, k;
double a[maxn];
const double eps = 1e-6;
bool check(double mid) {
  double G = 0;
  for (int i = 1; i <= n; ++i)
    G += ceil(a[i] / mid);
  return G <= k + n;
}
int main() {
#ifdef LOCAL
  freopen("1.in", "r", stdin);
#endif
  n = read(), k = read();
  for (int i = 1; i <= n; ++i)
    a[i] = read();
  double L = 0, R = 1e9;
  double ans = 0;
  while (L + eps < R) {
    double mid = (L + R) / 2.0;
    if (check(mid))
      ans = mid, R = mid;
    else
      L = mid;
  }
  //	printf("%.10f\\n", ans);
  //	cout << check(ans) << endl;
  //	cout << "C5=" << ceil(5.0) << endl;
  printf("%.0f", ceil(L));
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int read() {
  int x;
  scanf("%d", &x);
  return x;
}
const int maxn = 3e5 + 10;
const int INF = 1e9;
int mod = 1e9 + 7;
using namespace std;
int n, k;
double a[maxn];
const double eps = 1e-10;
bool check(double mid) {
  double G = 0;
  for (int i = 1; i <= n; ++i)
    G += ceil(a[i] / mid);
  return G <= k + n;
}
int main() {
#ifdef LOCAL
  freopen("1.in", "r", stdin);
#endif
  n = read(), k = read();
  for (int i = 1; i <= n; ++i)
    a[i] = read();
  double L = 0, R = 1e9;
  double ans = 0;
  while (L + eps < R) {
    double mid = (L + R) / 2.0;
    if (check(mid))
      ans = mid, R = mid;
    else
      L = mid;
  }
  //	printf("%.10f\\n", ans);
  //	cout << check(ans) << endl;
  //	cout << "C5=" << ceil(5.0) << endl;
  printf("%.0f", ceil(ans - 1e-6));
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

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

#define ll long long
//~ #define endl '\\n'

void solve() {
  int n, k;
  cin >> n >> k;
  vector<ll> v(n);
  for (ll &i : v)
    cin >> i;
  ll l = 1, r = 1000000001;
  ll ans = r;
  while (l != r) {
    ll mid = (l + r) / 2;
    ll j = k;
    for (int i = 0; i < n; i++) {
      j -= (v[i] - 1) / mid;
    }
    if (j >= 0) {
      r = mid;
      ans = mid;
    } else {
      l = mid + 1;
    }
  }
  cout << ans << endl;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1; // cin>>t;
  while (t--) {
    solve();
  }
  return 0;
}


Error: 0

Fixed submission:

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

#define ll long long
//~ #define endl '\\n'

void solve() {
  int n, k;
  cin >> n >> k;
  vector<ll> v(n);
  for (ll &i : v)
    cin >> i;
  ll l = 0, r = 1000000005;
  ll ans = r;
  while (l != r) {
    ll mid = (l + r) / 2;
    ll j = k;
    for (int i = 0; i < n; i++) {
      j -= (v[i] - 1) / mid;
    }
    if (j >= 0) {
      r = mid;
      ans = min(ans, mid);
    } else {
      l = mid + 1;
    }
  }
  cout << ans << endl;
}

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

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

#define ll long long
// #define endl '\\n'

void max_self(int &a, int b) { a = max(a, b); }
void min_self(int &a, int b) { a = min(a, b); }

int n, k;
vector<int> v;

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

void solve() {
  cin >> n >> k;
  v.resize(n);
  for (int &i : v)
    cin >> i;
  int l = 0;   // bad
  int r = 1e9; // good

  while (r > l + 1) {
    int mid = (l + r) / 2;
    if (good(mid)) {
      r = mid;
    } else {
      l = mid;
    }
  }
  cout << r << endl;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1; // cin>>t;
  for (int i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}


Error: 0

Fixed submission:

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

#define ll long long
// #define endl '\\n'

void max_self(int &a, int b) { a = max(a, b); }
void min_self(int &a, int b) { a = min(a, b); }

int n, k;
vector<int> v;

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

void solve() {
  cin >> n >> k;
  v.resize(n);
  for (int &i : v)
    cin >> i;
  int l = -1;  // bad
  int r = 1e9; // good

  while (r > l + 1) {
    int mid = (l + r) / 2;
    if (good(mid)) {
      r = mid;
    } else {
      l = mid;
    }
  }
  cout << r << endl;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1; // cin>>t;
  for (int i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

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

typedef long long LL;
typedef unsigned long long ULL;

const int PI = 3.141592653589793;
const int inf = 1000111222;
const int mod = 1000000007;
const int N = 200007;

int main() {

  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

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

  auto check = [&](int x) {
    LL s = 0;
    for (int z : ar) {
      s += (z + x - 1) / x - 1;
    }
    return s <= k;
  };
  int l = 0, r = *max_element(ar.begin(), ar.end()) + 1;
  while (l < r - 1) {
    int m = (l + r) / 2;
    if (check(m))
      r = m;
    else
      l = m;
  }
  cout << r << "\\n";
  return 0;
}


Error: 0

Fixed submission:

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

typedef long long LL;
typedef unsigned long long ULL;

const int PI = 3.141592653589793;
const int inf = 1000111222;
const int mod = 1000000007;
const int N = 200007;

int main() {

  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

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

  auto check = [&](int x) {
    LL s = 0;
    if (x == 1) {
      for (int z : ar) {
        s += (z - 1);
      }
      return s <= k;
    }
    for (int z : ar) {
      s += (z + x - 1) / x - 1;
    }
    return s <= k;
  };
  int l = 0, r = *max_element(ar.begin(), ar.end());
  while (l < r) {
    int m = (l + r) / 2;
    if (check(m))
      r = m;
    else
      l = m + 1;
  }
  cout << r << "\\n";
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  } else {
    return false;
  }
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  } else {
    return false;
  }
}
#define ll long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, n) for (int i = 1; i <= (n); i++)
#define mod (ll)(1e9 + 7)
#define inf (ll)(3e18 + 7)
#define pi (double)acos(-1.0)
#define P pair<int, int>
#define PiP pair<ll, pair<ll, ll>>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using namespace std;

ll n, k;
vector<ll> a(1000100);

int check(ll x) {
  ll ans = 0;
  rep(i, n) { ans += ((a[i] + x - 1) / x) - 1; }
  return ans;
}

int main() {
  cin >> n >> k;
  rep(i, n) cin >> a[i];
  ll ng = 0, ok = mod;
  while (ok - ng > 1) {
    ll mid = (ok + ng) / 2;
    if (check(mid) <= k)
      ok = mid;
    else
      ng = mid;
  }
  cout << ok << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  } else {
    return false;
  }
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  } else {
    return false;
  }
}
#define ll long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, n) for (int i = 1; i <= (n); i++)
#define mod (ll)(1e9 + 7)
#define inf (ll)(3e18 + 7)
#define pi (double)acos(-1.0)
#define P pair<int, int>
#define PiP pair<ll, pair<ll, ll>>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using namespace std;

ll n, k;
vector<ll> a(100010);

int check(ll x) {
  ll ans = 0;
  rep(i, n) {
    if (a[i] <= x)
      continue;
    ans += (a[i] + x - 1) / x - 1;
  }
  return ans;
}

int main() {
  cin >> n >> k;
  rep(i, n) cin >> a[i];
  ll ok = mod, ng = 1;
  while (ok - ng > 1) {
    ll mid = (ok + ng) / 2;
    if (check(mid) <= k)
      ok = mid;
    else
      ng = mid;
  }
  cout << ok << endl;
}
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<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;
}

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>
#include <string>
using namespace std;
#define ll long long
#define endl "\\n"
#define print_array(name, n)                                                   \\
  for (ll o = 0; o < n; o++)                                                   \\
  cout << name[o] << " "
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 2e18
#define pll pair<ll, ll>
#define pii pair<int, int>
bool sortbysecond(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.ss > b.ss);
}

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

template <typename T> string NumberTostring(T Number) {
  ostringstream ss;
  ss << Number;
  return ss.str();
}

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ll n, k;
  cin >> n >> k;
  vector<ll> vec(n);
  ll mx = 0;
  for (int i = 0; i < n; i++) {
    cin >> vec[i];
    if (mx < vec[i]) {
      mx = vec[i];
    }
  }
  ll low = 1;
  ll high = mx;
  ll ans = 0;
  while (low <= high) {
    ll mid = (high + low) / 2;
    ll temp = 0;
    for (int i = 0; i < n; i++) {
      if (vec[i] <= mid) {
        continue;
      }
      temp += (vec[i] + mid - 1) / mid - 1;
    }
    // cout<<mid<<" "<<temp<<endl;
    if (temp <= k) {
      high = mid - 1;
      ans = mid;
    } else {
      low = mid + 1;
    }
  }
  cout << ans << endl;
  return 0;
}

Error: -6
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc


Fixed submission:

#include <bits/stdc++.h>
#include <string>
using namespace std;
#define ll long long
#define endl "\\n"
#define print_array(name, n)                                                   \\
  for (ll o = 0; o < n; o++)                                                   \\
  cout << name[o] << " "
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 2e18
#define pll pair<ll, ll>
#define pii pair<int, int>
bool sortbysecond(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.ss > b.ss);
}

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

template <typename T> string NumberTostring(T Number) {
  ostringstream ss;
  ss << Number;
  return ss.str();
}

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ll n, k;
  cin >> n >> k;
  vector<ll> vec(n);
  ll mx = 0;
  for (int i = 0; i < n; i++) {
    cin >> vec[i];
    if (mx < vec[i]) {
      mx = vec[i];
    }
  }
  ll low = 0;
  ll high = mx;
  ll ans = 0;
  while (low <= high) {
    ll mid = low + (high - low) / 2;
    ll temp = 0;
    for (int i = 0; i < n; i++) {
      if (vec[i] <= mid) {
        continue;
      }
      temp += (vec[i] + mid - 1) / mid - 1;
    }
    // cout<<mid<<" "<<temp<<endl;
    if (temp <= k) {
      high = mid - 1;
      ans = mid;
    } else {
      low = mid + 1;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define pb push_back
#define mk make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fr(j, i, n) for (int i = j; i < n; ++i)
#define frr(j, i, n) for (int i = j; i <= n; ++i)
using namespace std;
void solve() {
  ll n, k;
  cin >> n >> k;
  ll a[n + 1];
  frr(1, i, n) cin >> a[i];
  ll left = 1, right = 1e9;
  ll ans = 1e10;
  while (left <= right) {
    ll moves = 0;
    ll mid = (left + right) / 2ll;
    frr(1, i, n) {
      if (a[i] % mid == 0)
        moves += ((a[i] / mid) - 1ll);
      else
        moves += (a[i] / mid);
    }
    if (moves > k)
      left = mid + 1ll;
    else
      ans = min(mid, ans), right = mid - 1ll;
  }
  cout << ans << "\\n";
}
int main() {
  // #ifndef ONLINE_JUDGE
  // 	freopen("input.txt","r",stdin);
  // 	freopen("output.txt","w",stdout);
  // #endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  // t=1;
  // cin>>t;
  while (t--)
    solve();
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define pb push_back
#define mk make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fr(j, i, n) for (int i = j; i < n; ++i)
#define frr(j, i, n) for (int i = j; i <= n; ++i)
using namespace std;
void solve() {
  ll n, k;
  cin >> n >> k;
  ll a[n + 1];
  frr(1, i, n) cin >> a[i];
  ll left = 0, right = 1e9;
  ll ans = 1e10;
  while (left <= right) {
    ll moves = 0;
    ll mid = (left + right) / 2ll;
    frr(1, i, n) {
      if (a[i] % mid == 0)
        moves += ((a[i] / mid) - 1ll);
      else
        moves += (a[i] / mid);
    }
    if (moves > k)
      left = mid + 1ll;
    else
      ans = min(mid, ans), right = mid - 1ll;
  }
  cout << ans << "\\n";
}
int main() {
  // #ifndef ONLINE_JUDGE
  // 	freopen("input.txt","r",stdin);
  // 	freopen("output.txt","w",stdout);
  // #endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  // t=1;
  // cin>>t;
  while (t--)
    solve();
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
bool valid(vector<int> &a, int len, int k, int n) {
  int count = 0;
  for (int i = 0; i < n; i++) {
    count += (a[i] + len - 1) / len - 1;
    if (count > k)
      return false;
  }
  return count <= k;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, k;
  cin >> n >> k;
  vector<int> a(n, 0);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a.begin(), a.end(), greater<int>());
  int l = 1, r = a[0], ans = a[0];
  if (k == 0)
    cout << ans;
  else {
    while (l <= r) {
      int mid = l + (r - l) / 2;
      if (valid(a, mid, k, n))
        ans = mid, r = mid - 1;
      else
        l = mid + 1;
    }
    cout << ans;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
bool valid(priority_queue<int> pq, int len, int k) {
  while (k--) {
    int x = pq.top();
    pq.pop();
    pq.push(len), pq.push(x - len);
    if (x < len || pq.top() <= len)
      return true;
  }
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, k, minn = INT_MAX;
  cin >> n >> k;
  priority_queue<int> pq;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    minn = min(minn, x);
    pq.push(x);
  }
  int l = 1, r = pq.top(), ans = r;
  if (k == 0)
    cout << ans;
  else {
    while (l <= r) {
      int mid = l + (r - l) / 2;
      if (valid(pq, mid, k))
        ans = mid, r = mid - 1;
      else
        l = mid + 1;
    }
    cout << ans;
  }
  return 0;
}