CF594E.Cutting the Line

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a non-empty line ss and an integer kk . The following operation is performed with this line exactly once:

  • A line is split into at most kk non-empty substrings, i.e. string ss is represented as a concatenation of a set of strings s=t1+t2+...+tms=t_{1}+t_{2}+...+t_{m} , 1<=m<=k1<=m<=k .
  • Some of strings tit_{i} are replaced by strings tirt_{i}^{r} , that is, their record from right to left.
  • The lines are concatenated back in the same order, we get string s=t1t2... tms'=t'_{1}t'_{2}...\ t'_{m} , where tit'_{i} equals tit_{i} or tirt_{i}^{r} .

Your task is to determine the lexicographically smallest string that could be the result of applying the given operation to the string ss .

输入格式

The first line of the input contains string ss ( 1<=s<=50000001<=|s|<=5000000 ), consisting of lowercase English letters. The second line contains integer kk ( 1<=k<=s1<=k<=|s| ) — the maximum number of parts in the partition.

输出格式

In the single line print the lexicographically minimum string ss' 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
    
首页