#include <bits/stdc++.h>
using namespace std;
int amounts[500007];
vector<int> counts;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int length;
cin >> length;
for (int i = 0; i < length; ++i)
{
int number;
cin >> number;
amounts[number] += 1;
}
for (int i = 1; i <= length; ++i)
{
if (amounts[i] != 0)
counts.push_back(amounts[i]);
}
sort(counts.begin(), counts.end());
int steps = 0;
int current = 0;
while (current < length)
{
current += 2 * counts[counts.size() - 1] - 1;
counts.pop_back();
++steps;
}
cout << steps << '\n';
}
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 | #include <bits/stdc++.h> using namespace std; int amounts[500007]; vector<int> counts; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int length; cin >> length; for (int i = 0; i < length; ++i) { int number; cin >> number; amounts[number] += 1; } for (int i = 1; i <= length; ++i) { if (amounts[i] != 0) counts.push_back(amounts[i]); } sort(counts.begin(), counts.end()); int steps = 0; int current = 0; while (current < length) { current += 2 * counts[counts.size() - 1] - 1; counts.pop_back(); ++steps; } cout << steps << '\n'; } |
English