実行時間制限: 2 sec / メモリ制限: 1024 MB
配点 : 300 点
問題文
100 階建ての建物 A
, B
があります。
i = 1,\dots, 100 について、建物 A
の i 階と B
の i 階は廊下で繋がれています。
また、i = 1,\dots, 99 について、建物 A
の i+1 階と B
の i 階は廊下で繋がれています。
どの廊下も双方向に通行可能で、移動には x 分かかります。
また、A
, B
どちらの建物にも階段があり、i=1,\dots,99 について、同じ建物の i 階と i+1 階は階段で繋がれています。どの階段も双方向に通行可能で、移動には y 分かかります。
建物 A
の a 階から建物 B
の b 階に移動するのにかかる最短時間を求めてください。
制約
- 1 \leq a,b,x,y \leq 100
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
a b x y
出力
建物 A
の a 階から建物 B
の b 階に移動するときの最短時間を出力せよ。
入力例 1
2 1 1 5
出力例 1
1
建物 A
の 2 階と建物 B
の 1 階は直接廊下で繋がれているため、1 分で移動できます。
階段を一度でも使うと 5 分かかってしまうため、これが最短です。
入力例 2
1 2 100 1
出力例 2
101
例えば、階段を使って建物 A
の 2 階に移動した後に廊下を使って建物 B
の 2 階に移動すると 1+100=101 分で移動できます。
入力例 3
1 100 1 100
出力例 3
199
廊下のみを使って移動すると、最短時間で移動できます。
Score : 300 points
Problem Statement
There are two 100-story buildings, called A
and B
. (In this problem, the ground floor is called the first floor.)
For each i = 1,\dots, 100, the i-th floor of A
and that of B
are connected by a corridor.
Also, for each i = 1,\dots, 99, there is a corridor that connects the (i+1)-th floor of A
and the i-th floor of B
.
You can traverse each of those corridors in both directions, and it takes you x minutes to get to the other end.
Additionally, both of the buildings have staircases. For each i = 1,\dots, 99, a staircase connects the i-th and (i+1)-th floors of a building, and you need y minutes to get to an adjacent floor by taking the stairs.
Find the minimum time needed to reach the b-th floor of B
from the a-th floor of A
.
Constraints
- 1 \leq a,b,x,y \leq 100
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
a b x y
Output
Print the minimum time needed to reach the b-th floor of B
from the a-th floor of A
.
Sample Input 1
2 1 1 5
Sample Output 1
1
There is a corridor that directly connects the 2-nd floor of A
and the 1-st floor of B
, so you can travel between them in 1 minute.
This is the fastest way to get there, since taking the stairs just once costs you 5 minutes.
Sample Input 2
1 2 100 1
Sample Output 2
101
For example, if you take the stairs to get to the 2-nd floor of A
and then use the corridor to reach the 2-nd floor of B
, you can get there in 1+100=101 minutes.
Sample Input 3
1 100 1 100
Sample Output 3
199
Using just corridors to travel is the fastest way to get there.