#include <bits/stdc++.h>
using namespace std;
vector<int> dane;
map<int, int> mapa;
vector<pair<int, int>> pairs;
vector<int> final;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
dane.push_back(x);
mapa[x]++;
}
for (int i = 1; i <= n; i++) {
if (mapa[i] >= 1) {
pairs.push_back(make_pair(mapa[i], i));
}
}
sort(pairs.begin(), pairs.end(), greater<pair<int,int>>());
int q = pairs.size();
for (int i = 0; i < q; i++) {
int q = pairs[i].first;
int x = pairs[i].second;
for(int j = 0; j < q; j++) {
final.push_back(x);
}
}
int head = 0;
int end = n-1;
int o = 0;
while (head <= end) {
int r = final[head];
int count = 0;
while(final[head]== r and head<n) {
head++;
count++;
}
int l = count-1;
int z = 0;
while(z < l){
end--;
z++;
}
o++;
}
cout << o << "\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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | #include <bits/stdc++.h> using namespace std; vector<int> dane; map<int, int> mapa; vector<pair<int, int>> pairs; vector<int> final; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; for (int i = 0; i < n; i++) { int x; cin >> x; dane.push_back(x); mapa[x]++; } for (int i = 1; i <= n; i++) { if (mapa[i] >= 1) { pairs.push_back(make_pair(mapa[i], i)); } } sort(pairs.begin(), pairs.end(), greater<pair<int,int>>()); int q = pairs.size(); for (int i = 0; i < q; i++) { int q = pairs[i].first; int x = pairs[i].second; for(int j = 0; j < q; j++) { final.push_back(x); } } int head = 0; int end = n-1; int o = 0; while (head <= end) { int r = final[head]; int count = 0; while(final[head]== r and head<n) { head++; count++; } int l = count-1; int z = 0; while(z < l){ end--; z++; } o++; } cout << o << "\n"; return 0; } |
English