#P4364. [九省联考 2018] IIIDX

[九省联考 2018] IIIDX

Description

Konano received a task to arrange the unlock order of tracks for the in-development game “IIIDX.” There are nn tracks in total. Each track has a difficulty dd. The ii-th track is unlocked after the player clears the ik\left\lfloor \frac i k \right\rfloor-th track (x\left\lfloor x \right\rfloor is the floor function). If ik=0\left\lfloor \frac i k \right\rfloor = 0, then this track requires no unlock.

For example, when k=2k = 2, the 11-st track requires no unlock (12=0\left\lfloor \frac 1 2 \right\rfloor = 0), and the 77-th track is unlocked after the player clears the 33-rd track since 72=3\left\lfloor \frac 7 2 \right\rfloor = 3.

Konano’s job is to arrange the order of these tracks so that each newly unlocked track has a difficulty not lower than the prerequisite track’s difficulty. That is, after determining the order, the difficulties satisfy didikd_i \geq d_{\left\lfloor \frac i k \right\rfloor} for every ii.

Of course, this is easy for Konano, who has spent a lot of time “chilling” in informatics competitions. If it were you, how would you solve this task?

Input Format

The first line contains one positive integer nn and one real number kk. nn is the number of tracks, and kk is as described above.

The second line contains nn space-separated positive integers dd, representing the difficulties of the nn tracks.

Output Format

Output one line with nn integers: the difficulty of the ii-th track after arranging the order.

If there are multiple valid solutions, output the one with d1d_1 maximized; if still tied, maximize d2d_2; and so on.

4 2.0
114 514 1919 810
114 810 514 1919

Hint

Test point ID nn kk dd Special constraints
11 1n101 \leq n \leq 10 k=2k=2 1d1001 \leq d \leq 100 All did_i are distinct
22 k=3k=3
33 k=1.1k=1.1
44 k=nk=n
55 1<k1001 < k \leq 100
66
77 1n20001\leq n\leq 2000 k=2k=2 1d1091\leq d\leq 10^9
88 None
99 k=3k=3 All did_i are distinct
1010 None
1111 1<k1091 < k \leq 10^9 All did_i are distinct
1212 None
1313 1n5000001\leq n\leq 500000 k=2k=2
1414 k=3k=3
1515 1<k1091<k\leq 10^9 All did_i are distinct
1616
1717 None
1818
1919
2020

Translated by ChatGPT 5