#include <bits/stdc++.h> using namespace std; int zli[500005]; int main() { int n, a, wyn = 0, i; cin >> n; for(i = 0; i < n; i++){ cin >> a; zli[a]++; } vector <pair <int, int> > p; for(i = 1; i <= 500000;i++){ if (zli[i] > 0) p.push_back(make_pair(zli[i],i)); } sort(p.rbegin(),p.rend()); //for(i = 0 ;i < p.size();i++) cout << p[i].first <<" "<<p[i].second << endl; int pocz = 0, kon = p.size() - 1; while (pocz <= kon){ int s = p[pocz].first-1; while(pocz < kon && s > 0) { s -= p[kon].first; if (s < 0) p[kon].first += s; else kon--; } wyn++; pocz++; } cout << wyn << endl; 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 | #include <bits/stdc++.h> using namespace std; int zli[500005]; int main() { int n, a, wyn = 0, i; cin >> n; for(i = 0; i < n; i++){ cin >> a; zli[a]++; } vector <pair <int, int> > p; for(i = 1; i <= 500000;i++){ if (zli[i] > 0) p.push_back(make_pair(zli[i],i)); } sort(p.rbegin(),p.rend()); //for(i = 0 ;i < p.size();i++) cout << p[i].first <<" "<<p[i].second << endl; int pocz = 0, kon = p.size() - 1; while (pocz <= kon){ int s = p[pocz].first-1; while(pocz < kon && s > 0) { s -= p[kon].first; if (s < 0) p[kon].first += s; else kon--; } wyn++; pocz++; } cout << wyn << endl; return 0; } |