#P1135. 奇怪的电梯
奇怪的电梯
Description
Hehe, one day I had a dream about a very strange elevator. The elevator can stop at every floor of the building, and on floor ( ) there is a number ( ). The elevator has only four buttons: Open, Close, Up, and Down. The number of floors moved up or down equals the number on the current floor. Of course, if the move would be invalid, the corresponding button will not work. For example: represents ( , , ... ), starting from floor . On floor , pressing "Up" takes you to floor , and pressing "Down" does nothing because there is no floor . Then, what is the minimum number of button presses to get from floor to floor ?
Input Format
Two lines in total.
The first line contains three positive integers separated by spaces, denoting ( , ).
The second line contains non-negative integers separated by spaces, denoting .
Output Format
One line: the minimum number of button presses. If it is impossible to reach, output -1.
5 1 5
3 3 1 2 5
3
Hint
For 100% of the testdata, , , .
There are test points in total. The first test points are worth points each, and the last test point is worth points.
Translated by ChatGPT 5
京公网安备 11011102002149号