3127: Powerful magic

时间限制:1000 ms 内存限制:128 MB
上传者:
提交:39 通过:9

题目描述

Bob is a powerful magician who uses cards to unleash powerful magic. Each card can unleash a huge amount of powerful magic, so the more cards you have, the more powerful spells you can cast.


There are now 26 types of cards, the cards face are $a$ to $z$, the weight of the set a is $1$, and the weight of the $z$ is $26$. Bob now has $n$ cards, and in order to defeat the evil Dark Magician, he needs to unleash a powerful magic spell of $m$ times. However, he can go to the store and exchange cards for cards, and the rule of exchanging cards is that each card can be exchanged with multiple other cards with the same sum of weights. And the cost is the difference between this card and the minimum weight of the exchanged cards. He wondered if he could defeat the evil Dark Magician and, if so, what was the minimum cost he would need to have $m$ cards.

输入格式

Each test contains multiple test cases. The first line contains the number of test cases $T$ ($1 \leq T \leq 20$). Description of the test cases follows.

The first line of each test case contains Two integers integer $n$ ($1 \leq n \leq 1000$)  and  $m$ ($n \leq m \leq 1000$)  — The number of cards and the number of powerful magic needed.

Each of the next  line contains A string of length $n$, describing $n$ cards.

输出格式

For each test case, print a single integer $k$, minimum cost to get $m$ cards,Otherwise printf -1.

输入样例 复制

3
3 5
abc
4 14
cdeg
3 100
zzz

输出样例 复制

2
10
-1