#USACOC2221A. Minimizing Haybales

Minimizing Haybales

Description

Bessie is bored and yet again causing trouble in Farmer John's barn. FJ has NN stacks of haybales. For each i[1,N]i\in [1,N], the iith stackhas hih_i haybales. Bessie does not want any haybales tofall, so the only operation she can perform is as follows:

  • If two adjacent stacks' heights differ by at most KK,she can swap the two stacks.

What is the lexicographically minimum sequence of heights that Bessie can obtainafter some sequence of these operations?

  • 1N1051\leq N \leq 10^5
  • 1hi1091\le h_i\le 10^9
  • 1K1091\le K\le 10^9

Input Format

The first line of input contains NN and KK. The i+1i+1-st line contains theheight of the ii-th haybale.

Output Format

Please print out NN lines, the ii-th containing the height of the ii-th haybale in the solution.

5 3
7
7
3
6
2
5 3
7
7
3
6
2

Scoring

  • In 10% of all input cases, N100N\le 100
  • In another 20% of all input cases, N5000N\le 5000
  • In the remaining 70% of input cases, there are no additionalconstraints

Note: the time and memory limits for this problem are 4s and 512MB, twicethe defaults.

Problem Credit

Problem credits: Daniel Zhang and Benjamin Qi