Back
Close

๐Ÿ ๐Ÿ– Beach Volleyball ๐Ÿ ๐Ÿ–

Statement

 Goal

You love playing beach volleyball! Out there in the sun, playing with your friends, volleying that ball back and forth, it's the best.

Until dude-face comes along, and kicks your precious volleyball into the ocean. You'd kick sand at him, but that volleyball could float away and you have to go get it right away!

You are located on the beach at X=start_x and Y=start_y, and ocean meets the beach where Y=beach_y. The volleyball is located in the water at X=ball_x and Y=ball_y.

You have to plot a route that will take the least time to get the ball. You happen to know that you can travel speed_land units per second on land and speed_water units per second while in the water.

You will travel in a straight line towards the shoreline to coordinate X=beach_x, Y=beach_y, then another straight line from there to the ball.

Find the best integer value for beach_x on the shore line that will result in the least travel time.
Input
Line 1: space separated values start_x and start_y
Line 2: beach_y
Line 3: space separated values ball_x and ball_y
Line 4: speed_land
Line 5: speed_water
Output
Line 1 : beach_x - The X coordinate of the point where you meet the beach on your way to the ball.
Constraints
0 โ‰ค start_x,ball_x โ‰ค 20,000,000
0 โ‰ค start_y < beach_y < ball_y โ‰ค 20,000,000
1 โ‰ค speed_water โ‰ค speed_land โ‰ค 1,000
Example
Input
2 0
10
2 20
1
1
Output
2

Tags
PhysicsLoopsDistancesTimeSnell's Law

Difficulty
Medium

Test cases
Straight Down Test
Input
2 0 10 2 20 1 1
Output
2

Straight Down Validator
Input
7 8 22 7 30 2 2
Output
7

Frictionless Water Test
Input
250 100 150 50 200 3 3
Output
150

Frictionless Water Validator
Input
300 50 150 0 200 3 3
Output
100

Different speeds Test
Input
1000 340 900 2000 1900 4 3
Output
1459

Different speeds Validator
Input
2000 540 800 5100 2800 5 4
Output
2774

Big Kick Test
Input
1000 5320 90000 200000 190000 10 1
Output
190829

Big Kick Validator
Input
2000 5440 80000 210000 180000 9 2
Output
188905

Really Big Kick Test
Input
1000 5320 9000000 20000000 190000005 10 1
Output
7970354

Really Big Kick Validator
Input
1000 5320 9000000 20000005 190000004 10 5
Output
1834372

Solution language

Solution

Stub generator input