#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); ios_base::sync_with_stdio(0); int n; cin >> n; int zliczanko[n+1]; for (int i = 0; i <= n; i++) { zliczanko[i] = 0; } for (int i = 0, t; i < n; i++) { cin >> t; zliczanko[t]++; } sort (zliczanko, zliczanko + n + 1); /*for (int i = 0; i < n+1; i++) { cout << zliczanko[i] << ' '; } cout << "\n";*/ int lp = 0, rp = n, wynik = 0; while (lp <= rp && zliczanko[rp] > 0) { wynik++; int a = zliczanko[lp], b = zliczanko[rp]; while (b-a > 0 && lp <= rp) { b-=a; lp++; a = zliczanko[lp]; } zliczanko[lp] = zliczanko[lp] - b + 1; rp--; } cout << wynik; 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 | #include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); ios_base::sync_with_stdio(0); int n; cin >> n; int zliczanko[n+1]; for (int i = 0; i <= n; i++) { zliczanko[i] = 0; } for (int i = 0, t; i < n; i++) { cin >> t; zliczanko[t]++; } sort (zliczanko, zliczanko + n + 1); /*for (int i = 0; i < n+1; i++) { cout << zliczanko[i] << ' '; } cout << "\n";*/ int lp = 0, rp = n, wynik = 0; while (lp <= rp && zliczanko[rp] > 0) { wynik++; int a = zliczanko[lp], b = zliczanko[rp]; while (b-a > 0 && lp <= rp) { b-=a; lp++; a = zliczanko[lp]; } zliczanko[lp] = zliczanko[lp] - b + 1; rp--; } cout << wynik; return 0; } |