Exiting the Matrix


  • محدودیت زمان: ۱ ثانیه
  • محدودیت حافظه: ۲۵۶ مگابایت

After facing numerous challenges, Majid succeeded in escaping from the matrix. Upon exiting the matrix, he finds himself in an elevator on the sths-th floor of a building with ff 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 uu floors up or dd floors down. Specifically:

  • After pressing Up button, if c+ufc+u \leq f, the elevator goes to floor c+uc+u. Otherwise, the elevator remains stationary.
  • After pressing Down button, if c-d \leq 1, the elevator goes to floor cdc-d. Otherwise, the elevator remains stationary. The only way to exit the building is the gthg-th floor. Since exiting the elevator shouldn’t be easy, each time Majid presses either the Up or Down 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 ff, ss, gg, uu, and dd separated by a space from left to right (1s,gf106,0u,d106)(1 \leq s,g \leq f \leq 10^6, 0 \leq u,d \leq10^6).

خروجی🔗

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 ss to floor gg using the elevator, print use the stairs.

ورودی نمونه 1🔗

10 1 10 2 1
Plain text

خروجی نمونه 1🔗

6
Plain text

ورودی نمونه 2🔗

100 2 1 1 0
Plain text

خروجی نمونه 2🔗

use the stairs
Plain text
ارسال پاسخ برای این سؤال
در حال حاضر شما دسترسی ندارید.