A Restaurant for Bears
InterviewTime limit2sMemory limit512 MB
Each arriving bear takes the smallest empty chair at or above its wanted number that is at least d away from every seated bear.
- Level
Medium4 of 10
- Topics
- Implementation, Greedy, Sorting
- Solved
- No attempts yet
Problem
Bears normally do not sit on a chair to eat. Lately, though, some bears eat while seated.
Kangho is a waiter at a huge restaurant for bears. The restaurant has infinitely many chairs, placed in a single row. The chairs are numbered , , ... starting from the one closest to the entrance.
Bears are very large, so they cannot sit right next to each other. Whenever two bears are seated, the difference between the numbers of their chairs must be at least . For example, if , two bears may sit on chairs and , but they may not sit on chairs and .
The restaurant has just opened and every chair is empty.
Today bears visit the restaurant, and they arrive one at a time. A bear does not get up from its chair until the restaurant closes.
Each bear that visits has a seat it wants. If the -th bear to arrive wants seat , the number of the chair it takes must be at least .
When Kangho leads a bear to its seat, he picks the smallest-numbered chair that the bear can sit on.
Given the seats the bears want in order of arrival, write a program that finds which chair each bear sits on.
Input
The first line contains the number of bears and the distance . (, )
The second line contains the seats the bears want, in order of arrival. A wanted seat is a natural number that is at least and at most .
Output
Print the chair each bear sits on, in order of arrival, separated by spaces.
Chair numbers have no upper bound, so an answer can be larger than .