Skip to main content

[Atcoder typical 90] Day 6 - Smallest Subsequence

· One min read
Clover

Question description

You are given a string SS of length NN, consisting of only lowercase English letters.

Find the lexicographically smallest substring of SS with a length of KK and output it.

Note:
A substring of a string TT is a string obtained by removing 0 or more characters from TT and concatenating the remaining characters in their original order.

The definition of lexicographic order:
Let X=x1x2xnX = x_1 x_2 \dots x_n and Y=y1y2ymY = y_1 y_2 \dots y_m be two different strings. XX is said to be lexicographically smaller than YY if and only if XX is a prefix of YY, or if jj is the smallest integer such that xjyjx_j \neq y_j, and xj<yjx_j < y_j.

Constraints

  • 1KN1000001 \leq K \leq N \leq 100000
  • SS is a string of length NN consisting of lowercase English letters
  • NN, KK are integers

Input
The input is given in the following format:

  • NN KK
  • SS

Output
Output the answer as a string.

Examples Input example

7 3
atcoder

Output example

acd

In this example, we can obtain the string "acd" by taking only the 1st, 3rd, and 5th characters.
This string is the lexicographically smallest 3-character substring among all possible substrings.

Approach

Complexity Analysis

  • time complexity :

Solution


Reference

[1] 競プロ典型 90 問
[2] 006 - Smallest Subsequence(★5)

Loading Comments...