#ABC057B. Checkpoints

Checkpoints

题目描述

There are NN students and MM checkpoints on the xyxy-plane.
The coordinates of the ii-th student (1≤i≤N)(1 \leq i \leq N) is (ai,bi)(a_i,b_i), and the coordinates of the checkpoint numbered jj (1≤j≤M)(1 \leq j \leq M) is (cj,dj)(c_j,d_j).
When the teacher gives a signal, each student has to go to the nearest checkpoint measured in Manhattan distance.
The Manhattan distance between two points (x1,y1)(x_1,y_1) and (x2,y2)(x_2,y_2) is ∣x1−x2∣+∣y1−y2∣|x_1-x_2|+|y_1-y_2|.
Here, ∣x∣|x| denotes the absolute value of xx.
If there are multiple nearest checkpoints for a student, he/she will select the checkpoint with the smallest index.
Which checkpoint will each student go to?

在 xyxy 这个平面上有 NN 个学生和 MM 个检查点。
编号为 ii -th 的学生 (1≤i≤N)(1 \leq i \leq N) 的坐标是 (ai,bi)(a_i,b_i) ,编号为 jj (1≤j≤M)(1 \leq j \leq M) 的检查点的坐标是 (cj,dj)(c_j,d_j) 。
当教师发出信号时,每个学生都必须前往以_曼哈顿距离_为单位的最近检查点。
两点 (x1,y1)(x_1,y_1) 和 (x2,y2)(x_2,y_2) 之间的曼哈顿距离为 ∣x1−x2∣+∣y1−y2∣|x_1-x_2|+|y_1-y_2| 。
这里, ∣x∣|x| 表示 xx 的绝对值。
如果一个学生有多个最近的检查点,他会选择指数最小的检查点。
每个学生会去哪个检查点?

输入格式

输入内容按以下格式标准输入:

NN MM
a1a_1 b1b_1
::
aNa_N bNb_N
c1c_1 d1d_1
::
cMc_M dMd_M

输出格式

打印 NN 行。
第 ii -th 行 (1≤i≤N)(1 \leq i \leq N) 应该包含第 ii -th 个学生要去的检查点的索引。

样例 #1

样例输入 #1

2 2
2 0
0 0
-1 0
1 0

样例输出 #1

2
1

样例 #2

样例输入 #2

3 4
10 10
-10 -10
3 3
1 2
2 3
3 5
3 5

样例输出 #2

3
1
2

样例 #3

样例输入 #3

5 5
-100000000 -100000000
-100000000 100000000
100000000 -100000000
100000000 100000000
0 0
0 0
100000000 100000000
100000000 -100000000
-100000000 100000000
-100000000 -100000000

样例输出 #3

5
4
3
2
1

说明

数据规模与约定

  • 1≤N,M≤501 \leq N,M \leq 50
  • −108≤ai,bi,cj,dj≤108-10^8 \leq a_i,b_i,c_j,d_j \leq 10^8
  • 所有输入值均为整数。

样例 11 解释

第一个学生与每个检查点之间的曼哈顿距离为

  • 对于检查点 11 : ∣2−(−1)∣+∣0−0∣=3|2-(-1)|+|0-0|=3
  • 对于检查点 22 : ∣2−1∣+∣0−0∣=1|2-1|+|0-0|=1

最近的检查点是检查点 22 。因此,输出的第一行应包含 22 。

第二名学生与每个检查点之间的曼哈顿距离为

  • 对于检查点 11 : ∣0−(−1)∣+∣0−0∣=1|0-(-1)|+|0-0|=1
  • 对于检查点 22 : ∣0−1∣+∣0−0∣=1|0-1|+|0-0|=1

当有多个最近检查点时,学生将前往索引最小的检查点。因此,输出结果的第二行应包含 11 。

样例 22 解释

同一坐标上可能有多个检查点。