1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  size_t N;
  cin >> N;

  map<int, int> cnt_map;

  for (int _ = 0; _ < N; _++) {
    int x;
    cin >> x;
    cnt_map[x]++;
  }

  vector<int> amounts;
  amounts.reserve(cnt_map.size());
  for (const auto& [k, v] : cnt_map) {
    amounts.push_back(v);
  }

  sort(amounts.begin(), amounts.end(), greater<int>());

  int result = 0;
  int capacity = 0;
  for (auto x : amounts) {
    result += 1;
    capacity += x + (x - 1);

    if (capacity >= N) break;
  }

  cout << result << "\n";
}