Problem:


Score : 200 points

Problem Statement

There are N students and M checkpoints on the xy-plane.

The coordinates of the i-th student (1 \leq i \leq N) is (a_i,b_i), and the coordinates of the checkpoint numbered j (1 \leq j \leq M) is (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 (x_1,y_1) and (x_2,y_2) is |x_1-x_2|+|y_1-y_2|.

Here, |x| denotes the absolute value of x.

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?

Constraints

1 \leq N,M \leq 50

-10^8 \leq a_i,b_i,c_j,d_j \leq 10^8

All input values are integers.

Input

The input is given from Standard Input in the following format:

N M
a_1 b_1
:  
a_N b_N
c_1 d_1
:  
c_M d_M

Output

Print N lines.

The i-th line (1 \leq i \leq N) should contain the index of the checkpoint for the i-th student to go.

Sample Input 1

2 2
2 0
0 0
-1 0
1 0

Sample Output 1

2
1

The Manhattan distance between the first student and each checkpoint is:

For checkpoint 1: |2-(-1)|+|0-0|=3

For checkpoint 2: |2-1|+|0-0|=1

The nearest checkpoint is checkpoint 2. Thus, the first line in the output should contain 2.

The Manhattan distance between the second student and each checkpoint is:

For checkpoint 1: |0-(-1)|+|0-0|=1

For checkpoint 2: |0-1|+|0-0|=1

When there are multiple nearest checkpoints, the student will go to the checkpoint with the smallest index. Thus, the second line in the output should contain 1.

Sample Input 2

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

Sample Output 2

3
1
2

There can be multiple checkpoints at the same coordinates.

Sample Input 3

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

Sample Output 3

5
4
3
2
1



Sample input:
2 2
2 0
0 0
-1 0
1 0


Sample output:
2
1

Submission status: Accepted

Solution code:
n, m = [int(n) for n in input().split()]

p = []
for i in range(n):
    p.append([int(n) for n in input().split()])

check_point = []
for j in range(m):
    check_point.append([int(n) for n in input().split()])

for i in range(n):
    l = []
    for j in range(m):
        delta = abs(p[i][0] - check_point[j][0]) + abs(p[i][1] - check_point[j][1])
        l.append(delta)

    print(l.index(min(l))+1)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
n=[]
m=[]
for i in range(N):
  n.append(list(map(int,input().split())))
for l in range(M):
  m.append(list(map(int,input().split())))
L=[]
for i in n:
  M=[]
  for l in m:
    A=abs(i[0]-l[0])+abs(i[1]-l[1])
    M.append(A)
  print(M.index(min(M))+1)

Submission status: Accepted

Solution code:


def read_input():
    n, m = map(int, input().split())

    students = []
    for i in range(n):
        a, b = map(int, input().split())
        students.append((a, b))

    checkpoints = []
    for j in range(m):
        c, d = map(int, input().split())
        checkpoints.append((c, d))

    return n, m, students, checkpoints


def search_nearest_checkpoint(st, checks):
    def manhattan_dist(a, b):
        return abs(a[0] - b[0]) + abs(a[1] - b[1])

    mindist = float('inf')
    minid = None
    for i, check in enumerate(checks):
        mdist = manhattan_dist(st, check)
        if mdist < mindist:
            mindist = mdist
            minid = i + 1

    return minid

def submit():
    n, m, students, checkpoints = read_input()


    for student in students:
        print(search_nearest_checkpoint(student, checkpoints))


if __name__ == '__main__':
    submit()

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
students=[]
for i in range(n):
    students.append(list(map(int, input().split())))
checkpoints=[]
for i in range(m):
    checkpoints.append(list(map(int, input().split())))

def dist(x, y):
    return abs(x[0]-y[0])+abs(x[1]-y[1])


for student in students:
    mini = [1e20, -1]
    for i in range(m):
        if dist(student,checkpoints[i]) < mini[0]:
            mini = [dist(student, checkpoints[i]),i]
    print(mini[1]+1)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
s = [list(map(int, input().split())) for _ in range(n)]
c = [list(map(int, input().split())) for _ in range(m)]
for si in s:
    di = 10 ** 10
    ans = 0
    for j, cj in enumerate(c):
        dij = abs(si[0] - cj[0]) + abs(si[1] - cj[1])
        if dij < di:
            di = dij
            ans = j + 1
    print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N)]
