Codeforces Round 499 (Div. 2)
A
Stages
Codeforces
900
原题
←B →
翻译中…

Natasha is going to fly to Mars. She needs to build a rocket, which consists of several stages in some order. Each of the stages is defined by a lowercase Latin letter. This way, the rocket can be described by the string — concatenation of letters, which correspond to the stages.

翻译中…

There are $n$ stages available. The rocket must contain exactly $k$ of them. Stages in the rocket should be ordered by their weight. So, after the stage with some letter can go only stage with a letter, which is at least two positions after in the alphabet (skipping one letter in between, or even more). For example, after letter 'c' can't go letters 'a', 'b', 'c' and 'd', but can go letters 'e', 'f', ..., 'z'.

翻译中…

For the rocket to fly as far as possible, its weight should be minimal. The weight of the rocket is equal to the sum of the weights of its stages. The weight of the stage is the number of its letter in the alphabet. For example, the stage 'a 'weighs one ton,' b 'weighs two tons, and' z' — $26$ tons.

翻译中…

Build the rocket with the minimal weight or determine, that it is impossible to build a rocket at all. Each stage can be used at most once.

翻译中…

Input

翻译中…

The first line of input contains two integers — $n$ and $k$ ($1 \le k \le n \le 50$) – the number of available stages and the number of stages to use in the rocket.

翻译中…

The second line contains string $s$, which consists of exactly $n$ lowercase Latin letters. Each letter defines a new stage, which can be used to build the rocket. Each stage can be used at most once.

翻译中…

Output

翻译中…

Print a single integer — the minimal total weight of the rocket or -1, if it is impossible to build the rocket at all.

翻译中…

Note

翻译中…

In the first example, the following rockets satisfy the condition:

翻译中…
  • "adx" (weight is $1+4+24=29$);
  • "ady" (weight is $1+4+25=30$);
  • "bdx" (weight is $2+4+24=30$);
  • "bdy" (weight is $2+4+25=31$).
翻译中…

Rocket "adx" has the minimal weight, so the answer is $29$.

翻译中…

In the second example, target rocket is "belo". Its weight is $2+5+12+15=34$.

翻译中…

In the third example, $n=k=2$, so the rocket must have both stages: 'a' and 'b'. This rocket doesn't satisfy the condition, because these letters are adjacent in the alphabet. Answer is -1.

翻译中…

样例

Input #1
5 3
xyabd
Output #1
29
InputCopy OutputCopy
Input #2
7 4
problem
Output #2
34
InputCopy OutputCopy
Input #3
2 2
ab
Output #3
-1
InputCopy OutputCopy
Input #4
12 1
abaabbaaabbb
Output #4
1
InputCopy OutputCopy
题目信息
题号
1011A
时间限制
1 s
内存限制
256 MB
标签
贪心
模拟
排序

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。