// [1B] Liderzy, Kamil Debowski
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
int n;
cin >> n;
vector<int> freq(n+1);
for (int i = 0; i < n; i++) {
int x;
cin >> x;
freq[x]++;
}
sort(freq.begin(), freq.end());
int answer = 0;
int small = 0, big = n;
while (small <= big) {
if (!freq[big]) {
big--;
continue;
}
int can = freq[big] - 1;
freq[big] = 0;
while (small < big && can > 0) {
int take = min(can, freq[small]);
can -= take;
freq[small] -= take;
if (!freq[small]) {
small++;
}
}
answer++;
}
cout << answer << endl;
}
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 | // [1B] Liderzy, Kamil Debowski #include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); ios_base::sync_with_stdio(0); int n; cin >> n; vector<int> freq(n+1); for (int i = 0; i < n; i++) { int x; cin >> x; freq[x]++; } sort(freq.begin(), freq.end()); int answer = 0; int small = 0, big = n; while (small <= big) { if (!freq[big]) { big--; continue; } int can = freq[big] - 1; freq[big] = 0; while (small < big && can > 0) { int take = min(can, freq[small]); can -= take; freq[small] -= take; if (!freq[small]) { small++; } } answer++; } cout << answer << endl; } |
English