Problem p02890 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
#include <stdlib.h>

#include <iomanip>
#include <iostream>
#include <sstream>
#include <stdint.h>
#include <string.h>

#define _USE_MATH_DEFINES
#include <math.h>

#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <algorithm>
#include <bitset>
#include <chrono>
#include <functional>
#include <random>

#define sqr(x) (x) * (x)

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long int i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

const i64 mod = 1000000007ll;
const i64 smod = 998244353ll;
const i64 inf = 10000000000000007ll;

const double eps = 1e-10;

// del

const i64 MAXN = 30005;

i64 n;
i64 m;

i64 a[MAXN];
i64 c[MAXN];
i64 ps[MAXN];

bool f(i64 k, i64 t) {
  i64 i = lower_bound(c + 1, c + m + 1, -t) - c;
  i64 s = ps[i - 1] - t * (i - 1);
  return s <= n - (k * t);
}

i64 bin(i64 k, i64 l, i64 r) {
  if (l == r) {
    return l;
  }
  if (l + 1 == r) {
    if (f(k, r)) {
      return r;
    } else {
      return l;
    }
  }

  i64 t = (l + r) / 2;
  if (f(k, t)) {
    return bin(k, t, r);
  } else {
    return bin(k, l, t);
  }
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout.precision(15);
  cout.setf(ios::fixed);

  cin >> n;

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

  for (i64 i = 0; i < n; i++) {
    c[a[i]]++;
  }

  sort(c + 1, c + n + 1, greater<i64>());

  for (i64 i = 1; i <= n; i++) {
    ps[i] = ps[i - 1] + c[i];
    if (c[i] != 0) {
      m++;
    }
  }

  for (i64 i = 1; i <= n; i++) {
    c[i] *= -1;
  }

  // i64 tt = f(3, 2);
  // cerr << tt << endl;

  stringstream ss;
  for (i64 k = 1; k <= n; k++) {
    i64 R = bin(k, 0, n / k);
    ss << R << endl;
  }

  cout << ss.str();

  return 0;
}

Fixed submission:
#include <stdio.h>
#include <stdlib.h>

#include <iomanip>
#include <iostream>
#include <sstream>
#include <stdint.h>
#include <string.h>

#define _USE_MATH_DEFINES
#include <math.h>

#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <algorithm>
#include <bitset>
#include <chrono>
#include <functional>
#include <random>

#define sqr(x) (x) * (x)

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long int i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

const i64 mod = 1000000007ll;
const i64 smod = 998244353ll;
const i64 inf = 10000000000000007ll;

const double eps = 1e-10;

// del

const i64 MAXN = 300005;

i64 n;
i64 m;

i64 a[MAXN];
i64 c[MAXN];
i64 ps[MAXN];

bool f(i64 k, i64 t) {
  i64 i = lower_bound(c + 1, c + m + 1, -t) - c;
  i64 s = ps[i - 1] - t * (i - 1);
  return s <= n - (k * t);
}

i64 bin(i64 k, i64 l, i64 r) {
  if (l == r) {
    return l;
  }
  if (l + 1 == r) {
    if (f(k, r)) {
      return r;
    } else {
      return l;
    }
  }

  i64 t = (l + r) / 2;
  if (f(k, t)) {
    return bin(k, t, r);
  } else {
    return bin(k, l, t);
  }
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout.precision(15);
  cout.setf(ios::fixed);

  cin >> n;

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

  for (i64 i = 0; i < n; i++) {
    c[a[i]]++;
  }

  sort(c + 1, c + n + 1, greater<i64>());

  for (i64 i = 1; i <= n; i++) {
    ps[i] = ps[i - 1] + c[i];
    if (c[i] != 0) {
      m++;
    }
  }

  for (i64 i = 1; i <= n; i++) {
    c[i] *= -1;
  }

  // i64 tt = f(3, 2);
  // cerr << tt << endl;

  stringstream ss;
  for (i64 k = 1; k <= n; k++) {
    i64 R = bin(k, 0, n / k);
    ss << R << endl;
  }

  cout << ss.str();

  return 0;
}