当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

6988:Display Substring

题目描述
When we display a string on a LED screen, there may be different energy consumptions for displaying different characters. Given a string $S$ with length $n$ consisting of lowercase English letters and the energy consumption of each letter. Assume that the energy consumption of a string is the sum of the energy consumptions of all its characters. Please find the $k$-th smallest energy consumption of all the $\textbf{different}$ substrings of $S$.

Note that a substring of a string $S$ is a contiguous subsequence of $S$. We say two strings $S$ and $T$ are different if the lengths of them are different or there exists at least one position $i$ satisfying $S[i] \neq T[i]$.
输入解释
The first line of the input contains an integer $T \ (1 \leq T \leq 2 \times 10^3)$ --- the number of test cases.

The first line of each test case contains two integers $n \ (1 \leq n \leq 10^5)$ and $k \ (1 \leq k \leq \frac{n (n + 1)}{2})$.

The second line of each test case contains a string $S$ with length $n$ consisting of lowercase English letters.

The third line of each test case contains $26$ integers $c_a, c_b, \ldots, c_z \ (1 \leq c_{\alpha} \leq 100)$ --- the energy consumption of each letter.

It is guaranteed that the sum of $n$ among all test cases does not exceed $8 \times 10^5$.
输出解释
For each test case, output a single integer in a separate line --- the $k$-th smallest energy consumption, or $-1$ if there is no answer.
输入样例
2
5 5
ababc
3 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
5 15
ababc
3 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
输出样例
4
-1

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-6988

最后修改于 2021-10-23T19:10:55+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
8000/4000MS(Java/Others) 262144/262144K(Java/Others)