Two dogs follow their own polyline routes at the same constant speed; find the minimum distance between them while both are still walking.
Hard8GeometryTwo pointersImplementationMathNo attempts yetTime limit6sMemory limit512 MBYou look after two dogs, Shadow and Lydia. Each dog knows one favorite walk by heart. A walk is given as a list of points: the dog goes straight from the first point to the second, then straight to the third, and so on to the last point, where its doghouse stands.
Walking the dogs one after the other takes too long, so you let both of them out at the same instant. The risk is that they come close enough to bother each other, so you want to know how close they ever get.
Both dogs start at the same moment and move at exactly the same constant speed. A dog that reaches the last point of its walk goes into its doghouse and falls asleep right away, and from that moment on the distance between the dogs no longer matters, even if the other dog keeps walking for a while. A dog is still awake at the exact instant it enters its house.
Find the smallest distance between the two dogs over the time both of them are awake.
The first line contains an integer n (2≤n≤100000), the number of points on Shadow's walk. Each of the next n lines contains two integers x and y (0≤x,y≤10000), one point of the walk, in the order Shadow visits them. Two consecutive points differ in at least one coordinate.
The next line contains an integer m (2≤m≤100000), the number of points on Lydia's walk. Each of the next m lines describes one point of Lydia's walk in the same format.
Print the smallest distance between the two dogs while both of them are awake, rounded to exactly six digits after the decimal point.