cswork / OA打开练习工作台

AmazonOA #203

Get Maximum Information Gain

估计中等可在线判题

考点(AI 标注)哈希计数字符串

Choose two different indices among n lowercase strings. Their number of common features is the number of common characters counted with multiplicity, i.e. the sum over letters of the smaller frequency; for aa and aaa it is 2. A pair is valid when its number of common features is ≤K; maximize the absolute difference of the two string lengths. The original text did not define the return value when no valid pair exists; this site adds that −1 is output in that case, and 0 is output when a valid pair exists but the lengths are equal.

输入格式

The first line contains n K, followed by n lines of lowercase strings. 2≤n≤1000, 1≤string length≤1000, 1≤K≤1000.

输出格式

Output a single integer, the answer.

样例 1

输入:

3 1
abc
bcd
zzzz

输出:

1

样例 2

输入:

2 1
aa
aaa

输出:

-1

样例 3

输入:

2 1
abc
xyz

输出:

0

样例说明

The answers are 1, −1 and 0; in the second example the common characters count as 2, not as 1 distinct letter.