cd = [list(map(int, input().split())) for _ in range(M)]
for i in range(N):
  l = float('inf')
  min_j = -1
  for j in range(M):
    tmp = abs(ab[i][0]-cd[j][0]) + abs(ab[i][1]-cd[j][1])
    if tmp < l:
      l = tmp
      min_j = j
  print(min_j+1)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
p=[list(map(int,input().split()))for _ in range(n)]
s=[list(map(int,'0'*m))for _ in range(n)]
for j in range(m):
  c,d=map(int,input().split())
  for i in range(n):
    s[i][j]=abs(p[i][0]-c)+abs(p[i][1]-d)
else:
  for i in range(n):print(1+s[i].index(min(s[i])))

Submission status: Accepted

Solution code:
n, m = [int(i) for i in input().split(" ")]
a = [0 for i in range(n)]
b = [0 for i in range(n)]
c = [0 for i in range(m)]
d = [0 for i in range(m)]
for i in range(n):
    a[i], b[i] = [int(i) for i in input().split(" ")]
for i in range(m):
    c[i], d[i] = [int(i) for i in input().split(" ")]

res = []
for i in range(n):
    tmp = 10 ** 10
    resj = 0
    for j in range(m):
        tmo = abs(a[i]-c[j]) + abs(b[i]-d[j])
        if tmo < tmp:
            tmp = tmo
            resj = j
    res.append(resj)

for i in res:
    print(i+1)

Submission status: Accepted

Solution code:
[N,M] = list(map(int,input().split()))
students = [list(map(int,input().split())) for i in range(N)]
check_points = [list(map(int,input().split())) for i in range(M)]
for sy,sx in students:
    min_dis = 10**9
    ans = -1
    for i,[gy,gx] in enumerate(check_points):
        dis = abs(sy-gy) + abs(sx-gx)
        if dis < min_dis:
            min_dis = dis
            ans = i+1
    print(ans)

Submission status: Accepted

Solution code:
N, M = map(int,input().split())
student = []
for i in range (N):
    a, b = map(int,input().split())
    student.append([a,b])
 
flags = []
for i in range (M):
    c, d = map(int,input().split())
    flags.append([c,d])
    
    
for n in range (N):
    x = student[n][0]
    y = student[n][1]
    lowest_score = 10**10
    lowest= 0
    for m in range (M):
        x_m  = flags[m][0]
        y_m  = flags[m][1]
        temp_score = abs(x-x_m) + abs(y-y_m) 
        if temp_score < lowest_score:
            lowest_score = temp_score
            lowest = m
    print(lowest+1)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(N)]
cd = [list(map(int, input().split())) for i in range(M)]

ans = []
for i in ab:
    a, b = i
    Min = 10**9
    num = 1
    for j in cd:
        c, d = j
        L = abs(a-c) + abs(b-d)
        if L < Min:
            pt = num
            Min = L
        num += 1
    ans.append(pt)

for i in ans:
    print(i)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
a, b, c, d = [], [], [], []
for i in range(N):
    ai, bi = map(int, input().split())
    a.append(ai)
    b.append(bi)
for i in range(M):
    ci, di = map(int, input().split())
    c.append(ci)
    d.append(di)

for i in range(N):
    check = int(1e9)
    point = -1
    for j in range(M):
        dis = abs(a[i]-c[j]) + abs(b[i]-d[j])
        if dis < check:
            check = dis
            point = j+1
    print(point)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())

a = []
b = []
c = []
d = []

for i in range(N):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)

for j in range(M):
    x, y = map(int, input().split())
    c.append(x)
    d.append(y)

