CF1348C.Phoenix and Distribution
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Phoenix has a string s consisting of lowercase Latin letters. He wants to distribute all the letters of his string into k non-empty strings a1,a2,…,ak such that every letter of s goes to exactly one of the strings ai. The strings ai do not need to be substrings of s. Phoenix can distribute letters of s and rearrange the letters within each string ai however he wants.
For example, if $s = $ baba and k=2, Phoenix may distribute the letters of his string in many ways, such as:
- ba and ba
- a and abb
- ab and ab
- aa and bb
But these ways are invalid:
- baa and ba
- b and ba
- baba and empty string (ai should be non-empty)
Phoenix wants to distribute the letters of his string s into k strings a1,a2,…,ak to minimize the lexicographically maximum string among them, i. e. minimize max(a1,a2,…,ak). Help him find the optimal distribution and print the minimal possible value of max(a1,a2,…,ak).
String x is lexicographically less than string y if either x is a prefix of y and x=y, or there exists an index i (1≤i≤min(∣x∣,∣y∣)) such that xi < yi and for every j (1≤j<i) xj=yj. Here ∣x∣ denotes the length of the string x.
凤凰有一个由小写拉丁字母组成的字符串 s。他希望将字符串 s 中的所有字母分配到 k 个非空字符串 a1,a2,…,ak 中,使得 s 的每个字母恰好被分配到某个 ai 中。这些字符串 ai 不必是 s 的子串。凤凰可以以任意方式分配 s 的字母,并可在每个字符串 ai 内任意重排其字母。
例如,若 $s = $ baba 且 k=2,凤凰可将字符串的字母以多种方式分配,例如:
- ba 和 ba
- a 和 abb
- ab 和 ab
- aa 和 bb
但以下方式是无效的:
- baa 和 ba
- b 和 ba
- baba 和空字符串(因所有 ai 必须非空)
凤凰希望将字符串 s 的字母分配到 k 个字符串 a1,a2,…,ak 中,使得其中字典序最大的字符串尽可能小,即最小化 max(a1,a2,…,ak)。请帮助他找到最优分配方案,并输出 max(a1,a2,…,ak) 的最小可能值。
字符串 x 字典序小于字符串 y,当且仅当满足以下任一条件:
- x 是 y 的真前缀(即 x 是 y 的前缀且 x=y),或
- 存在下标 i(1≤i≤min(∣x∣,∣y∣)),使得 xi<yi,且对所有 j(1≤j<i)均有 xj=yj。
此处 ∣x∣ 表示字符串 x 的长度。
输入格式
The input consists of multiple test cases. The first line contains an integer t (1≤t≤1000) — the number of test cases. Each test case consists of two lines.
The first line of each test case consists of two integers n and k (1≤k≤n≤105) — the length of string s and the number of non-empty strings, into which Phoenix wants to distribute letters of s, respectively.
The second line of each test case contains a string s of length n consisting only of lowercase Latin letters.
It is guaranteed that the sum of n over all test cases is ≤105.
输入包含多个测试用例。第一行包含一个整数 t(1≤t≤1000),表示测试用例的数量。每个测试用例由两行组成。
每个测试用例的第一行包含两个整数 n 和 k(1≤k≤n≤105),分别表示字符串 s 的长度,以及 Phoenix 希望将 s 中的字母分配到的非空字符串的数量。
每个测试用例的第二行包含一个长度为 n 的字符串 s,该字符串仅由小写拉丁字母组成。
保证所有测试用例的 n 之和不超过 105。
输出格式
Print t answers — one per test case. The i-th answer should be the minimal possible value of max(a1,a2,…,ak) in the i-th test case.
输出 t 个答案——每个测试用例一个答案。第 i 个答案应为第 i 个测试用例中 max(a1,a2,…,ak) 的最小可能值。
输入输出样例
输入#1
6 4 2 baba 5 2 baacb 5 3 baacb 5 3 aaaaa 6 4 aaxxzz 7 1 phoenix
输出#1
ab abbc b aa x ehinopx
说明/提示
In the first test case, one optimal solution is to distribute baba into ab and ab.
In the second test case, one optimal solution is to distribute baacb into abbc and a.
In the third test case, one optimal solution is to distribute baacb into ac, ab, and b.
In the fourth test case, one optimal solution is to distribute aaaaa into aa, aa, and a.
In the fifth test case, one optimal solution is to distribute aaxxzz into az, az, x, and x.
In the sixth test case, one optimal solution is to distribute phoenix into ehinopx.
在第一个测试用例中,一种最优解是将字符串 baba 拆分为 ab 和 ab。
在第二个测试用例中,一种最优解是将字符串 baacb 拆分为 abbc 和 a。
在第三个测试用例中,一种最优解是将字符串 baacb 拆分为 ac、ab 和 b。
在第四个测试用例中,一种最优解是将字符串 aaaaa 拆分为 aa、aa 和 a。
在第五个测试用例中,一种最优解是将字符串 aaxxzz 拆分为 az、az、x 和 x。
在第六个测试用例中,一种最优解是将字符串 phoenix 拆分为 ehinopx。
输入解题思路,AI测评打分。不知道怎么写?