IntuitOA #15
Letter Candles
Estimated MediumJudge-ready
Topics (AI-labelled)Stacks & HeapsGreedy
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.
Input
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
Output the minimum cost.
Example 1
Input:
4
2
aabb
Output:
2
Example 2
Input:
5
2
aaaab
Output:
5
Example 3
Input:
3
0
abc
Output:
3
Editorial
Loading solution…