Codeforces Round 330 (Div. 1)
翻译中…
You are given a non-empty line $*s*$ and an integer $*k*$. The following operation is performed with this line exactly once:
翻译中…
- A line is split into at most
$*k*$non-empty substrings, i.e. string$*s*$is represented as a concatenation of a set of strings$*s* = *t*_{1} + *t*_{2} + ... + *t*_{*m*}$,$1 ≤ *m* ≤ *k*$. - Some of strings
$*t*_{*i*}$are replaced by strings$*t*_{*i*}^{*r*}$, that is, their record from right to left. - The lines are concatenated back in the same order, we get string
$*s*' = *t*'_{1}*t*'_{2}... *t*'_{*m*}$, where$*t*'_{*i*}$equals$*t*_{*i*}$or$*t*_{*i*}^{*r*}$.
翻译中…
Your task is to determine the lexicographically smallest string that could be the result of applying the given operation to the string $*s*$.
翻译中…
Input
翻译中…
The first line of the input contains string $*s*$ ($1 ≤ |*s*| ≤ 5 000 000$), consisting of lowercase English letters. The second line contains integer $*k*$ ($1 ≤ *k* ≤ |*s*|$) — the maximum number of parts in the partition.
翻译中…
Output
翻译中…
In the single line print the lexicographically minimum string $*s*'$ which can be obtained as a result of performing the described operation.
翻译中…
样例
Input #1
aba
2
Output #1
aab
InputCopy
OutputCopy
Input #2
aaaabacaba
2
Output #2
aaaaabacab
InputCopy
OutputCopy
Input #3
bababa
1
Output #3
ababab
InputCopy
OutputCopy
Input #4
abacabadabacaba
4
Output #4
aababacabacabad
InputCopy
OutputCopy
题目信息
标签
后缀结构
字符串
题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。