#P16103. [ICPC 2019 NAIPC] Cutting Strings

[ICPC 2019 NAIPC] Cutting Strings

题目描述

You are given a string ss and an integer kk. You can remove at most kk non-intersecting substrings from ss. Your task is to find the alphabetically (i.e., dictionary order) largest resulting string.

For example, with string abcdcada and k=2k=2, you can choose the substrings [abc]d[ca]da and remove them to get dda.

输入格式

Each input will begin with a line with a single integer cc (1c21051 \leq c \leq 2\cdot10^5), which is the number of cases you must solve.

Each of the next cc lines will contain an integer kk and a string ss (1ks1051 \leq k \leq |s| \leq 10^5, s[az]s \in [a-z]^*), separated by a space.

The total length of all strings in the input will be at most 10610^6.

输出格式

Output the largest string, alphabetically, that you can get by removing kk or fewer non-intersecting substrings from ss.

4
2 abcdcada
1 ababb
2 ababb
1 dadbdcdbdad
dda
bb
bbb
ddcdbdad