Raslboyy

https://codeforces.com/contest/462/problem/B

Sep 22nd, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. #include <iostream>
  2. #include <map>
  3. #include <algorithm>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.     int n, k;
  11.     cin >> n >> k;
  12.     vector<unsigned long long> vec(300);
  13.     for (int i = 0; i < n; i++) {
  14.         char ch; cin >> ch;
  15.         vec[ch]++;
  16.     }
  17.     sort(vec.begin(), vec.end(), [](auto a, auto b) {
  18.         return a > b;
  19.         });
  20.     int count = 0;
  21.     unsigned long long res = 0;
  22.     for (auto i = 0; count < k; i++) {
  23.         res += min(vec[i] * vec[i], 1ULL * (k - count) * (k - count));
  24.         count += min(vec[i], 1ULL * (k - count));
  25.     }
  26.     cout << res << endl;
  27. }
Add Comment
Please, Sign In to add comment