QOJ.ac

QOJ

実行時間制限: 2.0 s メモリ制限: 512 MB 満点: 100

#17599. K-TI

統計

数列と自然数 $K$ が与えられます。 この数列において、位置が $K$ で割り切れる場所にある数の中で最大のものを探します。ここで、数列の位置は $0$ から数えるものとします。言い換えれば、位置 $0, K, 2K, 3K, \dots$ にある数の中で最大のものを探します。そのような最大値が複数ある場合は、最も左にあるものを選びます。見つけた数を数列から削除し、その後に続く数は左に一つずつ詰められ、空いた場所を埋めるように位置が変化します。

この操作を数列の要素がなくなるまで繰り返します。この操作を行うプログラムを作成してください。

入力

最初の行に自然数 $N$ と $K$ ($2 \le K \le N \le 100\,000$) が与えられます。 次の行に、数列を構成する $N$ 個の自然数が、$0$ 番目から $(N-1)$ 番目まで順に与えられます。各自然数は $[1, N]$ の範囲の値です。

出力

$N$ 個の自然数を出力してください。$i$ 番目に出力する数は、$i$ 回目の操作で削除された数です。

小課題

小課題 配点 追加の制約
1 7 $N \le 1000$
2 25 $K = 2$
3 23 $K \le 10$
4 25 $100 \le K \le N$
5 20 追加の制約なし

入出力例

入力 1

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

出力 1

10
6
4
5
2
9
3
5
1
1

入力 2

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

出力 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.