CF1348C.Phoenix and Distribution

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Phoenix has a string ss consisting of lowercase Latin letters. He wants to distribute all the letters of his string into kk non-empty strings a1,a2,…,aka_1, a_2, \dots, a_k such that every letter of ss goes to exactly one of the strings aia_i. The strings aia_i do not need to be substrings of ss. Phoenix can distribute letters of ss and rearrange the letters within each string aia_i however he wants.

For example, if $s = $ baba and k=2k=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 (aia_i should be non-empty)

Phoenix wants to distribute the letters of his string ss into kk strings a1,a2,…,aka_1, a_2, \dots, a_k to minimize the lexicographically maximum string among them, i. e. minimize max(a1,a2,…,ak)max(a_1, a_2, \dots, a_k). Help him find the optimal distribution and print the minimal possible value of max(a1,a2,…,ak)max(a_1, a_2, \dots, a_k).

String xx is lexicographically less than string yy if either xx is a prefix of yy and x≠yx \ne y, or there exists an index ii (1≤i≤min(∣x∣,∣y∣))1 \le i \le min(|x|, |y|)) such that xix_i < yiy_i and for every jj (1≤j<i)(1 \le j \lt i) xj=yjx_j = y_j. Here ∣x∣|x| denotes the length of the string xx.

凤凰有一个由小写拉丁字母组成的字符串 ss。他希望将字符串 ss 中的所有字母分配到 kk 个非空字符串 a1,a2,…,aka_1, a_2, \dots, a_k 中,使得 ss 的每个字母恰好被分配到某个 aia_i 中。这些字符串 aia_i 不必是 ss 的子串。凤凰可以以任意方式分配 ss 的字母,并可在每个字符串 aia_i 内任意重排其字母。

例如,若 $s = $ baba 且 k=2k=2,凤凰可将字符串的字母以多种方式分配,例如:

  • ba 和 ba
  • a 和 abb
  • ab 和 ab
  • aa 和 bb

但以下方式是无效的:

  • baa 和 ba
  • b 和 ba
  • baba 和空字符串(因所有 aia_i 必须非空)

凤凰希望将字符串 ss 的字母分配到 kk 个字符串 a1,a2,…,aka_1, a_2, \dots, a_k 中,使得其中字典序最大的字符串尽可能小,即最小化 max⁡(a1,a2,…,ak)\max(a_1, a_2, \dots, a_k)。请帮助他找到最优分配方案,并输出 max⁡(a1,a2,…,ak)\max(a_1, a_2, \dots, a_k) 的最小可能值。

字符串 xx 字典序小于字符串 yy,当且仅当满足以下任一条件:

  • xx 是 yy 的真前缀(即 xx 是 yy 的前缀且 x≠yx \ne y),或
  • 存在下标 ii(1≤i≤min⁡(∣x∣,∣y∣)1 \le i \le \min(|x|, |y|)),使得 xi<yix_i < y_i,且对所有 jj(1≤j<i1 \le j < i)均有 xj=yjx_j = y_j。
    此处 ∣x∣|x| 表示字符串 xx 的长度。

输入格式

The input consists of multiple test cases. The first line contains an integer tt (1≤t≤10001 \le t \le 1000) — the number of test cases. Each test case consists of two lines.

The first line of each test case consists of two integers nn and kk (1≤k≤n≤1051 \le k \le n \le 10^5) — the length of string ss and the number of non-empty strings, into which Phoenix wants to distribute letters of ss, respectively.

The second line of each test case contains a string ss of length nn consisting only of lowercase Latin letters.

It is guaranteed that the sum of nn over all test cases is ≤105\le 10^5.

输入包含多个测试用例。第一行包含一个整数 tt(1≤t≤10001 \le t \le 1000),表示测试用例的数量。每个测试用例由两行组成。

每个测试用例的第一行包含两个整数 nn 和 kk(1≤k≤n≤1051 \le k \le n \le 10^5),分别表示字符串 ss 的长度,以及 Phoenix 希望将 ss 中的字母分配到的非空字符串的数量。

每个测试用例的第二行包含一个长度为 nn 的字符串 ss,该字符串仅由小写拉丁字母组成。

保证所有测试用例的 nn 之和不超过 10510^5。

输出格式

Print tt answers — one per test case. The ii-th answer should be the minimal possible value of max(a1,a2,…,ak)max(a_1, a_2, \dots, a_k) in the ii-th test case.

输出 tt 个答案——每个测试用例一个答案。第 ii 个答案应为第 ii 个测试用例中 max(a1,a2,…,ak)max(a_1, a_2, \dots, a_k) 的最小可能值。

输入输出样例

  • 输入#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测评打分。不知道怎么写?

首页