CF594E.Cutting the Line
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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=t1+t2+...+tm , 1<=m<=k .
- Some of strings ti are replaced by strings tir , that is, their record from right to left.
- The lines are concatenated back in the same order, we get string s′=t1′t2′... tm′ , where ti′ equals ti or tir .
Your task is to determine the lexicographically smallest string that could be the result of applying the given operation to the string s .
输入格式
The first line of the input contains string s ( 1<=∣s∣<=5000000 ), consisting of lowercase English letters. The second line contains integer k ( 1<=k<=∣s∣ ) — the maximum number of parts in the partition.
输出格式
In the single line print the lexicographically minimum string s′ which can be obtained as a result of performing the described operation.
输入输出样例
输入#1
aba 2
输出#1
aab
输入#2
aaaabacaba 2
输出#2
aaaaabacab
输入#3
bababa 1
输出#3
ababab
输入#4
abacabadabacaba 4
输出#4
aababacabacabad