#P4364. Unlocking Song Arrangement

    ID: 17610 Type: Default 1000ms 256MiB

Unlocking Song Arrangement

Unlocking Song Arrangement

Konano has been assigned a task for the upcoming game IIIDX: arranging the unlocking order of n songs. Each song has a difficulty level \(d\). The game unlocks the \(i\)th song after the player clears \(\lfloor \frac{i}{k} \rfloor\) songs. If \(\lfloor \frac{i}{k} \rfloor = 0\), then the song does not require unlocking.

You need to arrange the songs into a valid order so that for every song \(i\) with \(\lfloor \frac{i}{k} \rfloor > 0\), the difficulty satisfies \[ d_i \ge d_{\lfloor i/k \rfloor} \] In other words, each unlocked song must have a difficulty not less than that of the song whose passage triggers its unlock.

If multiple valid arrangements exist, output any of them.

inputFormat

The first line contains two integers \(n\) and \(k\) (\(1 \le n \le 10^5\), \(1 \le k \le n\)).

The second line contains \(n\) integers \(d_1, d_2, \dots, d_n\) (\(1 \le d_i \le 10^9\)) representing the difficulty levels of the songs.

outputFormat

Output a permutation of the \(n\) song difficulties (separated by spaces) that satisfies the unlocking condition described above. If no valid arrangement exists, output -1. (Note: A sorted non-decreasing order always satisfies the condition.)

sample

5 2
3 1 2 4 5
1 2 3 4 5

</p>