for i in range(N):
    ans = 0
    minDist = 10**8 * 2
    for j in range(M):
        dist = abs(c[j]-a[i]) + abs(d[j]-b[i]) 
        if dist < minDist:
            minDist = dist
            ans = j
        
    print(ans+1)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
Ans,G,C=[],[],[]
for i in range(n):
  a,b=map(int,input().split())
  G.append([a,b])
for i in range(m):
  c,d=map(int,input().split())
  C.append([c,d])
for i in range(n):
  dis=float("inf")
  ct=0
  for j in range(m):
    a,b=G[i][0],G[i][1]
    c,d=C[j][0],C[j][1]
    dis_c=abs(a-c)+abs(b-d)
    if dis_c<dis:
      ct=j
      dis=dis_c
  Ans.append(ct+1)
print(*Ans,sep="\n")

Submission status: Accepted

Solution code:
n, m = map(int,input().split())
students = []
marks = []
for _ in range(n):
    student = list(map(int,input().split()))
    students.append(student)
for i in range(m):
    mark = list(map(int,input().split()))
    mark.append(i+1)
    marks.append(mark)
INF = 10**10 
for a, b in students:
    mdist = INF
    for c, d, m in marks:
        if abs(a-c) + abs(b-d) < mdist:
            move_mark = m
            mdist = abs(a-c) + abs(b-d)
    print(move_mark)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in '1'*n]
b = [list(map(int, input().split())) for _ in '1'*m]
for i in a:
	d=[]
	for j in b:
		d.append(abs(i[0]-j[0])+abs(i[1]-j[1]))
	print(d.index(min(d))+1)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
students = []
checkpoint = []
for i in range(N):
    students.append(list(map(int, input().split())))
for j in range(M):
    checkpoint.append(list(map(int, input().split())))
for k in students:
    a, b = k[0], k[1]
    distance = []
    for l in checkpoint:
        c, d = l[0], l[1]
        distance.append(abs(a - c) + abs(b - d))
    print(distance.index(min(distance))+1)

Submission status: Accepted

Solution code:
n, m = [int(item) for item in input().split()]
ab = [[int(item) for item in input().split()] for _ in range(n)]
cd = [[int(item) for item in input().split()] for _ in range(m)]

for j, (a,b) in enumerate(ab):
    ans = 10**10 
    prev = 10**10
    for i in range(m):
        c, d = cd[i] 
        ans = min(ans, abs(a-c) + abs(b-d))
        if ans != prev:
            id = i+1
        prev = ans
    print(id)

Submission status: Accepted

Solution code:
# -*-  coding utf-8 -*-

n,m=map(int,input().split())

A=[list(map(int,input().split())) for i in range(n)]
B=[list(map(int,input().split())) for j in range(m)]


for a in A:
    D=[]
    for i in range(m):
        D.append([abs(a[0]-B[i][0])+abs(a[1]-B[i][1]),i+1])
    D=sorted(D,key=lambda x:(x[0],x[1]))
    print(D[0][1])

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
S = [list(map(int, input().split())) for _ in range(N)]
R = [list(map(int, input().split())) for _ in range(M)]
for a, b in S:
    min_j = -1
    min_d = 10 ** 10
    for j, (c, d) in enumerate(R):
        distance = abs(a - c) + abs(b - d)
        if distance < min_d:
            min_j = j
            min_d = distance
    print(min_j + 1)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
pos1=[list(map(int,input().split())) for _ in range(n)]
pos2=[list(map(int,input().split())) for _ in range(m)]
ans=[0]*n
for i in range(n):
  lim=10**9
  for j in range(m):
    tmp=abs(pos1[i][0]-pos2[j][0])+abs(pos1[i][1]-pos2[j][1])
    if tmp<lim:
      lim=tmp
      ans[i]=j+1
for i in range(n):
  print(ans[i])

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
A = []

for i in range(n):
  a,b = map(int, input().split())
  A.append([a,b])
  
C = []
for i in range(m):
  c,d = map(int, input().split())
  C.append([c,d])
  
