QOJ.ac

QOJ

حد الوقت: 1 s حد الذاكرة: 64 MB مجموع النقاط: 100

#11043. 接近 2

الإحصائيات

有一句著名的波兰谚语:“苹果总会落在苹果树附近”$^{1}$。你的任务是通过实验来验证这句谚语。苹果树和苹果的位置可以用平面上的点来表示。点之间的距离由曼哈顿距离定义:

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

假设每个苹果都从离它最近的苹果树上落下。

编写一个程序:

  • 从标准输入读取苹果树和苹果的位置描述,
  • 计算苹果与其对应苹果树之间的最小距离,
  • 将结果写入标准输出。

$^{1}$这句谚语的英语对应表达为:“有其父必有其子”或“有其母必有其女”。

输入格式

输入的第一行包含两个整数 $n$ 和 $m$ ($1 \le n, m \le 100\,000$),用空格分隔,分别表示苹果树的数量和苹果的数量。输入的第二行包含 $2 \cdot n$ 个范围在 $[0, 10^{8}]$ 内的整数,用空格分隔,表示苹果树的坐标对:$x_{1} \ y_{1} \ x_{2} \ y_{2} \dots x_{n} \ y_{n}$。输入的第三行包含 $2 \cdot m$ 个范围在 $[0, 10^{8}]$ 内的整数,用空格分隔,表示苹果的坐标对:$x'_{1} \ y'_{1} \ x'_{2} \ y'_{2} \dots x'_{m} \ y'_{m}$。我们将苹果树和苹果都视为平面上的点;同一个点上可能有多棵苹果树或多个苹果。

输出格式

输出的第一行且仅包含一行,即苹果与其对应苹果树之间的最小距离。

样例

输入 1

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

输出 1

1

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.