#include <bits/stdc++.h> using namespace std; #define pb push_back #define fi first #define sn second typedef long long ll; typedef vector<int> VI; typedef vector<char> VC; typedef pair<int, int> PI; int main() { int n; cin >> n; VI counter(n + 1, 0); for (int i = 0; i < n; i++) { int a; cin >> a; counter[a] += 1; } sort(counter.rbegin(), counter.rend()); int p = 0; int q = counter.size() - 1; int res = 1; // for (int x : counter) cout << x << " "; // cout << endl; while (p < q) { // cout<<p<<" "<<q<<endl; if (counter[p] > counter[q]) { counter[p] -= counter[q]; q--; } else { counter[q] -= (counter[p] - 1); p++; res++; } } cout << res << 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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | #include <bits/stdc++.h> using namespace std; #define pb push_back #define fi first #define sn second typedef long long ll; typedef vector<int> VI; typedef vector<char> VC; typedef pair<int, int> PI; int main() { int n; cin >> n; VI counter(n + 1, 0); for (int i = 0; i < n; i++) { int a; cin >> a; counter[a] += 1; } sort(counter.rbegin(), counter.rend()); int p = 0; int q = counter.size() - 1; int res = 1; // for (int x : counter) cout << x << " "; // cout << endl; while (p < q) { // cout<<p<<" "<<q<<endl; if (counter[p] > counter[q]) { counter[p] -= counter[q]; q--; } else { counter[q] -= (counter[p] - 1); p++; res++; } } cout << res << endl; return 0; } |