Find the minimum total time Kevin sprints on hot sand to go from the car to the ball and back, cooling at circular umbrellas, where each sun run is at most k seconds and the ball visit does not reset the limit.
Hard8GraphShortest pathGeometryMathNo attempts yetTime limit2sMemory limit512 MBKevin got back to his car after a morning at the beach and was about to drive away when he realised he had left his ball behind. He remembers exactly where it is. The trouble is the heat: sand in direct sunlight is scorching, and Kevin can run on hot sand for at most k seconds at a time. On hot sand he runs at exactly 1 metre per second.
Umbrellas are scattered around the beach. Each umbrella is a perfect circle, and the sand under it stays cool. Every time Kevin reaches an umbrella, he waits there until his feet have cooled down enough to run for another k seconds. He can cool his feet at the car too, so he starts out with cool feet. Time spent in the shade or at the car does not count as time in the sun, and neither does moving around inside the shade.
Kevin never runs more than k seconds on hot sand at a time, so if two umbrellas are more than k metres apart he will not run between them. Picking up the ball does not cool his feet. The run from the last cool spot to the ball and the run from the ball to the next cool spot count together against the same k seconds.
Determine the minimum time Kevin must spend in the sun to retrieve his ball and return to the car.
The first line contains four integers n, k, x and y. Here n (0≤n≤100) is the number of umbrellas, k (1≤k≤100) is how far Kevin can run on hot sand at a time, in metres, and (x, y) (−100≤x≤100, −100≤y≤100) is the position of the ball. Kevin starts at his car at (0, 0). Treat Kevin and the ball as single points.
Each of the next n lines describes one umbrella with three integers x, y and r (−100≤x≤100, −100≤y≤100, 1≤r≤100). The umbrella is the circle centred at (x, y) with radius r.
Several things (the ball, one or more umbrellas, Kevin) may sit at the same place. All lengths are in metres.
Print the minimum time in seconds that Kevin must spend in the sun, rounded to 10 digits after the decimal point. If he cannot retrieve the ball and return to the car, print -1 instead.