On the beach P94819


Statement
 

pdf   zip

thehtml

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?

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.

unit=0.07cm

(100,100) sand0.92 0.82 0.68 grass0.39 0.78 0.0 sea0.0 0.48 0.68

linecolor=sand (20,20)(20,80)(80,80)(80,20)

linecolor=grass (00,20)(20,20)(20,80)(80,80)(80,20)(100,20)(100,100)(0,100)(00,20)

linecolor=sea (00,00)(00,20)(100,20)(100,00)(00,00)

linestyle=solid linewidth=2pt linecolor=black fillcolor=black (19.5,20)2

linestyle=dashed linecolor=magenta ->(44,60)(19.5,40) ->(19.5,40)(19.5,20)

linestyle=dashed linewidth=1.5pt linecolor=blue ->(44,60)(44,20)

linestyle=solid linewidth=2pt linecolor=red fillcolor=red (44,60)2

linecolor=black (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.

Public test cases
  • Input

    30 30 12 20 3 2
    30 30 12 20 13 5
    25.5 12.1 23.6 4.7 18.4 5.3
    

    Output

    60.000
    244.000
    58.388
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Official solutions
    C++
    User solutions
    C++