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
#include <iostream>
#include <vector>
using namespace std;

int main(){
	int minimum = 1, n;

	cin >> n;
    int suma = n;

    vector<int> liczby(n + 1, 0), ilosc(n + 1, 0);

    for(int i = 0; i < n; i++){
        int liczba;
        cin >> liczba;
        liczby[liczba]++;
    }

    int highest = 0;
    for(int i = 1; i < n + 1; i++){
        int liczba = liczby[i];
        ilosc[liczba]++;
        if (highest < liczba){
            highest = liczba;
        }
    }

    while(true){
        if(highest + highest > suma){
            cout << minimum;
            return 0;
        }

        minimum++;
        ilosc[highest]--;
        suma -= highest + highest - 1;

        while(true){
            if(ilosc[highest] > 0) break;
            highest--;
        }
    }

	return -1;
}