#include <iostream>
#include <algorithm>
using namespace std;
const int MAX_N = 500001;
int inp[MAX_N];
int tmp[MAX_N];
int yep[MAX_N];
int N;
int licz()
{
for (int i = 1; i < MAX_N; i++)
{
if (inp[i] > 0) {
tmp[inp[i]]++;
}
}
int g = 0;
for (int i = MAX_N - 1; i > 0; i--) {
while(tmp[i]-->0){
yep[g++] = i;
}
}
int s = 0;
int c = 0;
while (s < N)
{
s += yep[c] * 2 - 1;
c++;
}
return c;
}
int main()
{
cin >> N;
int x;
for (int i = 0; i < N; i++)
{
cin >> x;
inp[x]++;
}
cout << licz() << endl;
return 0;
}
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 | #include <iostream> #include <algorithm> using namespace std; const int MAX_N = 500001; int inp[MAX_N]; int tmp[MAX_N]; int yep[MAX_N]; int N; int licz() { for (int i = 1; i < MAX_N; i++) { if (inp[i] > 0) { tmp[inp[i]]++; } } int g = 0; for (int i = MAX_N - 1; i > 0; i--) { while(tmp[i]-->0){ yep[g++] = i; } } int s = 0; int c = 0; while (s < N) { s += yep[c] * 2 - 1; c++; } return c; } int main() { cin >> N; int x; for (int i = 0; i < N; i++) { cin >> x; inp[x]++; } cout << licz() << endl; return 0; } |
English