TSS Contest P7 - Point Query

View as PDF

Submit solution

Points: 8
Time limit: 2.0s
Java 8 6.0s
Memory limit: 64M

Author:
Problem type

Given N points and Q queries, both of the form x, y, determine the Manhattan distance of the point closest to each query.

Manhattan distance is defined as the distance between two points measured along horizontal and vertical lines only.

All points and queries will be in the first quadrant ( 0 \le x,y \le 10^3).

Input Specifications

The first line contains the integers, N and Q where 1 \le N \le 10^6. and 1 \le Q \le 10^7.

The next N lines contains 2 space separated integers x, y representing a single point.

The next Q lines contains 2 space separated integers x, y representing a single query.

Output Specifications

For each query, output the minimum Manhattan distance to it from any point.

Sample Input 1

3 3
1 1
500 500
1000 1000
1 1
350 321
221 55

Sample Output 1

0
329
274

Comments

There are no comments at the moment.