QOJ.ac

QOJ

时间限制: 2.0 s 内存限制: 512 MB 总分: 100

#17599. K-TI

统计

You are given a sequence of numbers and a natural number $K$.

We look for the largest number in the sequence at positions divisible by $K$, where the positions of the numbers in the sequence are counted starting from zero. In other words, we look for the largest number at positions $0, K, 2K, 3K, \dots$. If there are multiple such largest numbers, we choose the first one. We remove the found number from the sequence, and the numbers that follow it naturally shift one position to the left, i.e., they change their positions to fill the resulting "gap".

We repeat the described step as long as there are numbers in the sequence. Write a program that performs this for us.

Input

The first line contains the natural numbers $N$ and $K$ ($2 \le K \le N \le 100\,000$).

The next line contains $N$ natural numbers with values in the interval $[1, N]$ that make up the given sequence, in order from the zeroth to the $(N-1)$-th number.

Output

Print $N$ natural numbers, where the $i$-th printed number is equal to the number removed in the $i$-th step.

Subtasks

Subtask Points Additional Constraints
1 7 $N \le 1000$
2 25 $K = 2$
3 23 $K \le 10$
4 25 $100 \le K \le N$
5 20 No additional constraints

Examples

Input 1

10 2
2 3 1 9 10 4 5 6 1 5

Output 1

10
6
4
5
2
9
3
5
1
1

Input 2

10 3
2 3 1 9 10 4 5 6 1 5

Output 2

9
10
4
5
6
2
5
3
1
1

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.