4496: E. Elevator
内存限制:512 MB
时间限制:1 S
标准输入输出
题目类型:传统
评测方式:Special Judge
上传者:
提交:4
通过:0
题目描述
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 xi 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.
The i-th elevator will start at second xi 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.
输入格式
The first line contains two positive integers n,m (1≤ n ≤ 5 ⋅ 105,2 ≤ m ≤ 109), denoting the number of elevators and floors.
The second line contains n positive integers x1,…,xn (1 ≤ xi ≤ 109), denoting the start time of the elevators.
The second line contains n positive integers x1,…,xn (1 ≤ xi ≤ 109), denoting the start time of the elevators.
输出格式
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.
输入样例 复制
6 20
3 8 12 6 9 9
输出样例 复制
0
8
-1
4
13
14