410571: GYM104053 E Elevator

Memory Limit:512 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

E. Elevatortime limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard output

There are $$$n$$$ elevators participating in a speed race starting at second $$$0$$$ in a building of $$$m$$$ floors numbered $$$1$$$ through $$$m$$$.

The $$$i$$$-th elevator will start at second $$$x_i$$$ at floor $$$1$$$ and will ascend at the speed of $$$1$$$ floor per second. Besides, there is a button on each floor except floor $$$1$$$ and floor $$$m$$$, which, if pressed, will make the first elevator that reaches this floor stop for $$$1$$$ second. If more than one elevator reaches a floor at the same time, only the elevator with the smallest index will be regarded as the first one. There are no buttons pressed now, but you can press the buttons on some floors before the start of the race. Notice that you can not press the button after the race starts.

Now you wonder whether you will be able to manipulate the race by pressing the buttons to make the $$$i$$$-th elevator be the first to reach floor $$$m$$$, and how many buttons you have to press at least if you can. If more than one elevator reaches floor $$$m$$$ at the same time, only the elevator with the smallest index will be regarded as the first one.

Input

The first line contains two positive integers $$$n,m$$$ ($$$1\le n\le 5 \cdot 10^5,2\le m\le 10^9$$$), denoting the number of elevators and floors.

The second line contains $$$n$$$ positive integers $$$x_1,\ldots,x_n$$$ ($$$1 \le x_i \le 10^9$$$), denoting the start time of the elevators.

Output

Output $$$n$$$ lines. The $$$i$$$-th line should contain the minimum number of buttons you have to press to make the $$$i$$$-th elevator to be the first to reach floor $$$m$$$. Output $$$-1$$$ instead if it is impossible.

ExampleInput
6 20
3 8 12 6 9 9
Output
0
8
-1
4
13
14

加入题单

上一题 下一题 算法标签: