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

#include <algorithm>
#include <array>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <ctime>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using llint = long long int;
using u64 = std::uint_fast64_t;

void solve(void) {

  llint n, k;
  std::cin >> n >> k;

  std::vector<llint> A(n);
  llint longest = 0;
  for (int i = 0; i < n; i++) {
    std::cin >> A[i];
    longest = std::max(longest, A[i]);
  }

  llint st = 0;
  llint ed = longest;
  while (st < ed - 1) {
    // std::cout << st << " " << ed << std::endl;
    llint mid = (ed + st) / 2;
    llint cnt = 0;
    for (int i = 0; i < n; i++) {
      // std::cout << cnt << " & " << A[i] << std::endl;
      cnt += (A[i] - 1) / mid;
    }
    if (k < cnt)
      st = mid;
    else
      ed = mid;
  }

  llint cnt = 0;
  for (int i = 0; i < n; i++) {
    cnt += (A[i] - 1) / ed;
  }
  if (k >= cnt)
    std::cout << ed << std::endl;
  else
    std::cout << st << std::endl;
}
int main(void) {
  solve();
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <array>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <ctime>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using llint = long long int;
using u64 = std::uint_fast64_t;

void solve(void) {

  llint n, k;
  std::cin >> n >> k;

  std::priority_queue<std::array<llint, 3>> A;
  for (int i = 0; i < n; i++) {
    std::array<llint, 3> tmp;
    std::cin >> tmp[1];
    tmp[2] = 1;
    tmp[0] = tmp[1];
    A.push(tmp);
  }

  for (int i = 0; i < k; i++) {
    auto a = A.top();
    if (a[0] == 1)
      break;
    A.pop();
    a[2]++;
    a[0] = (a[1] + a[2] - 1) / a[2];
    A.push(a);
  }

  auto a = A.top();
  std::cout << a[0] << std::endl;
}
int main(void) {
  solve();
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

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

const long long mod = 1e9 + 7;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-10)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main() {
  int n, k;
  cin >> n >> k;
  vi a(n);
  rep(i, n) cin >> a[i];
  int mx = 0;
  rep(i, n) mx = max(mx, a[i]);
  double l = 0.0, r = mx;
  while (fabs(r - l) >= 1e-6) {
    double c = (l + r) / 2.0;
    ll sum = 0;
    rep(i, n) sum += (ll)(a[i] / c);
    if (sum > k)
      l = c;
    else
      r = c;
  }
  cout << (ll)ceil(l) << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

const long long mod = 1e9 + 7;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-10)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main() {
  int n, k;
  cin >> n >> k;
  vi a(n);
  rep(i, n) cin >> a[i];
  int mx = 0;
  rep(i, n) mx = max(mx, a[i]);
  double l = 0.0, r = mx;
  while (fabs(r - l) >= 1e-7) {
    double c = (l + r) / 2.0;
    ll sum = 0;
    rep(i, n) sum += (a[i] - EPS) / c;
    if (sum > k)
      l = c;
    else
      r = c;
  }
  ll ans = l + 0.999999;
  cout << ans << endl;
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define REP(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;
vector<ll> v(10000000);
ll b;
bool C(ll num) {
  ll sum = 0;
  rep(i, v.size()) {
    if (v[i] > num) {
      sum += v[i] / num;
      if (!(v[i] % num))
        sum--;
    }
  }
  return (b < sum);
}
bool hantei(ll num) {
  if (num == 0)
    return true;
  ll sum = 0;
  rep(i, v.size()) {
    if (v[i] > num) {
      sum += v[i] / num;
      if (!(v[i] % num))
        sum--;
    }
  }
  if (sum <= b)
    return true;
  else
    return false;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll a, c, d, m, n, maxi = 0, f = 0, mini = INF, sum = 0;
  string str;
  cin >> n >> b;
  priority_queue<long double> q;
  // vector<vector<ll>> v(tate,vector<ll> (yoko));
  v.resize(n);
  rep(i, n) { cin >> v[i]; }
  if (b == 0) {
    maxi = v[n - 1];
    rep(i, n - 1) { maxi = max(maxi, v[i]); }
    cout << maxi << endl;
    return 0;
  }
  ll ub = 10e9 + 1;
  ll lb = 0;
  for (ll i = 0; i < 100; i++) {
    ll mid = (lb + ub) / 2;
    if (mid == 0)
      continue;
    if (C(mid))
      lb = mid;
    else
      ub = mid;
  }
  if (hantei(ub))
    cout << ub << endl;
  else
    cout << lb << endl;
  // cout<<"ub "<<ub<<" lb "<<lb<<endl;

  return 0;
}


Error: 0

Fixed submission:

// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define REP(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;
vector<ll> v(10000000);
ll b;
bool C(ll num) {
  ll sum = 0;
  rep(i, v.size()) {
    if (v[i] > num) {
      sum += v[i] / num;
      if (!(v[i] % num))
        sum--;
    }
  }
  return (b < sum);
}
bool hantei(ll num) {
  ll sum = 0;
  rep(i, v.size()) {
    if (v[i] > num) {
      sum += v[i] / num;
      if (!(v[i] % num))
        sum--;
    }
  }
  if (sum <= b)
    return true;
  else
    return false;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll a, c, d, m, n, maxi = 0, f = 0, mini = INF, sum = 0;
  string str;
  cin >> n >> b;
  priority_queue<long double> q;
  // vector<vector<ll>> v(tate,vector<ll> (yoko));
  v.resize(n);
  rep(i, n) { cin >> v[i]; }
  if (b == 0) {
    maxi = v[n - 1];
    rep(i, n - 1) { maxi = max(maxi, v[i]); }
    cout << maxi << endl;
    return 0;
  }
  ll ub = 10e9 + 1;
  ll lb = 0;
  for (ll i = 0; i < 10000; i++) {
    ll mid = (lb + ub) / 2;
    if (C(mid))
      lb = mid;
    else
      ub = mid;
  }
  if (hantei(ub))
    cout << ub << endl;
  else
    cout << lb << endl;
  // cout<<"ub "<<ub<<" lb "<<lb<<endl;

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

#include <bits/stdc++.h>
#define ll long long int
#define uu first
#define vv second
#define pii pair<int, int>
#define pdp pair<double, pii>
#define pll pair<ll, ll>
#define fastio                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
using namespace std;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int N = 1e6 + 6;

int main() {
  fastio;
  int n, k;
  cin >> n >> k;
  vector<int> vec(n);
  for (int i = 0; i < n; i++)
    cin >> vec[i];

  int lo = 1, hi = INF, ret = -1;

  while (lo <= hi) {
    int mid = (lo + hi) / 2;

    int cnt = 0;

    for (auto x : vec) {
      cnt += (x - 1) / mid + 1 - 1;
    }

    if (cnt > k) {
      lo = mid + 1;
    } else {
      ret = mid;
      hi = mid - 1;
    }
  }
  cout << ret << '\\n';
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
#define uu first
#define vv second
#define pii pair<int, int>
#define pdp pair<double, pii>
#define pll pair<ll, ll>
#define fastio                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
using namespace std;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int N = 1e6 + 6;

int main() {
  fastio;
  int n, k;
  cin >> n >> k;
  vector<int> vec(n);
  for (int i = 0; i < n; i++)
    cin >> vec[i];

  int lo = 0, hi = INF, ret = -1;

  while (lo <= hi) {
    int mid = (lo + hi) / 2;

    int cnt = 0;

    for (auto x : vec) {
      cnt += (x - 1) / mid + 1 - 1;
    }

    if (cnt > k) {
      lo = mid + 1;
    } else {
      ret = mid;
      hi = mid - 1;
    }
  }
  cout << ret << '\\n';
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define per(i, a, b) for (int i = a; i >= b; --i)
#define mem0(x) memset(x, 0, sizeof(x))
#define meminf(x) memset(x, 0x3f, sizeof(x))
#define VI vector<int>
#define VL vector<ll>
using namespace std;

double a[200005];
int n, k;

int check(double x) {
  ll cnt = 0;
  rep(i, 1, n) {
    cnt += (ll)(a[i] / x);
    if (fabs(a[i] - (ll)(a[i] / x) * x) <= 0.1) {
      --cnt;
    }
  }
  return cnt > k;
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> k;

  double l = 1, r = 0;
  rep(i, 1, n) {
    cin >> a[i];
    r = max(r, a[i]);
  }
  int cnt = 0;
  while (cnt++ < 100) {
    double mid = (l + r) / 2;
    if (check(mid)) {
      l = mid + 0.01;
    } else {
      r = mid;
    }
  }
  cout << (ll)ceil(l);
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define per(i, a, b) for (int i = a; i >= b; --i)
#define mem0(x) memset(x, 0, sizeof(x))
#define meminf(x) memset(x, 0x3f, sizeof(x))
#define VI vector<int>
#define VL vector<ll>
using namespace std;

double a[200005];
int n, k;

int check(double x) {
  ll cnt = 0;
  rep(i, 1, n) {
    cnt += (ll)(a[i] / x);
    if (fabs(a[i] - (ll)(a[i] / x) * x) <= 0.1) {
      --cnt;
    }
  }
  return cnt > k;
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> k;

  double l = 1, r = 0;
  rep(i, 1, n) {
    cin >> a[i];
    r = max(r, a[i]);
  }
  while (l <= r) {
    double mid = (l + r) / 2;
    if (check(mid)) {
      l = mid + 0.01;
    } else {
      r = mid;
    }
  }
  cout << (ll)ceil(l);
}
Problem p02598 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define fo(i, n) for (ll i = 0; i < n; i++)
#define fo1(i, n) for (ll i = 1; i <= n; i++)
#define loop(i, a, b) for (ll i = a; i <= b; i++)
#define loopr(i, a, b) for (ll i = b; i >= a; i--)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
#define vll vector<ll>
#define vvl vector<vll>
#define vpll vector<pll>
#define pll pair<ll, ll>
#define F first
#define S second
#define MOD 1000000007
ll max(ll a, ll b) {
  if (a > b)
    return a;
  else
    return b;
}
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll fexp(ll a, ll b) {
  ll ans = 1;
  while (b) {
    if (b & 1)
      ans = ans * a % MOD;
    b /= 2;
    a = a * a % MOD;
  }
  return ans;
}
ll inverse(ll a, ll p) { return fexp(a, p - 2); }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll T = 1;
  // cin >> T;
  ll t = 0;
  while (t++ < T) {
    ll n, k;
    cin >> n >> k;
    vll a(n);
    fo(i, n) cin >> a[i];
    ll lo = 1, hi = *max_element(all(a)), ans;
    ll m;
    while (lo < hi) {
      m = (lo + hi) / 2;
      ll req = 0;
      fo(i, n) {
        if (a[i] % m == 0)
          req += a[i] / m - 1;
        else
          req += a[i] / m;
      }
      if (req <= k) {
        hi = m;
      } else
        lo = m + 1;
    }
    cout << lo << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define fo(i, n) for (ll i = 0; i < n; i++)
#define fo1(i, n) for (ll i = 1; i <= n; i++)
#define loop(i, a, b) for (ll i = a; i <= b; i++)
#define loopr(i, a, b) for (ll i = b; i >= a; i--)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
#define vll vector<ll>
#define vvl vector<vll>
#define vpll vector<pll>
#define pll pair<ll, ll>
#define F first
#define S second
#define MOD 1000000007
ll max(ll a, ll b) {
  if (a > b)
    return a;
  else
    return b;
}
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll fexp(ll a, ll b) {
  ll ans = 1;
  while (b) {
    if (b & 1)
      ans = ans * a % MOD;
    b /= 2;
    a = a * a % MOD;
  }
  return ans;
}
ll inverse(ll a, ll p) { return fexp(a, p - 2); }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll T = 1;
  // cin >> T;
  ll t = 0;
  while (t++ < T) {
    ll n, k;
    cin >> n >> k;
    vll a(n);
    fo(i, n) cin >> a[i];
    ll lo = 1, hi = *max_element(all(a)), ans;
    ll m;
    while (lo <= hi) {
      m = (lo + hi) / 2;
      ll req = 0;
      fo(i, n) {
        if (a[i] % m == 0)
          req += a[i] / m - 1;
        else
          req += a[i] / m;
      }
      if (req <= k) {
        hi = m;
      } else
        lo = m + 1;
    }
    cout << lo << endl;
  }
  return 0;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

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

typedef long long ll;

ll n, l, r, k, arr[200000];

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

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

  ll mx = *max_element(arr, arr + n);

  l = 1, r = mx;
  ll ans = mx;

  while (l <= r) {
    ll m = (r + l) / 2;

    ll req = 0;

    for (int i = 0; i < n; i++)
      req += ((arr[i] + m - 1) / m) - 1;

    if (req <= k) {
      ans = m;
      r = m - 1;
    } else
      l = m + 1;
  }

  // cout<<"A";

  cout << ans;
}

Error: WA

Fixed submission:

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

typedef long long ll;

ll n, l, r, k, arr[200000];

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

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

  ll mx = *max_element(arr, arr + n);

  l = 0, r = mx;
  ll ans = 1;

  while (l <= r) {
    ll m = (r + l) / 2;

    ll req = 0;

    for (int i = 0; i < n; i++) {
      req += ((arr[i] + m - 1) / m) - 1;
    }

    if (req <= k) {
      ans = m;
      r = m - 1;
    } else
      l = m + 1;
  }

  // cout<<"A";

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

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

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

  vector<long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  long l = 0, r = *max_element(a.begin(), a.end());
  long m;
  while (r - l > 1) {
    m = (l + r) / 2;

    long count = 0;
    for (int i = 0; i < n; i++) {
      count += a[i] / m;
      if (a[i] % m == 0) {
        count--;
      }
    }
    if (count <= k) {
      r = m;
    } else {
      l = m;
    }
  }
  cout << r << endl;

  return 0;
}

Error: 0

Fixed submission:

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

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

  vector<long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  long l = -1, r = *max_element(a.begin(), a.end());
  long m;
  while (r - l > 1) {
    m = (l + r) / 2;

    long count = 0;
    for (int i = 0; i < n; i++) {
      count += a[i] / m + 1 - 1;
    }
    if (count <= k) {
      r = m;
    } else {
      l = m;
    }
  }
  cout << r << endl;

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

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define endl '\\n'
typedef pair<int, int> P;
typedef long long ll;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  ll r = 1e9;
  ll l = 0;
  vector<int> a(n);
  rep(i, n) { cin >> a[i]; }

  rep(tmp, 200) {
    ll mid = (l + r) / 2;
    if (mid == 0) {
      cout << 1 << endl;
      return 0;
    }
    int cnt = 0;
    for (auto j : a) {
      cnt += (j + mid - 1) / mid - 1;
    }
    if (cnt <= k) {
      r = mid;
    } else {
      l = mid;
    }
  }
  cout << r << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define endl '\\n'
typedef pair<int, int> P;
typedef long long ll;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  ll r = 1e9;
  ll l = 0;
  vector<int> a(n);
  rep(i, n) { cin >> a[i]; }

  rep(tmp, 200) {
    ll mid = (l + r) / 2;
    int cnt = 0;
    for (auto j : a) {
      cnt += (j + mid - 1) / mid - 1;
    }
    if (cnt <= k) {
      r = mid;
    } else {
      l = mid;
    }
  }
  cout << r << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
// void rec(int val,map<int,int>&mp,int chk)
// {
//     if(val<=chk) return 0;
//     if(mp.count(val)) return mp[val];
//     if(val>chk)
//     {
//         int l=rec((val+1)/2,mp,chk);
//         int r=rec((val)/2,mp,chk);
//         return mp[val]=l+r+1;
//     }

// }
int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a.rbegin(), a.rend());
  ll lo = 1;
  ll hi = a[0];
  // cout<<hi<<endl;
  auto chk = [&](ll val) {
    ll v = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] <= val)
        break;
      else {
        ll z = a[i];

        v += z / val;
      }
    }
    return v;
  };
  ll ans;
  // cout<<chk(4)<<endl;
  if (k == 0) {
    cout << hi << endl;
    return 0;
  }
  while (lo <= hi) {
    ll m = lo + (hi - lo) / 2;
    ll cal = chk(m);
    if (cal > k)
      lo = m + 1;
    else {
      ans = m;
      hi = m - 1;
    }
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
// void rec(int val,map<int,int>&mp,int chk)
// {
//     if(val<=chk) return 0;
//     if(mp.count(val)) return mp[val];
//     if(val>chk)
//     {
//         int l=rec((val+1)/2,mp,chk);
//         int r=rec((val)/2,mp,chk);
//         return mp[val]=l+r+1;
//     }

// }
int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a.rbegin(), a.rend());
  ll lo = 0;
  ll hi = a[0];
  // cout<<hi<<endl;
  auto chk = [&](ll val) {
    ll v = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] <= val)
        break;
      else {
        ll z = a[i];

        v += z / val;
      }
    }
    return v;
  };
  ll ans;
  // cout<<chk(4)<<endl;
  while (lo <= hi) {
    ll m = lo + (hi - lo) / 2;
    ll cal = chk(m);
    if (cal > k)
      lo = m + 1;
    else {
      ans = m;
      hi = m - 1;
    }
  }
  cout << ans << endl;
}
Problem p02598 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
#define lli long long int
#define tc                                                                     \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
#define all(x) x.begin(), x.end()
#define f first
#define s second
#define pb push_back
#define vi vector<int>
#define vll vector<lli>
#define maxn 1771562
#define mod 1000000007
#define inf 10000000

