On the beach

You have been sunbathing on a sand beach, and now you want to take a
bath. You touch the sand, but it burns! How can you minimize the total
pain to reach the sea?

0.53 Assume a two-dimensional world. The beach has length ℓ and width w.
Where y ≤ 0, there is sea. Where 0 < x < ℓ and 0 < y < w, there is sand.
The rest is covered by grass. You are at a position (a, b) strictly
inside the beach. Walking a unit on the sand causes pain s. Walking a
unit on the grass causes pain g, with g < s.

To the right we see an example with ℓ = w = 30, a = 12 and b = 20. The
black dot shows the origin (0, 0). The red dot shows your position. If
s = 3 and g = 2, the best path (in blue) goes straight into the sea. If
s = 13 and g = 5, the best path (in pink) goes first straight on the
sand to the point (0, 15), and then straight on the grass into the sea.

0.50

(100,100)

(20,20)(20,80)(80,80)(80,20)

(00,20)(20,20)(20,80)(80,80)(80,20)(100,20)(100,100)(0,100)(00,20)

(00,00)(00,20)(100,20)(100,00)(00,00)

(19.5,20)2

(44,60)(19.5,40) (19.5,40)(19.5,20)

(44,60)(44,20)

(44,60)2

(50,85)ℓ (47,85)(20,85) (53,85)(80,85)

(85,50)w (85,47)(85,20) (85,53)(85,80)

Given ℓ, w, a, b, s and g, can you minimize the pain to reach the sea?

Input

Input consists of several cases, each with ℓ, w, a, b, s and g. They are
strictly positive real numbers with at most three digits after the
decimal point. Assume a < ℓ, b < w, and g < s.

Output

For every case, print the minimum total pain to reach the sea with three
digits after the decimal point. The input cases have no precision
issues.

Problem information

Author: Salvador Roura

Generation: 2026-01-25T12:06:50.831Z

© Jutge.org, 2006–2026.
https://jutge.org
