Codeforces Round 726 (Div. 2)
E1
Erase and Extend (Easy Version)
Codeforces
1600
原题
← DE2 →
翻译中…

This is the easy version of the problem. The only difference is the constraints on $n$ and $k$. You can make hacks only if all versions of the problem are solved.

翻译中…

You have a string $s$, and you can do two types of operations on it:

翻译中…
  • Delete the last character of the string.
  • Duplicate the string: $s:=s+s$, where $+$ denotes concatenation.
翻译中…

You can use each operation any number of times (possibly none).

翻译中…

Your task is to find the lexicographically smallest string of length exactly $k$ that can be obtained by doing these operations on string $s$.

翻译中…

A string $a$ is lexicographically smaller than a string $b$ if and only if one of the following holds:

翻译中…
  • $a$ is a prefix of $b$, but $a\ne b$;
  • In the first position where $a$ and $b$ differ, the string $a$ has a letter that appears earlier in the alphabet than the corresponding letter in $b$.
翻译中…

Input

翻译中…

The first line contains two integers $n$, $k$ ($1 \leq n, k \leq 5000$) — the length of the original string $s$ and the length of the desired string.

翻译中…

The second line contains the string $s$, consisting of $n$ lowercase English letters.

翻译中…

Output

翻译中…

Print the lexicographically smallest string of length $k$ that can be obtained by doing the operations on string $s$.

翻译中…

Note

翻译中…

In the first test, it is optimal to make one duplication: "dbcadabc" $\to$ "dbcadabcdbcadabc".

翻译中…

In the second test it is optimal to delete the last $3$ characters, then duplicate the string $3$ times, then delete the last $3$ characters to make the string have length $k$.

翻译中…

"abcd" $\to$ "abc" $\to$ "ab" $\to$ "a" $\to$ "aa" $\to$ "aaaa" $\to$ "aaaaaaaa" $\to$ "aaaaaaa" $\to$ "aaaaaa" $\to$ "aaaaa".

翻译中…

样例

Input #1
8 16
dbcadabc
Output #1
dbcadabcdbcadabc
InputCopy OutputCopy
Input #2
4 5
abcd
Output #2
aaaaa
InputCopy OutputCopy
题目信息
题号
1537E1
时间限制
2 s
内存限制
256 MB
标签
二分
暴力
动态规划
贪心
哈希
模拟
后缀结构
字符串
双指针

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。