CF1239C.Queue in the Train

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

There are nn seats in the train's car and there is exactly one passenger occupying every seat. The seats are numbered from 11 to nn from left to right. The trip is long, so each passenger will become hungry at some moment of time and will go to take boiled water for his noodles. The person at seat ii ( 1in1 \leq i \leq n ) will decide to go for boiled water at minute tit_i .

Tank with a boiled water is located to the left of the 11 -st seat. In case too many passengers will go for boiled water simultaneously, they will form a queue, since there can be only one passenger using the tank at each particular moment of time. Each passenger uses the tank for exactly pp minutes. We assume that the time it takes passengers to go from their seat to the tank is negligibly small.

Nobody likes to stand in a queue. So when the passenger occupying the ii -th seat wants to go for a boiled water, he will first take a look on all seats from 11 to i1i - 1 . In case at least one of those seats is empty, he assumes that those people are standing in a queue right now, so he would be better seating for the time being. However, at the very first moment he observes that all seats with numbers smaller than ii are busy, he will go to the tank.

There is an unspoken rule, that in case at some moment several people can go to the tank, than only the leftmost of them (that is, seating on the seat with smallest number) will go to the tank, while all others will wait for the next moment.

Your goal is to find for each passenger, when he will receive the boiled water for his noodles.

输入格式

The first line contains integers nn and pp ( 1n1000001 \leq n \leq 100\,000 , 1p1091 \leq p \leq 10^9 ) — the number of people and the amount of time one person uses the tank.

The second line contains nn integers t1,t2,,tnt_1, t_2, \dots, t_n ( 0ti1090 \leq t_i \leq 10^9 ) — the moments when the corresponding passenger will go for the boiled water.

输出格式

Print nn integers, where ii -th of them is the time moment the passenger on ii -th seat will receive his boiled water.

输入输出样例

  • 输入#1

    5 314
    0 310 942 628 0
    

    输出#1

    314 628 1256 942 1570 
    

说明/提示

Consider the example.

At the 00 -th minute there were two passengers willing to go for a water, passenger 11 and 55 , so the first passenger has gone first, and returned at the 314314 -th minute. At this moment the passenger 22 was already willing to go for the water, so the passenger 22 has gone next, and so on. In the end, 55 -th passenger was last to receive the boiled water.

首页