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
42
43
44
45
46
47
48
49
50
51
52
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;

int n;

vector<int> count_occurences(const int *t)
{
   vector<int> result;
   int c = 0, last = t[0];
   for (int i=0; i<n; ++i)
      if (t[i] == last) {
         ++c;
      } else {
         result.push_back(c);
         c = 1;
         last = t[i];
      }
   result.push_back(c);
   return result;
}

int main()
{
   scanf("%d", &n);
   int t[n];
   for (int i=0; i<n; ++i)
      scanf("%d", &t[i]);

   sort(t, t+n);
   vector<int> o = count_occurences(t);
   sort(o.begin(), o.end());

   //for (int i=0; i<o.size(); ++i)
   //   printf("%d ", o[i]);
   //printf("\n");

   int result = 0, start = 0;
   for (int i=o.size()-1; start < i; --i) {
      //printf("i = %d, start = %d\n", i, start);
      int sum = 0;
      while (start < i && sum + o[start] < o[i]) {
         sum += o[start];
         ++start;
      }
      //printf("i = %d, start = %d, sum = %d\n", i, start, sum);
      ++result;
   }
   ++result; // count start == i (end of loop condition)
   printf("%d\n", result);
}