P26312 [AtCoder] Rearrangement of Sequence
NOI
题目描述

Problem Description

Ringo has a sequence of length $ N $ consisting of distinct integers from $ 1 $ to $ N $. Ringo plans to cut this sequence at $ K $ places to divide it into $ K+1 $ contiguous parts, and then concatenate these parts in any order to form a new sequence. Find the lexicographically smallest sequence that Ringo can create.

Input Format

The input is given from the standard input in the following format:

$ N $ $ K $ $ A_1 $ $ A_2 $ ... $ A_N $

  • The first line contains two integers $N\ (2\ ≦\ N\ ≦\ 10^5),\ K\ (1\ ≦\ K\ ≦\ N-1)$ separated by a space. This indicates that the sequence has a length of $ N $ and will be cut at $ K $ places.
  • The second line contains $ N $ integers separated by spaces. The $i\ (1\ ≦\ i\ ≦\ N)$th integer $A_i\ (1\ ≦\ A_i\ ≦\ N)$ represents the $ i $th number in the sequence. It is guaranteed that all $ A_i $ are distinct.

Output Format

The output consists of $ N $ lines. The $ i $th line should contain a single integer representing the $ i $th number of the lexicographically smallest sequence that Ringo can create. Ensure a newline at the end of the output.

Sample Input and Output

Sample Input #1

5 3
1 3 5 2 4

Sample Output #1

1
2
3
5
4

Sample Input #2

9 5
4 6 8 1 2 9 3 7 5

Sample Output #2

1
2
3
4
6
7
5
8
9

Notes/Hints

Sample Explanation 1

Cutting the sequence as $1\ |\ 3\ 5\ |\ 2\ |\ 4$ and rearranging it to $1\ |\ 2\ |\ 3\ 5\ |\ 4$ results in the lexicographically smallest sequence.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
5 3 1 3 5 2 4
样例输出
1 2 3 5 4