cswork / OA打开练习工作台

IntuitOA #15

Letter Candles

估计中等可在线判题

考点(AI 标注)单调栈与堆贪心调度

The cost of a box is the sum of the squares of the frequencies of each lowercase letter. Remove at most M candles and find the minimum achievable cost.

See below for this site's input format and constraints.

输入格式

Three lines give N, M, and the string S in that order. |S|=N, and S contains only lowercase English letters. This site uses 1≤N≤1000000 and 0≤M≤N.

输出格式

Output the minimum cost.

样例 1

输入:

4
2
aabb

输出:

2

样例 2

输入:

5
2
aaaab

输出:

5

样例 3

输入:

3
0
abc

输出:

3