All problems

Hikers Meeting Time

Hard · binary search

A group of hikers is spread out along a long, straight trail, and they want to meet at one spot on it. Hiker i is currently standing at position[i] metres along the trail. They do not all set off at once: hiker i starts walking delay[i] minutes from now, and then walks at a speed of speed[i] metres per minute, in either direction and stopping whenever they like. Until they set off, a hiker stays where they are.

The group has one rule: the meeting cannot take place before the last hiker has set off. At the meeting time every hiker must be standing at the same spot, and a hiker who gets there early simply waits.

Return the earliest time, in minutes from now, at which the meeting can take place. The spot does not have to be a whole number of metres, and neither does the time.

Decimal arithmetic is never exact, so round your answer to 3 decimal places before returning it (a value exactly halfway between two candidates rounds up). Your answer is compared with the expected value exactly.

Examples

Example 1

Input: position = [0, 10], speed = [1, 1], delay = [0, 0]

Output: 5.0

Both hikers set off at once and walk towards each other at 1 metre per minute, so they meet in the middle after 5 minutes.

Example 2

Input: position = [0, 10], speed = [2, 3], delay = [1, 0]

Output: 2.4

At minute 2.4 the first hiker has walked for 1.4 minutes (2.8 metres) and the second for 2.4 minutes (7.2 metres). Together that is exactly the 10 metres between them.

Constraints