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
#include  <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map> 

using namespace std;

int main(){
    int n;
    unordered_map<int, int> umap;
    cin >> n;

    int a;
    for(int i = 0; i < n; i++){
        cin >> a;
        if(umap.find(a)==umap.end()){
            umap[a] = 1;
        }else{
            umap[a]++;
        }
    }

    vector<int> nums;
    unordered_map<int, int>::iterator itr;
    for (itr = umap.begin();itr != umap.end(); itr++){
        nums.push_back(itr->second);
    }

    sort(nums.begin(), nums.end());
    reverse(nums.begin(), nums.end());
    for(int i = 0; i < nums.size(); i++){
        n -= ((nums[i]*2)-1);
        if(n<=0){
            cout << i+1 << "\n";
            return 0;
        }
    }

    return 0;
}