Woburn Challenge 2018-19 Round 2 - Junior Division
Problem 1: Alternate Access
The IMF (Impossible Mission Force) has gotten wind of a vile plot by escaped convict Solomon Lane to poison Toronto's entire supply of maple syrup! They've dispatched their best agent, Ethan Hunt, to put a stop to this.
Ethan has learned that Solomon will be meeting with a poison supplier somewhere in the CN Tower, which has 147 floors, numbered 1…147 from bottom to top. Ethan has already infiltrated the tower by disguising his identity behind a hockey mask, and made his way to floor A (1 ≤ A ≤ 147). Unfortunately, Solomon is on a different floor B (1 ≤ B ≤ 147, A ≠ B). Simply taking the stairs or elevator at this point won't do, as those routes are sure to be heavily guarded. As such, Ethan will need to use creative thinking to gain alternate access to floor B.
Fortunately, he's got the high-tech gadgets for the job. Without a second thought, Ethan has found himself cutting through a window and clinging to the exterior of the tower at floor A using supermagnetic gloves. What remains is painstakingly making his way to floor B, ideally before the gloves run out of energy. Ethan is able to climb upwards by 1 floor (in other words, increase his current floor by 1) by using up U (1 ≤ U ≤ 100) Joules of energy. Similarly, he's able to climb downwards by 1 floor (decreasing his current floor by 1) by using up D (1 ≤ D ≤ 100) Joules of energy. Upon arriving at floor B, it'll be a simple matter of cutting through a window, barging inside, and taking out Solomon's guards (there can't be more than a couple dozen of them).
What's the minimum amount of glove energy required for Ethan to gain access to floor B?
Input Format
The first line of input consists of a single integer, A.
The second line consists of a single integer, B.
The third line consists of a single integer, U.
The fourth line consists of a single integer, D.
Output Format
Output a single integer, the minimum amount of energy (in Joules) required for Ethan to climb from floor A to floor B.
Sample Input 1
40 39 4 5
Sample Output 1
5
Sample Input 2
142 147 9 12
Sample Output 2
45
Sample Explanation
In the first case, Ethan must climb downwards by 1 floor (from 40 to 39), which requires 5 Joules of energy.
In the second case, Ethan must climb upwards by 5 floors (from 142 to 147), which requires a total of 45 Joules of energy.
All Submissions
Best Solutions
Point Value: 3 (partial)
Time Limit: 2.00s
Memory Limit: 16M
Added: Dec 14, 2018
Author: SourSpinach
Languages Allowed:
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3
Comments (Search)
It's quiet in here...