#include <iostream>
constexpr int MAX_N = 500001;
int a[MAX_N], b[MAX_N];
int main()
{
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
int n;
std::cin >> n;
for(int i = 0; i < n; ++i)
std::cin >> a[i];
for(int i = 0; i < n; ++i)
++b[a[i]],
a[i] = 0;
for(int i = 0; i <= n; ++i)
++a[b[i]];
int sum = 0, res = 0;
for(int i = n; i > 0 && sum < n; --i)
for(int j = 0; j < a[i] && sum < n; ++j)
sum += 2*i-1,
++res;
std::cout << res << '\n';
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 | #include <iostream> constexpr int MAX_N = 500001; int a[MAX_N], b[MAX_N]; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); int n; std::cin >> n; for(int i = 0; i < n; ++i) std::cin >> a[i]; for(int i = 0; i < n; ++i) ++b[a[i]], a[i] = 0; for(int i = 0; i <= n; ++i) ++a[b[i]]; int sum = 0, res = 0; for(int i = n; i > 0 && sum < n; --i) for(int j = 0; j < a[i] && sum < n; ++j) sum += 2*i-1, ++res; std::cout << res << '\n'; return 0; } |
English