Distance to the nearest point

Given two sets S and Q of points on the plane, determine, for each point
in Q, the minimum of the Manhattan distances to the points in S.

Input

Input consists of a natural n, the coordinates of the n points in S, a
natural m, and the coordinates of the m points in Q. Assume 1 ≤ n ≤ 10⁵
and 0 ≤ m ≤ 10⁵. The coordinates are real numbers. Points can be
repeated.

Output

For every point in Q, print the Manhattan distance to its closest point
in S.

Observation

This problem tolerates an error of 10⁻⁷ for each output.

Problem information

Author: Jordi Petit

Generation: 2026-01-25T10:34:18.335Z

© Jutge.org, 2006–2026.
https://jutge.org