ans = [0 for i in range(n)]
infinity = float("infinity")
for i in range(n):
  min_length = infinity
  for j  in range(m):
    if abs(A[i][0] - C[j][0]) + abs(A[i][1] - C[j][1]) < min_length:
      min_length = abs(A[i][0] - C[j][0]) + abs(A[i][1] - C[j][1])
      ans[i] = j+1
      
for i in range(len(ans)):
  print(ans[i])

Submission status: Accepted

Solution code:
N,M = map(int,input().split())

ab_a = []
for i in range(0,N):
    ab = list(map(int,input().split()))
    ab_a.append(ab)

cd_a = []
for i in range(0,M):
    cd = list(map(int,input().split()))
    cd_a.append(cd)

for i in range(0,N):
    mnh = 10 ** 10
    point = 100
    h = 0
    for h in range(0,M):
        tmp = abs(cd_a[h][0] - ab_a[i][0]) + abs(cd_a[h][1] - ab_a[i][1])
        if tmp < mnh:
            mnh = tmp
            point = h
    print(point + 1)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
piv = []
check = []
for i in range(n):
    a,b = map(int,input().split())
    piv.append([a,b])
for i in range(m):
    c,d = map(int,input().split())
    check.append([c,d])


for i in range(n):
    tmp = 1000000000
    ans = 0

    for j in range(m):
        x = abs(piv[i][0] - check[j][0]) + abs(piv[i][1] - check[j][1])
        if tmp > x:
            ans = j + 1
            tmp = x

    print(ans)

Submission status: Accepted

Solution code:
from functools import reduce
import math

def main():
    # N! を求める
    # f = math.factorial(N)
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    # 1e10

    # 初期値用:十分小さい数(-100億)
    # -1e10
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N,M = (int(_) for _ in input().split())
    a = []
    b = []
    c = []
    d = []
    ans = []
    for i in range(N):
        t1, t2 = (int(_) for _ in input().split())  
        a.append(t1)
        b.append(t2)
    for i in range(M):
        t1, t2 = (int(_) for _ in input().split())  
        c.append(t1)
        d.append(t2)

    for i in range(N):
        min_dist = 1e10
        ans.append(0)
        for j in range(M):
            dist = abs(a[i]-c[j])+abs(b[i]-d[j])
            if min_dist > dist:
                ans[i] = str(j+1)
                min_dist = dist
    print('\n'.join(ans))
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

def main():
    input = sys.stdin.readline
    N, M = map(int, input().split())

    init = []
    for _ in range(N):
        a, b = map(int, input().split())
        init.append((a, b))

    check = []
    for _ in range(M):
        c, d = map(int, input().split())
        check.append((c, d))

    for i in init:
        pos = 0
        dist = 10**9
        x0, y0 = i[0], i[1]
        for j in range(M):
            x1, y1 = check[j][0], check[j][1]
            if abs(x0 - x1) + abs(y0 - y1) < dist:
                pos = j + 1
                dist = abs(x0 - x1) + abs(y0 - y1)

        print(pos)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
a_list=[]
b_list=[]
for i in range(N):
    a,b=map(int,input().split())
    a_list.append(a)
    b_list.append(b)
    
c_list=[]
d_list=[]
for i in range(M):
    c,d=map(int,input().split())
    c_list.append(c)
    d_list.append(d)

for i in range(N):
    sum=1000000000
    for j in range(M):
        key=abs(a_list[i]-c_list[j])+abs(b_list[i]-d_list[j])
        if sum>key:
            ans=j+1
            sum=key
    print(ans)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
st=[list(map(int,input().split())) for i in range(N)]
ch=[list(map(int,input().split())) for i in range(M)]
for s in st:
    Min=1000000000
    Mindex=-1
    for i in range(M):
        if abs(ch[i][0]-s[0])+abs(ch[i][1]-s[1])<Min:
            Min=abs(ch[i][0]-s[0])+abs(ch[i][1]-s[1])
            Mindex=i+1
    print(Mindex)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())

