#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef long long ll;
const int N = 5e5+7;
int n, a[N], cnt[N];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for (int i=0; i<n; i++){
cin >> a[i];
cnt[a[i]]++;
}
deque<int> dq;
vector<int> tmp;
for (int i=1; i<=n; i++){
if (cnt[i]) tmp.push_back(cnt[i]);
}
sort(tmp.begin(), tmp.end());
reverse(tmp.begin(), tmp.end());
for (auto i : tmp) dq.push_back(i);
int res = 0;
while (!dq.empty()){
int cur = 0;
while (dq.size() > 1 && cur + dq.back() < dq.front()){
cur += dq.back();
dq.pop_back();
}
if (dq.size() > 1){
dq.back() -= (dq.front() - cur - 1);
}
dq.pop_front();
res++;
}
cout << res << '\n';
return 0;
}
/*
5
1 2 3 1 2
*/
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 50 51 52 | #include <bits/stdc++.h> #define fi first #define se second using namespace std; typedef long long ll; const int N = 5e5+7; int n, a[N], cnt[N]; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; for (int i=0; i<n; i++){ cin >> a[i]; cnt[a[i]]++; } deque<int> dq; vector<int> tmp; for (int i=1; i<=n; i++){ if (cnt[i]) tmp.push_back(cnt[i]); } sort(tmp.begin(), tmp.end()); reverse(tmp.begin(), tmp.end()); for (auto i : tmp) dq.push_back(i); int res = 0; while (!dq.empty()){ int cur = 0; while (dq.size() > 1 && cur + dq.back() < dq.front()){ cur += dq.back(); dq.pop_back(); } if (dq.size() > 1){ dq.back() -= (dq.front() - cur - 1); } dq.pop_front(); res++; } cout << res << '\n'; return 0; } /* 5 1 2 3 1 2 */ |
English