#include <stdio.h> #include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int n; cin >> n; vector<int> arr(n); for (int i = 0; i < n; i++) cin >> arr[i]; sort(arr.begin(), arr.end()); vector<int> arr2(n); arr2 = arr; int uniqueCount = unique(arr2.begin(), arr2.end()) - arr2.begin(); vector<int> quantity(uniqueCount); quantity[0] = 1; int qIndex = 0; for (int i = 1; i < n; i++) { if (arr[i] == arr[i - 1]) quantity[qIndex]++; else { qIndex++; quantity[qIndex]++; } } vector<int> quantity2(uniqueCount); quantity2 = quantity; sort(quantity2.begin(), quantity2.end()); int sequences = uniqueCount; int capacity = quantity2[uniqueCount - 1]; int lowestUnuse = 0; for (int i = uniqueCount - 1; i > 0; i--) { for (int j = lowestUnuse; j < i; j++) { if (capacity - 1 >= quantity2[j]) sequences--; if (capacity > 0) capacity -= quantity[j]; else { lowestUnuse = j + 1; break; } } } cout << sequences; 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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | #include <stdio.h> #include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int n; cin >> n; vector<int> arr(n); for (int i = 0; i < n; i++) cin >> arr[i]; sort(arr.begin(), arr.end()); vector<int> arr2(n); arr2 = arr; int uniqueCount = unique(arr2.begin(), arr2.end()) - arr2.begin(); vector<int> quantity(uniqueCount); quantity[0] = 1; int qIndex = 0; for (int i = 1; i < n; i++) { if (arr[i] == arr[i - 1]) quantity[qIndex]++; else { qIndex++; quantity[qIndex]++; } } vector<int> quantity2(uniqueCount); quantity2 = quantity; sort(quantity2.begin(), quantity2.end()); int sequences = uniqueCount; int capacity = quantity2[uniqueCount - 1]; int lowestUnuse = 0; for (int i = uniqueCount - 1; i > 0; i--) { for (int j = lowestUnuse; j < i; j++) { if (capacity - 1 >= quantity2[j]) sequences--; if (capacity > 0) capacity -= quantity[j]; else { lowestUnuse = j + 1; break; } } } cout << sequences; return 0; } |