A=[list(map(int,input().split())) for _ in range(n)]

B=[list(map(int,input().split())) for _ in range(m)]


for a in A:
    D=[]
    for i in range(m):
        D.append([abs(a[0]-B[i][0])+abs(a[1]-B[i][1]),i+1])
    D=sorted(D,key=lambda x:(x[0],x[1]))
    print(D[0][1])

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
a, b, c, d = [], [], [], []
for i in range(N):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)
for i in range(M):
    x, y = map(int, input().split())
    c.append(x)
    d.append(y)
    
for i in range(N):
    ans = 0
    tmp = 10 ** 10
    for j in range(M):
        if abs(a[i] - c[j]) + abs(b[i] - d[j]) < tmp:
            tmp = abs(a[i] - c[j]) + abs(b[i] - d[j])
            ans = j + 1
    print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
a = [0 for i in range(N)]
b = [0 for i in range(N)]
for i in range(N):
	a[i], b[i] = map(int, input().split())
c = [0 for i in range(M)]
d = [0 for i in range(M)]
for i in range(M):
	c[i], d[i] = map(int, input().split())

ans = [1 for i in range(N)]
for i in range(N):
	for j in range(M):
		if abs(a[i]-c[j])+abs(b[i]-d[j]) < abs(a[i]-c[ans[i]-1])+abs(b[i]-d[ans[i]-1]):
			ans[i] = j+1

for i in range(N):
	print(ans[i])

Submission status: Accepted

Solution code:
import sys

ni = lambda: int(sys.stdin.readline().rstrip())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
INF = 10 ** 9
n, m = nm()
ab = [nl() for i in range(n)]
cd = [nl() for i in range(m)]
ans = []
for i in range(n):
    temp = INF
    a = ab[i][0]
    b = ab[i][1]
    for j in range(m-1, -1, -1):
        c = cd[j][0]
        d = cd[j][1]
        if abs(a - c) + abs(b - d) <= temp:
            temp = abs(a - c) + abs(b - d)
            idx = j + 1
    ans.append(str(idx))
print('\n'.join(ans))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a = []
b = []
for _ in range(n):
    a1, b1 = map(int, input().split())
    a.append([a1, b1])
for _ in range(m):
    c, d = map(int, input().split())
    b.append([c, d])
for a_ in a:
    e = []
    for b_ in b:
        ans = abs(a_[0] - b_[0]) + abs(a_[1] - b_[1])
        e.append(ans)
    print(e.index(min(e))+1)

Submission status: Accepted

Solution code:
n, m = map(int, raw_input().split())
a = []
c = []
for i in range(n):
	a.append(map(int, raw_input().split()))
for j in range(m):
	c.append(map(int, raw_input().split()))

for i in range(n):
	dist0 = 999999999
	j0 = 999
	for j in range(m):
		dist = abs(a[i][0]-c[j][0]) + abs(a[i][1]-c[j][1])
		if dist < dist0:
			dist0 = dist
			j0 = j
	print j0 + 1

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
stud = []
for i in range(n):
    a,b = map(int,input().split())
    stud.append([a,b])
dist = [ 1e9 for i in range(n) ]
at = [ 0 for i in range(n) ]
for j in range(m):
    a,b = map(int,input().split())
    for i in range(n):
        d = abs(a - stud[i][0]) + abs(b - stud[i][1])
        if d < dist[i]:
            dist[i] = d
            at[i] = j+1

for i in at:
    print(i)

Submission status: Accepted

Solution code:
(n,m),*a=[list(map(int,s.split()))for s in open(0)]
for i,j in a[:n]:l=[abs(x-i)+abs(y-j)for x,y in a[n:]];print(1+l.index(min(l)))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
students = [tuple(map(int,input().split())) for i in range(N)]
cps = [tuple(map(int,input().split())) for i in range(M)]

def manlen(a,b) :
  return abs(a[0]-b[0])+abs(a[1]-b[1])

