-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB_Appleman_and_Card_Game.cpp
More file actions
47 lines (46 loc) · 1001 Bytes
/
B_Appleman_and_Card_Game.cpp
File metadata and controls
47 lines (46 loc) · 1001 Bytes
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
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fastio \
{ \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
}
// #define inf 1e12
int main()
{
fastio
ll n,
k;
cin >> n >> k;
string s;
cin >> s;
vector<pair<ll, char>> v;
map<char, ll> mp;
for (ll i = 0; i < s.size(); i++)
{
mp[s[i]]++;
}
ll ans = 0;
ll sum = 0;
for (auto x : mp)
{
v.push_back({x.second, x.first});
// cout << x.first << " " << x.second << endl;
}
sort(v.begin(), v.end());
for (ll i = v.size() - 1; i >= 0; i--)
{
ll z = v[i].first;
if (sum + z >= k)
{
z = k - sum;
}
sum += z;
ans += (z * z);
if (sum == k)
break;
}
// cout << v[i].first << " " << v[i].second << endl;
cout << ans << endl;
}