#P16103. [ICPC 2019 NAIPC] Cutting Strings

[ICPC 2019 NAIPC] Cutting Strings

Problem Description

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.

Input Format

Each input will begin with a line with a single integer cc (1≤c≤2⋅1051 \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 (1≤k≤∣s∣≤1051 \leq k \leq |s| \leq 10^5, s∈[a−z]∗s \in [a-z]^*), separated by a space.

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

Output Format

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