#include <cstdio> #include <algorithm> #include <vector> int main() { int N; scanf("%d", &N); std::vector<int> counts; counts.resize(N + 1); for (int i = 0; i < N; ++i) { int t; scanf("%d", &t); counts[t]++; } std::sort(counts.begin(), counts.end(), std::greater<int>()); int result = 0; int toConsume = N; for (int i = 0; i < N && toConsume; ++i) { ++result; int cnt = counts[i]; cnt += cnt / 2; // rest; toConsume -= std::min(toConsume, cnt); } printf("%d\n", result); 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 | #include <cstdio> #include <algorithm> #include <vector> int main() { int N; scanf("%d", &N); std::vector<int> counts; counts.resize(N + 1); for (int i = 0; i < N; ++i) { int t; scanf("%d", &t); counts[t]++; } std::sort(counts.begin(), counts.end(), std::greater<int>()); int result = 0; int toConsume = N; for (int i = 0; i < N && toConsume; ++i) { ++result; int cnt = counts[i]; cnt += cnt / 2; // rest; toConsume -= std::min(toConsume, cnt); } printf("%d\n", result); return 0; } |