Lexicographically Minimal Subsequence

아직 제출이 없습니다시간 제한2초메모리 제한512 MB

문제

Your are given a string ss and an integer kk. Find the lexicographically minimal subsequence of ss which length is kk.

입력

The first line contains a string ss (1s1061 \le |s| \le 10^6). It consists of lowercase Latin letters.

The second line contains an integer kk (1ks1 \le k \le |s|) --- the length of the resulting subsequence.

출력

Output the lexicographically minimal subsequence of ss which length is kk.

힌트

String s_p_1s_p_2s_p_k(1p_1<p_2<<p_ks)s\_{p\_{1}}s\_{p\_{2}}\dots s\_{p\_{k}} (1 \le p\_{1} < p\_{2} < \dots < p\_{k} \le |s|) is called a subsequence of string ss.

String x=x_1x_2x_kx = x\_{1}x\_{2}\dots x\_{k} is lexicographically less than string y=y_1y_2y_ky = y\_{1}y\_{2}\dots y\_{k}, if there exists such number ii (1ik)(1 \le i \le k), that x_1=y_1,x_2=y_2,,x_i1=y_i1x\_{1} = y\_{1}, x\_{2} = y\_{2}, \ldots , x\_{i-1} = y\_{i-1} and x_i<y_ix\_{i} < y\_{i}. Characters in strings are compared as their ASCII codes.