CF1076A.Minimizing the String

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

You are given a string ss consisting of nn lowercase Latin letters.

You have to remove at most one (i.e. zero or one) character of this string in such a way that the string you obtain will be lexicographically smallest among all strings that can be obtained using this operation.

String s=s1s2sns = s_1 s_2 \dots s_n is lexicographically smaller than string t=t1t2tmt = t_1 t_2 \dots t_m if n<mn < m and s1=t1,s2=t2,,sn=tns_1 = t_1, s_2 = t_2, \dots, s_n = t_n or there exists a number pp such that pnp \le n and s1=t1,s2=t2,,sp1=tp1s_1 = t_1, s_2 = t_2, \dots, s_{p-1} = t_{p-1} and sp<tps_p < t_p .

For example, "aaa" is smaller than "aaaa", "abb" is smaller than "abc", "pqr" is smaller than "z".

输入格式

The first line of the input contains one integer nn ( 2n21052 \le n \le 2 \cdot 10^5 ) — the length of ss .

The second line of the input contains exactly nn lowercase Latin letters — the string ss .

输出格式

Print one string — the smallest possible lexicographically string that can be obtained by removing at most one character from the string ss .

输入输出样例

  • 输入#1

    3
    aaa
    

    输出#1

    aa
    
  • 输入#2

    5
    abcda
    

    输出#2

    abca
    

说明/提示

In the first example you can remove any character of ss to obtain the string "aa".

In the second example "abca" < "abcd" < "abcda" < "abda" < "acda" < "bcda".

首页