#include <bits/stdc++.h>
using namespace std;
const int MAX = 5e5+5;
int ciag[MAX];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, liczba;
vector<int> wyst;
cin >> n;
for(int i = 0; i < n; i++)
{
cin >> liczba;
ciag[liczba]++;
}
for(int i = 1; i <= n; i++)
{
if(ciag[i]!=0)
{
wyst.push_back(ciag[i]);
}
}
sort(wyst.begin(), wyst.end());
int ile = 0;
int res = 0;
int suma = 0;
while(wyst.size() > 0)
{
res++;
ile = 0;
while(suma+wyst[ile] < wyst.back())
{
suma+=wyst[ile];
ile++;
}
wyst.erase(wyst.begin(), wyst.begin() + ile);
auto low = upper_bound(wyst.begin(), wyst.end(), suma);
//cout << suma << ' ' << low-wyst.begin() << endl;
wyst.erase(low);
suma = 0;
}
cout << res;
}
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 | #include <bits/stdc++.h> using namespace std; const int MAX = 5e5+5; int ciag[MAX]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, liczba; vector<int> wyst; cin >> n; for(int i = 0; i < n; i++) { cin >> liczba; ciag[liczba]++; } for(int i = 1; i <= n; i++) { if(ciag[i]!=0) { wyst.push_back(ciag[i]); } } sort(wyst.begin(), wyst.end()); int ile = 0; int res = 0; int suma = 0; while(wyst.size() > 0) { res++; ile = 0; while(suma+wyst[ile] < wyst.back()) { suma+=wyst[ile]; ile++; } wyst.erase(wyst.begin(), wyst.begin() + ile); auto low = upper_bound(wyst.begin(), wyst.end(), suma); //cout << suma << ' ' << low-wyst.begin() << endl; wyst.erase(low); suma = 0; } cout << res; } |
English