Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <map>
- #include <algorithm>
- #include <vector>
- using namespace std;
- int main()
- {
- int n, k;
- cin >> n >> k;
- vector<unsigned long long> vec(300);
- for (int i = 0; i < n; i++) {
- char ch; cin >> ch;
- vec[ch]++;
- }
- sort(vec.begin(), vec.end(), [](auto a, auto b) {
- return a > b;
- });
- int count = 0;
- unsigned long long res = 0;
- for (auto i = 0; count < k; i++) {
- res += min(vec[i] * vec[i], 1ULL * (k - count) * (k - count));
- count += min(vec[i], 1ULL * (k - count));
- }
- cout << res << endl;
- }
Add Comment
Please, Sign In to add comment