#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(inp[i] != last){ nums.push_back(tmp); last = inp[i]; tmp = 0; } tmp++; } nums.push_back(tmp); sort(nums.begin(), nums.end()); for(int i = 1; i <= n; i++){ tmp = 0; for(int j = nums.size() - 1; j >= 0; j--) { if(nums[j] < i) break; tmp += int(nums[j]/i) * i; } if(tmp == 0) { for(int j = i; j <= n; j++){ cout << "0 "; } break; } cout << tmp << ' '; } 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 | #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(inp[i] != last){ nums.push_back(tmp); last = inp[i]; tmp = 0; } tmp++; } nums.push_back(tmp); sort(nums.begin(), nums.end()); for(int i = 1; i <= n; i++){ tmp = 0; for(int j = nums.size() - 1; j >= 0; j--) { if(nums[j] < i) break; tmp += int(nums[j]/i) * i; } if(tmp == 0) { for(int j = i; j <= n; j++){ cout << "0 "; } break; } cout << tmp << ' '; } return 0; } |