- محدودیت زمان: ۱ ثانیه
- محدودیت حافظه: ۲۵۶ مگابایت
After facing numerous challenges, Majid succeeded in escaping from the matrix. Upon exiting the matrix, he finds himself in an elevator on the floor of a building with floors. Majid quickly realizes that this elevator is not an ordinary one. The elevator has only two buttons: Up
and Down
. By pressing these buttons, the elevator moves floors up or floors down.
Specifically:
- After pressing
Up
button, if , the elevator goes to floor . Otherwise, the elevator remains stationary. - After pressing
Down
button, if c-d \leq 1, the elevator goes to floor . Otherwise, the elevator remains stationary. The only way to exit the building is the floor. Since exiting the elevator shouldn’t be easy, each time Majid presses either theUp
orDown
button, he has to pay a high cost. Shocked by the conditions, Majid asks you to calculate the minimum cost for him to exit the building.
ورودی
In the only input line, you are given integers , , , , and separated by a space from left to right .
خروجی
In the only line of output, print the minimum number of times Majid needs to press the elevator buttons to exit the building. If it is impossible to reach from floor to floor using the elevator, print use the stairs
.
ورودی نمونه 1
خروجی نمونه 1
ورودی نمونه 2
خروجی نمونه 2
ارسال پاسخ برای این سؤال