for std in students:
  lengths = [manlen(std,cp) for cp in cps]
  bestcp = 1 + lengths.index(min(lengths))
  print(bestcp)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
X=[list(map(int,input().split())) for i in range(N)]
check=[list(map(int,input().split())) for i in range(M)]

for x,y in X:
    dist=[abs(x-c[0])+abs(y-c[1]) for c in check]

    MIN=min(dist)

    print(dist.index(MIN)+1)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
ab = []
cd = []
for i in range(N):
    a, b = map(int, input().split())
    ab.append([a, b])

for i in range(M):
    c, d = map(int, input().split())
    cd.append([c, d])

for i in range(N):
    m_min = 100000000000
    i_min = -1
    for j in range(M):
        m = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
        if m < m_min:
            m_min = m 
            i_min = j
    print(i_min+1)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
S = []
C = []

for i in range(N):
    a, b = map(int, input().split())
    S.append((a, b))

for i in range(M):
    c, d = map(int, input().split())
    C.append((c, d))

for si in S:
    ans = -1
    min_ = 10 ** 10
    for i, ci in enumerate(C):
        ds = abs(ci[0] - si[0]) + abs(ci[1] - si[1])
        if ds < min_:
            min_ = ds
            ans = i
    print(ans + 1)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
STUDENTS = [tuple(map(int, input().split())) for _ in range(N)]
CHECKPOINTS = [tuple(map(int, input().split())) for _ in range(M)]
for student in STUDENTS:
	L = 10 ** 10
	for i, checkpoint in enumerate(CHECKPOINTS):
		l = abs(checkpoint[0] - student[0]) + abs(checkpoint[1] - student[1])
		if l < L:
			nc = i + 1
			L = l
	print(nc)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
hoge_x=[]
hoge_y=[]
huga_x=[]
huga_y=[]
for i in range(n):
  a,b=map(int,input().split())
  hoge_x.append(a)
  hoge_y.append(b)
  
for j in range(m):
  a,b=map(int,input().split())
  huga_x.append(a)
  huga_y.append(b)

for i in range(n):
  ans_kyori=-1
  ans_index=-1
  for j in range(m):
    kyori=abs(hoge_x[i]-huga_x[j])+abs(hoge_y[i]-huga_y[j])
    if(kyori<ans_kyori or ans_kyori==-1):
      ans_kyori=kyori
      ans_index=j+1
  print(ans_index)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

n,m = map(int,input().split())
a = [0] * n
b = [0] * n
c = [0] * m
d = [0] * m
for i in range(n):
    a[i],b[i] = map(int,input().split())
for j in range(m):
    c[j],d[j] = map(int,input().split())
check = []

for i in range(n):
    min_len = 10000000000
    min_id = 10000000000
    for j in range(m):
        length = abs(a[i] - c[j]) + abs(b[i] - d[j])
        if length < min_len:
            min_len = length
            min_id = j + 1
    check.append(min_id)

for i in range(len(check)):
    print(check[i])

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
cd = [list(map(int, input().split())) for _ in range(m)]

for per in ab:
    diff = []
    for check in cd:
        diff.append(abs(per[0]-check[0]) + abs(per[1]-check[1]))
    print(diff.index(min(diff))+1)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=[list(map(int,input().split()))for i in range(n)]
b=[list(map(int,input().split()))for i in range(m)]
for i in a:
  t=10**18
  ans=0
  c=1
  for j in b:
    k=abs(i[0]-j[0])+abs(i[1]-j[1])
    if t>k:
      ans=c
      t=k
    c+=1
  print(ans)

Submission status: Accepted

Solution code:
def checkpoints(N: int, M: int, students: list, points: list)->list:
    ans = []
    for x, y in students:
        min_d, min_i = float('inf'), 0
        for i, (c, d) in enumerate(points):
            if abs(x-c) + abs(y-d) < min_d:
                min_d = abs(x-c) + abs(y-d)
                min_i = i
        ans.append(min_i)

    return ans


