#include<bits/stdc++.h> using namespace std; vector<int> inp; vector<int> nums; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); int n; cin >> n; for(int i = 0; i < n; i++){ int tmp; cin >> tmp; inp.push_back(tmp); } sort(inp.begin(), inp.end()); int tmp = 0; int last = inp[0]; for(int i = 0; i < n; i++){ if(last != inp[i]){ last = inp[i]; nums.push_back(tmp); tmp = 0; } tmp++; } nums.push_back(tmp); sort(nums.begin(), nums.end()); int result = 0; int j = 0; for(int i = nums.size() - 1; i >= 0; i--) { if(i == j){ result++; break; } if(i < j) { break; } tmp = 0; while(tmp + nums[j] < nums[i] && i > j) { tmp += nums[j]; j++; } result++; } cout << result; 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 | #include<bits/stdc++.h> using namespace std; vector<int> inp; vector<int> nums; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); int n; cin >> n; for(int i = 0; i < n; i++){ int tmp; cin >> tmp; inp.push_back(tmp); } sort(inp.begin(), inp.end()); int tmp = 0; int last = inp[0]; for(int i = 0; i < n; i++){ if(last != inp[i]){ last = inp[i]; nums.push_back(tmp); tmp = 0; } tmp++; } nums.push_back(tmp); sort(nums.begin(), nums.end()); int result = 0; int j = 0; for(int i = nums.size() - 1; i >= 0; i--) { if(i == j){ result++; break; } if(i < j) { break; } tmp = 0; while(tmp + nums[j] < nums[i] && i > j) { tmp += nums[j]; j++; } result++; } cout << result; return 0; } |