eolymp
bolt
Try our new interface for solving problems
Məsələlər

Elevator Trouble

Elevator Trouble

You are on your way to your first job interview as a program tester, and you are already late. The interview is in a skyscraper and you are currently in floor \textbf{s}, where you see an elevator. Upon entering the elvator, you learn that it has only two buttons, marked "\textbf{UP u}" and "\textbf{DOWN d}". You conclude that the \textbf{UP}-button takes the elevator \textbf{u} floors up (if there aren't enough floors, pressing the \textbf{UP}-botton does nothing, or at least so you assume), whereas the \textbf{DOWN}-button takes you \textbf{d} stories down (or none if there aren't enough). Knowing that the interview is at floor \textbf{g}, and that there are only \textbf{f} floors in the building, you quickly decide to write a program that gives you the amount of button pushes you need to perform. If you simply cannot reach the correct floor, your program halts with the message "\textbf{use the stairs}". Given input \textbf{f}, \textbf{s}, \textbf{g}, \textbf{u} and \textbf{d} (floors, start, goal, up, down), nd the shortest sequence of button presses you must press in order to get from \textbf{s} to \textbf{g}, given a building of \textbf{f} floors, or output "\textbf{use the stairs}" if you cannot get from \textbf{s} to \textbf{g} by the given elevator. \InputFile The input will consist of one line, namely \textbf{f s g u d}, where \textbf{1} ≤ \textbf{s}, \textbf{g} ≤ \textbf{f} ≤ \textbf{1000000} and \textbf{0} ≤ \textbf{u}, \textbf{d} ≤ \textbf{1000000}. The floors are one-indexed, i.e. if there are \textbf{10} stories, \textbf{s} and \textbf{g} be in \textbf{\[1, 10\]}. \OutputFile You must reply with the minimum numbers of pushes you must make in order to get from \textbf{s} to \textbf{g}, or output \textbf{use the stairs} if it is impossible given the con guration of the elvator.
Zaman məhdudiyyəti 1 saniyə
Yaddaşı istafadə məhdudiyyəti 64 MiB
Giriş verilənləri #1
10 1 10 2 1
Çıxış verilənləri #1
6
Giriş verilənləri #2
100 2 1 1 0
Çıxış verilənləri #2
use the stairs
Mənbə 2011 Nordic Collegiate Programming Contest, 1 Октября, Задача D