if __name__ == "__main__":
    N = 0
    M = 0
    N, M = map(int, input().split())
    students = [tuple(map(int, input().split())) for _ in range(N)]
    points = [tuple(map(int, input().split())) for _ in range(M)]
    ans = checkpoints(N, M, students, points)

    print('\n'.join(str(i+1) for i in ans))

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
"""
a,b = LI()
print((a+b)%24)
"""
#B
n,m = LI()
p = LIR(n)
q = LIR(m)
for x,y in p:
    s = 1
    ans = float("inf")
    for i in range(m):
        if abs(x-q[i][0])+abs(y-q[i][1]) < ans:
            ans = abs(x-q[i][0])+abs(y-q[i][1])
            c = i+1
    print(c)
#C
"""
n = I()
ans = int(math.log10(n)+1)
for i in range(2,int(n**0.5)+1):
    if n%i == 0:
        ans = min(ans, max(int(math.log10(i)+1),int(math.log10(n//i)+1)))
print(ans)
"""

#D
"""
n,a,b = LI()
v = LI()
v.sort()
v = v[::-1]
ans = v[:a]
d = {}
d[ans[-1]] = 0
if ans[0] != ans[-1]:
    for i in ans:
        if i == ans[-1]:
            d[i] += 1
    k = d[i]
    d[i] = 0
    for i in v:
        if i == ans[-1]:
            d[i] += 1
    c = 1
    for j in range(min(k,d[ans[-1]]-k)):
        c *= d[ans[-1]]-j
        c //= j+1
else:
    for i in v:
        if i == ans[-1]:
            d[i] += 1
    c = 0
    for k in range(a,min(d[ans[-1]],b)+1):
        p = 1
        for j in range(min(k,d[ans[-1]]-k)):
            p *= d[ans[-1]]-j
            p //= j+1
        c += p
print(sum(ans)/a)
print(c)
"""
#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
N, M = map(int, input().split())

a, b = [0] * N, [0] * N
c, d = [0] * M, [0] * M

for i in range(N):
    a[i], b[i] = map(int, input().split())
for i in range(M):
    c[i], d[i] = map(int, input().split())

for i in range(N):
    tmp = []
    for j in range(M):
        tmp.append(abs(a[i] - c[j]) + abs(b[i] - d[j]))
    print(np.argmin(tmp) + 1)

Submission status: Accepted

Solution code:
N,M = map(int, input().split())
S=[list(map(int, input().split())) for _ in range(N)]
C=[list(map(int, input().split())) for _ in range(M)]
import sys
for st in S:
  n=-1
  z= sys.maxsize
  j=0
  for ch in C:
    mi = abs(st[0] - ch[0]) + abs(st[1] - ch[1])
    j+=1
    #print(z)
    if z > mi:
      z = mi
      n = j
  print(n)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
cd=[list(map(int,input().split())) for _ in range(m)]

for i in range(n):
    ans=-1
    min=100000000000
    for j in range(m):
        dis=abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
        if(min>dis):
            min=dis
            ans=j+1
    print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
students = [list(map(int, input().split())) for _ in range(N)]
checkpoints = [list(map(int, input().split())) for _ in range(M)]
for s in students:
    ans = 10**9
    for i, c in enumerate(checkpoints):
        dis = abs(c[0] - s[0]) + abs(c[1] - s[1])
        if ans > dis:
            ans = dis
            ansi = i
    print(ansi + 1)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
listA = [list(map(int, input().split())) for i in range(n)]
listB = [list(map(int, input().split())) for j in range(m)]
listC=[]

for k in range(n):
  b=0
  c=0
  for l in range(m):
    a=abs(listA[k][0]-listB[l][0])+abs(listA[k][1]-listB[l][1])
    if a<b or l==0:
      b=a
      c=l
  print(c+1)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
a, b, c, d = [],[],[],[]

for i in range(N):
  ai, bi = map(int, input().split())
  a.append(ai)
  b.append(bi)
