Bala

0

0 votes
Problem

Bala loves to visit exotic places. This time, he is planning to visit Honolulu, Hawaii but he does’t have enough money to buy the flight tickets. He came to know about an annual event called PECFEST in which a coding competition was being organized and the winner would be awarded with a hefty amount of money. As Bala was very good with coding, he decided to give it a try so that he can have the money for his trip. In order to win the competition, he had to solve the following problem:  A string 'str' was given to him which contained 'p' lowercase letters. Now he has to perform some manipulations on the given string. During a single move, he can take a subsequence 'seq' from the given string and add it to his knapsack of strings. Remember that the knapsack cannot have duplicates. Also, if Bala uses this move, it will cost him 'length of str - |length of seq|' units. Now Bala has to find the minimum total cost to fill his knapsack of size 'w'. Also, if it is not possible to do the task, the same should be reported by him.

Input
1. The first line contains two integers p and w (1<=p, k<=100), the length of string and the knapsack size.
2. The second line contains the string.

Output
Just print the total cost, if it is possible to obtain the mentioned size knapsack, otherwise print -1.

Note :- The characters in the subsequence doesn't need to occur successively in the string.
 

Sample Input
4 5
asgr
Sample Output
4
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

For the given input we have knapsack = { "asgr", "asg", "agr", "asr", "sgr" }. Here the cost of first element in knapsack is 0 and the cost of all other remaining is 1 each. So the total cost is 4.

Contributers:
Editor Image

?