int main() {
  fastio;
  int n, k;
  cin >> n >> k;
  lli a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  lli l = 1, h = 1e9, ans;
  while (l <= h) {
    lli mid = (l + h) / 2;
    lli ca = 0;
    for (int i = 0; i < n; i++) {
      ca += a[i] / mid - 1;
      if (a[i] % mid)
        ca++;
    }
    // cout<<mid<<" "<<ca<<"\\n";
    if (ca <= k)
      ans = mid, h = mid - 1;
    else
      l = mid + 1;
  }
  cout << ans << "\\n";
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
#define lli long long int
#define tc                                                                     \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
#define all(x) x.begin(), x.end()
#define f first
#define s second
#define pb push_back
#define vi vector<int>
#define vll vector<lli>
#define maxn 1771562
#define mod 1000000007
#define inf 10000000

int main() {
  fastio;
  int n, k;
  cin >> n >> k;
  lli a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  lli l = 0, h = 1e9, ans;
  while (l <= h) {
    lli mid = (l + h) / 2;
    lli ca = 0;
    for (int i = 0; i < n; i++) {
      ca += a[i] / mid - 1;
      if (a[i] % mid)
        ca++;
    }
    // cout<<mid<<" "<<ca<<"\\n";
    if (ca <= k)
      ans = mid, h = mid - 1;
    else
      l = mid + 1;
  }
  cout << ans << "\\n";
  return 0;
}