WC '18 Contest 2 J1 - Alternate Access

View as PDF

Submit solution

Points: 3 (partial)
Time limit: 1.0s
Memory limit: 16M

Author:
Problem type
Woburn Challenge 2018-19 Round 2 - Junior Division

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 \dots 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 \le A \le 147). Unfortunately, Solomon is on a different floor B (1 \le B \le 147, A \ne 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 \le U \le 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 \le D \le 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 Specification

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 Specification

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.


Comments

There are no comments at the moment.