#  print(a, b)
for j in range(M):
  cj, dj = map(int, input().split())
  c.append(cj)
  d.append(dj)
  
#print(a,b,c,d)
  
for i in range(N):
  dist, min_dist = 0, 10**9
  ans = 1
  for j in range(M):
    dist = abs(c[j] - a[i]) + abs(d[j] - b[i])
    if dist < min_dist:
      ans = j+1
      min_dist = dist
#    print("ai:{}, bi:{}, cj:{}, dj:{}, dist:{}, ans:{}".format(a[i], b[i], c[j], d[j], dist, ans))
#    print("i:{}, j:{}, dist:{}, min_dist:{}, ans:{}".format(i, j, dist, min_dist, ans))
#    min_dist = min(dist, min_dist)
  print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())

S = []
C = []
for i in range(N):
    a, b = map(int, input().split())
    S.append((a,b))
for i in range(M):
    c, d = map(int, input().split())
    C.append((c,d))
# print(S)
# print(C)

for s in S:
    ans = []
    for i,c in enumerate(C):
        d = abs(s[0] - c[0]) + abs(s[1] - c[1])
        ans.append((d,i))
    ans = sorted(ans)
    min_d = ans[0][0]
    ans_last = []
    for j in ans:
        if j[0] == min_d:
            ans_last.append(j[1]+1)
    print(sorted(ans_last)[0])

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
ab=[[int(i) for i in input().split()] for i in range(N)]
check=[[int(i) for  i in input().split()] for i in range(M)]
for hito in ab:
    curmin=10**9
    goto=0
    for j,point in enumerate(check):
        if abs(point[1]-hito[1])+abs(point[0]-hito[0])<curmin:
            curmin=abs(point[1]-hito[1])+abs(point[0]-hito[0])
            goto=j+1
    print(goto)

Submission status: Accepted

Solution code:
N, M = list(map(int, input().split()))
St = [input().split() for _ in range(N)]
Ch = [input().split() for _ in range(M)]

for i in range(N):
    memo = []
    for j in range(M):
        diff = abs(int(St[i][0]) - int(Ch[j][0])) + abs(int(St[i][1]) - int(Ch[j][1]))
        memo.append(diff)
    print(memo.index(min(memo)) + 1)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
a = [list(map(int,input().split())) for _ in range(n)]
b = [list(map(int,input().split())) for _ in range(m)]
for ax,ay in a:
    mh = []
    for i,[bx,by] in enumerate(b):
        mh.append([abs(ax-bx) + abs(ay-by), i+1])   
    mh.sort()
    print(mh[0][1])

Submission status: Accepted

Solution code:
#057 B
N,M= map(int,input().split())
AB=[[str(j) for j in input().split()] for i in range(N)]
CD=[[str(j) for j in input().split()] for i in range(M)]

for i in range(0, N):
    min_=10**9
    
    ind = 0
    for j in range(0, M):
        if abs(int(AB[i][0])-int(CD[j][0]))+ abs(int(AB[i][1])-int(CD[j][1])) < min_:
            min_=abs(int(AB[i][0])-int(CD[j][0]))+ abs(int(AB[i][1])-int(CD[j][1]))
            ind_ = j
        #print(i,j,min_,ind_+1)
    print(ind_+1)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
student=[]
man=[]
for i in range(n):
  x,y=map(int,input().split())
  student.append([x,y])
for i in range(m):
  x,y=map(int,input().split())
  man.append([x,y])
for i in student:
  ans=[]
  for j in man:
    ans.append(abs(i[0]-j[0])+abs(i[1]-j[1]))
  print(ans.index(min(ans))+1)

Submission status: Accepted

Solution code:
N, M = list(map(int, input().split()))
ab = [list(map(int, input().split())) for i in range(N)]
cd = [list(map(int, input().split())) for i in range(M)]

for a, b in ab:
    tmp = []
    for c, d in cd:
        tmp.append(abs(a-c) + abs(b-d))
    n = min(tmp)
    print(tmp.index(n)+1)