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
#include <bits/stdc++.h>
using namespace std;
int n;
vector < int > v;
int t[500005];
int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; ++i)
    {
        int k;
        scanf("%d", &k);
        ++t[k];
    }
    for (int i = 0; i <= n; ++i)
    {
        if (t[i] != 0)
            v.push_back(t[i]);
    }
    sort(v.begin(), v.end());
    int x = n;
    for (int i = v.size() - 1; i > -1; --i)
    {
        x -= 2  * v[i] - 1;
        if (x <= 0)
        {
            printf("%d", v.size() - i);
            return 0;
        }
    }
}