QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 64 MB Total points: 100

#11043. Near 2

統計

A known Polish proverb is: 'The apple always falls near the apple tree'^{1}. Your task is to check this proverb experimentally. Positions of apple trees and apples can be identified with points on a plane. The distances between points are defined by Manhattan metric:

$$d((x_{1}, y_{1}), (x_{2}, y_{2})) = |x_{1} - x_{2}| + |y_{1} - y_{2}|$$

Let us assume that every apple has fallen from the apple tree closest to it.

Write a program that:

  • reads a description of positions of apple trees and apples from the standard input,
  • computes the smallest distance between an apple and its apple tree,
  • writes the result to the standard output.

^{1}An English equivalent of this proverb is: 'Like father, like son' or 'Like mother, like daughter'.

Input Format

The first line of input contains two integers $ n $ and $ m $ ($1 ≤ n, m ≤ 100\,000$), separated with a single space and denoting the number of apple trees and the number of apples. The second line of input contains $2 \cdot n$ integers from the range $[0,10^{8}]$, separated with single spaces and denoting the pairs of coordinates of apple trees: $ x_{1}$ $y_{1}$ $x_{2}$ $y_{2}$ ... $x_{n} $ $y_{n}$. The third line of input contains $2 \cdot m$ integers from the range $[0,10^{8}]$, separated with single spaces and denoting the pairs of coordinates of apples: $ x'_{1}$ $y'_{1}$ $x'_{2}$ $y'_{2}$ ... $x'_{n}$ $y'_{n} $. We treat both apple trees and apples as points on a plane; there can be multiple apple trees and multiple apples in one point.

Output Format

The first and only line of output should contain the smallest distance between an apple and its apple tree.

Example

Input

3 4
0 2 2 0 2 2
1 1 2 1 2 3 1 4

Output

1
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.