#include <bits/stdc++.h> using namespace std; int main (){ ios::sync_with_stdio(0); cin.tie(0); int n, c, j{}, liderzy{}; cin >> n; vector <int> L(n), Ll; for (auto &i : L) cin >> i; sort (L.begin(), L.end()); c = L[0]; //for (auto zz : L) //cout << zz << ' '; //cout << endl; for (auto i : L) if (i == c) ++j; else { Ll.push_back(j); j = 1; c = i; } Ll.push_back(j); /*for (auto zz : Ll) cout << zz << ' '; cout << endl; */ sort (Ll.begin(), Ll.end()); for (int i{Ll.size() - 1}; Ll[i] > 1 and n > 0/*i >= 0*/; --i) { n -= 2*Ll[i] - 1; ++liderzy; } if (n > 0) liderzy += n; cout << liderzy << 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 | #include <bits/stdc++.h> using namespace std; int main (){ ios::sync_with_stdio(0); cin.tie(0); int n, c, j{}, liderzy{}; cin >> n; vector <int> L(n), Ll; for (auto &i : L) cin >> i; sort (L.begin(), L.end()); c = L[0]; //for (auto zz : L) //cout << zz << ' '; //cout << endl; for (auto i : L) if (i == c) ++j; else { Ll.push_back(j); j = 1; c = i; } Ll.push_back(j); /*for (auto zz : Ll) cout << zz << ' '; cout << endl; */ sort (Ll.begin(), Ll.end()); for (int i{Ll.size() - 1}; Ll[i] > 1 and n > 0/*i >= 0*/; --i) { n -= 2*Ll[i] - 1; ++liderzy; } if (n > 0) liderzy += n; cout << liderzy << endl; return 0; } |