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

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

	int n;
	cin >> n;

	int arr[n], sum = 0;
	for(int& i : arr)
		cin >> i;

	sort(arr, arr+n);
	vector<int> vec = {1};
	for(int i = 1; i < n; ++i) {
		if(arr[i] > arr[i-1]) vec.push_back(1);
		else vec.back()++;
	}

	sort(vec.rbegin(), vec.rend());
	auto i = vec.cbegin();
	for(; i != vec.cend() && sum <= (n-1)/2+1; ++i)
		sum += *i;
	cout << max<long>(i - vec.cbegin(), 1);
}