-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path462B.cpp
More file actions
72 lines (71 loc) · 1.49 KB
/
462B.cpp
File metadata and controls
72 lines (71 loc) · 1.49 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <bits/stdc++.h>
#define mod 1000000007
#define FOR(i, a, b) for (i = a; i < b; i++)
#define FastIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef priority_queue<ll, vector<ll>, greater<ll>> minheap;
typedef priority_queue<ll> maxheap;
int dxrow[] = {-1, 0, 0, 1, 1, 1, -1, -1}; //first 4 straight last 4 diagonals
int dycol[] = {0, -1, 1, 0, 1, -1, -1, 1};
void printV(vector<ll> v)
{
for (ll i = 0; i < v.size(); i++)
cout << v[i] << "\n";
}
ll power(ll a, ll b)
{
return (ll)(pow(a, b) + 0.5);
}
int modexp(ll A, ll B, ll C)
{
if (A == 0)
return 0;
if (B == 0)
return 1;
ll y;
if (B % 2 == 0)
{
y = modexp(A, B / 2, C);
y = (y * y) % C;
}
else
{
y = A % C;
y = (y * modexp(A, B - 1, C) % C) % C;
}
return (ll)((y + C) % C);
}
int main()
{
ll n, k;
cin >> n >> k;
string s;
cin >> s;
ll freq[26];
memset(freq, 0, sizeof(freq));
for (ll i = 0; i < n; i++)
freq[s[i] - 65]++;
sort(freq, freq + 26, greater<ll>());
ll ans = 0;
for (ll i = 0; i < n; i++)
{
if (k > freq[i])
{
ans += (freq[i] * freq[i]);
k -= freq[i];
}
else
{
ans += (k * k);
k = 0;
}
if (k == 0)
break;
}
cout << ans;
}