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 = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]
cd = [list(map(int,input().split())) for _ in range(m)]

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

Submission status: Accepted

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

for i in range(n):
    l = [0]*m
    for j in range(m):
        l[j] = abs(s[i][0] - p[j][0]) + abs(s[i][1] - p[j][1])
    print((l.index(min(l)) +1))

Submission status: Accepted

Solution code:
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 i in range(M):
    c[i], d[i] = map(int, input().split())

for i in range(N):
    d1 = float('inf')
    for j in range(M):
        d2 = abs(a[i] - c[j]) + abs(b[i] - d[j])
        if d1 > d2:
            d1 = d2
            check = j + 1
    print(check)

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):
    lst = []
    for j in range(m):
        lst.append(abs(cd[j][0]-ab[i][0])+abs(cd[j][1]-ab[i][1]))
    for j in range(m):
        if lst[j]==min(lst):
            print(j+1)
            break

Submission status: Accepted

Solution code:
n,m = map(int,input().split())#n学生 mチェックポイント
student = []
checkpoint = []
for i in range(n):
    student.append(list(map(int,input().split())))
for i in range(m):
    checkpoint.append(list(map(int,input().split())))

for i in range(n):
    ans = 0 #答えの初期化
    tmp = 100000000000 #距離初期化
    for j in range(m):
        if tmp > abs(student[i][0] - checkpoint[j][0]) + abs(student[i][1] - checkpoint[j][1]):
            ans = j
            tmp = abs(student[i][0] - checkpoint[j][0]) + abs(student[i][1] - checkpoint[j][1])
    print(ans+1)

Submission status: Accepted

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

n,m=map(int, input().split())
ab = []
cd = []

for _ in range(n):
    ab.append(list(map(int, input().split())))
#print(ab)

for _ in range(m):
    cd.append(list(map(int, input().split())))
#print(cd)

#print("-------")
#print("n:",n,"m:",m)

#PLiがどこに行くか
for i in range(n):
    #各チェックポイントとの距離
    dis = []
    for j in range(m):
        #print("---")
        #print("i:",i,"j:",j)
        #print(ab[i][0])
        #print(ab[i][1])
        #print(cd[j][0])
        #print(cd[j][1])
        dis.append(abs(ab[i][0] - cd[j][0])+abs(ab[i][1] - cd[j][1]))
    #print(dis)


    #最寄りのチェックポイントを特定
    min_dis = min(dis)
    for idx, k in enumerate(dis):
        if min_dis == k:
            print(idx+1)
            break

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
c = [list(map(int, input().split())) for i in range(m)]
for i in range(n):
    dim, num = 10**10, -1
    for j in range(m):
        if abs(a[i][0] - c[j][0]) + abs(a[i][1] - c[j][1]) < dim:
            dim = abs(a[i][0] - c[j][0]) + abs(a[i][1] - c[j][1])
            num = j
    print(num+1)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
student = [[0, 0]] * n
for i in range(n):
    a, b = map(int, input().split())
    student[i] = [a, b]

point = [[0, 0]] * m
for i in range(m):
    a, b = map(int, input().split())
    point[i] = [a, b]

for i in student:
    min_d = abs(i[0] - point[0][0]) + abs(i[1] - point[0][1])
    min_i = 1
    for j in range(m):
        d = abs(i[0] - point[j][0]) + abs(i[1] - point[j][1])
        if min_d > d:
            min_d = abs(i[0] - point[j][0]) + abs(i[1] - point[j][1])
            min_i = j+1
    print(min_i)

Submission status: Accepted

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

Submission status: Accepted

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

for a,b in student:
  length=10**10
  pn=0
  for j in range(m):
    c,d=point[j]
    if abs(a-c)+abs(b-d)<length:
      length=abs(a-c)+abs(b-d)
      pn=1+j
  print(pn)

Submission status: Accepted

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


ans = [0] * n
for i in range(n):
    tmp = [0, 10 ** 18]
    for j in range(m):
        if abs(a[i][0]-c[j][0])+abs(a[i][1]-c[j][1]) < tmp[1]:
            tmp = [j,abs(a[i][0]-c[j][0])+abs(a[i][1]-c[j][1])]
    ans[i] = tmp[0]+1

for i in ans:
    print(i)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
ab,cd=[],[]
ans_dis=[1000000000 for i in range(n)] 
ans=[0 for i in range(n)]
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):
    for j in range(m):
        dis=abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
        if dis<ans_dis[i]:
            ans[i]=(j+1)
            ans_dis[i]=dis
for i in range(n):
    print(ans[i])

Submission status: Accepted

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

for i in range(n):
    p=m
    r=100000000000000000
    for j in range(m):
        if r>abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1]):
            r=abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
            p=j+1
        elif r==abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1]):
            if p>j+1:
                p=j+1
    print(p)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
x=[list(map(int,input().split())) for i in range(n+m)]
for a,b in x[:n]:
    l=[abs(a-c)+abs(b-d) for c,d in x[n:]]
    print(l.index(min(l))+1)

Submission status: Accepted

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

student = [list(map(int, input().split())) for _ in range(N)]
checkP = [list(map(int, input().split())) for _ in range(M)]

for s in student:  
  ans = 0
  min_dist = 1<<60
  for i, c in enumerate(checkP, 1):    
    dist = abs(s[0]-c[0]) + abs(s[1]-c[1])
    if dist < min_dist:      
      min_dist = dist
      ans = i
  print(ans)

Submission status: Accepted

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

A = []
C = []

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


for i in range(N):
    S.append([])
    min = float('inf')
  
    for j in range(M):
        temp = abs(A[i][0]-C[j][0])+abs(A[i][1]-C[j][1])
        if min > temp:
            min = temp
            S[i].clear()
            S[i].append(j)

for i in range(N):
    print(S[i][0]+1)

Submission status: Accepted

Solution code:

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

student = []
point = []
dis = 0

for _ in range(n):
    a,b = map(int,input().split())
    student.append((a,b))

for _ in range(m):
    c,d = map(int,input().split())
    point.append((c,d))

for i in range(n):
    ans = []
    for j in range(m):
        ans.append(abs(student[i][0]-point[j][0]) + abs(student[i][1]-point[j][1]))
    idx = ans.index(min(ans))
    print(idx + 1)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
A=[]
B=[]
for i in range(N):
  a,b=map(int,input().split())
  A += [a]
  B += [b]
C=[]
D=[]
for i in range(M):
  c,d=map(int,input().split())
  C +=[c]
  D +=[d]
P=[]
for i in range(N):
  d=float('inf')
  p=-1
  for j in range(M):
    if abs(A[i]-C[j])+abs(B[i]-D[j])<d:
      d=abs(A[i]-C[j])+abs(B[i]-D[j])
      p=j+1
  P+=[p]
for i in range(N):
  print(P[i])

Submission status: Accepted

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

# print(ab, c)


for i in range(n):
    d = []
    for j in range(m):
        d.append(abs(ab[i][0] - c[j][0]) + abs(ab[i][1] - c[j][1]))
    # print(d)
    idx = d.index(min(d))
    print(idx + 1)

Submission status: Accepted

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

for sx, sy in S:
    m = 10**9
    for i, (px, py) in enumerate(P):
        d = abs(px-sx)+abs(py-sy)
        if d<m:
            im = i
            m = d
    print(im+1)

Submission status: Accepted

Solution code:
def func(x):
	return abs(x[0]-k[0])+abs(x[1]-k[1])


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

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

for k in s:
	print(1+t.index(min(t, key=func)))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N,M=map(int,input().split())
A=[0]*N
B=[0]*N
C=[0]*M
D=[0]*M
for i in range(N):
    a,b=map(int,input().split())
    A[i]=a
    B[i]=b
for i in range(M):
    c,d=map(int,input().split())
    C[i]=c
    D[i]=d

for i in range(N):
    ans=0
    lgt=float('inf')
    for j in range(M):
        l=abs(A[i]-C[j])+abs(B[i]-D[j])
        if l<lgt:
            lgt=l
            ans=j
    print(ans+1)

Submission status: Accepted

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

for ab in AB:
    num = 0
    dist = 10**10
    for i in range(len(CD)):
        dist_can = abs(ab[0]-CD[i][0]) + abs(ab[1]-CD[i][1])
        if dist_can < dist:
            dist = dist_can
            ans = i+1
    print(ans)

Submission status: Accepted

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

for c,d in cdl:
    ans = -1
    l = float("inf")
    for idx, (a,b) in enumerate(abl):
        dist = abs(a-c) + abs(b-d)
        if dist < l:
            ans = idx + 1
            l = dist
    print(ans)

Submission status: Accepted

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

for i in a:
    ans = [abs(i[0]-j[0])+abs(i[1]-j[1])for j in c]
    ans_min = min(ans)
    print(ans.index(ans_min)+1)

Submission status: Accepted

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

for i in range(N):
    A=[abs(students[i][0]-checkpoints[j][0])+abs(students[i][1]-checkpoints[j][1]) for j in range(M)]
    print(A.index(min(A))+1)

Submission status: Accepted

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

ans=-1

for (a,b) in ab:
  f=10**9
  for i,(c,d) in enumerate(cd):
    distance=abs(a-c)+abs(b-d)
    if f>distance:
      f=distance
      ans=i+1
    #print(distance)
  print(ans)

Submission status: Accepted

Solution code:
import sys
n, m = map(int, sys.stdin.readline().split())

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

for i in range(m):
    c,d = map(int, sys.stdin.readline().split())
    points.append((c,d))

for i in range(n):
    distance = 10 ** 9
    index = -1
    for j in range(m):
        tmp_dis = abs(students[i][0] - points[j][0]) + \
                  abs(students[i][1] - points[j][1])
        if tmp_dis < distance:
            distance = tmp_dis
            index = j + 1
    print(index)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
ab = [[int(i) for i in input().split()] for j in range(N)]
cd = [[int(i) for i in input().split()] for j in range(M)]
for i in range(N):
    ans = 0
    dis = abs(ab[i][0] - cd[ans][0]) + abs(ab[i][1] - cd[ans][1])
    for nth in range(1, M):
        if abs(ab[i][0] - cd[nth][0]) + abs(ab[i][1] - cd[nth][1]) < dis:
            ans = nth
            dis = abs(ab[i][0] - cd[ans][0]) + abs(ab[i][1] - cd[ans][1])
    print(ans + 1)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf')
ans = 0 ;count = 0 ;pro = 1

n,m=map(int,input().split())
ab=[tuple(map(int,input().split())) for i in range(n)]
cd=[tuple(map(int,input().split())) for i in range(m)]
for a,b in ab:
    tmp=inf
    candi=0
    for j in range(m):
        c=cd[j][0]
        d=cd[j][1]
        k=abs(a-c)+abs(b-d)
        if tmp>k:
            tmp=k
            candi=j
    print(candi+1)

Submission status: Accepted

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

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

#1点目だけ初期化用に分ける
point_no_distance = []

cd = check_point_xy[0]
c = cd[0]
d = cd[1]
point_no = 1

for i in range(N):
    ab = student_xy[i]
    a = ab[0]
    b = ab[1]
    distance = abs(c-a) + abs(d-b)
    point_no_distance.append((point_no,distance))

#2点目以降
for j in range(1,M):
    cd = check_point_xy[j]
    c = cd[0]
    d = cd[1]
    point_no = j + 1
    
    for i in range(N):
        ab = student_xy[i]
        a = ab[0]
        b = ab[1]
        distance = abs(c-a) + abs(d-b)
        if distance < point_no_distance[i][1]:
            point_no_distance[i] = (point_no,distance)
            
for i in range(N):
    pd = point_no_distance[i]
    print(pd[0])

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)]
student = []
for i in range(n):
    ans = []
    for j in range(m):
        ans.append(abs(cd[j][0]-ab[i][0])+abs(cd[j][1]-ab[i][1]))
    ansn = ans.index(min(ans))+1
    print(ansn)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
student = [tuple(map(int, input().split())) for _ in range(n)]
check_points = [tuple(map(int, input().split())) for _ in range(m)]
for i in range(n):
    distance = float('inf')
    index = float('inf')
    for j in range(m):
        now = abs(student[i][0] - check_points[j][0]) + abs(student[i][1] - check_points[j][1])
        if now < distance:
            distance = now
            index = j + 1
    print(index)

Submission status: Accepted

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

nl = [[int(i) for i in input().split()] for _ in range(n)]
ml = [[int(i) for i in input().split()] for _ in range(m)]

for i in nl:
    ans = 0
    dist = 10 **18
    for idx,j in enumerate(ml):
        if dist > abs(i[0] - j[0]) + abs(i[1] - j[1]):
            dist = abs(i[0] - j[0]) + abs(i[1] - j[1])
            ans = idx + 1
    print(ans)

Submission status: Accepted

Solution code:
import sys
import numpy as np

I = np.array(sys.stdin.read().split(), dtype=np.int64)
n, m = I[:2]
ab = I[2:2+n*2].reshape(-1, 2)
cd = I[2+n*2:].reshape(-1, 2)

def main():
    res = np.absolute(cd - ab[:, None])
    res = np.sum(res, axis=2)
    ans = np.argmin(res, axis=1) + 1
    return ans

if __name__ == '__main__':
    ans = main()
    print(*ans, sep='\n')

Submission status: Accepted

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

for _ in range(N):
    lst_n.append([int(x) for x in input().split()])

for _ in range(M):
    lst_m.append([int(x) for x in input().split()])

for a, b in lst_n:
    ret = 10 ** 9
    ret_idx = 0
    for idx, (c, d) in enumerate(lst_m, 1):
        n = abs(a - c) + abs(b - d)
        if n < ret:
            ret = n
            ret_idx = idx
    print(ret_idx)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
std = [list(map(int,input().split())) for i in range(n)]
chk = [list(map(int,input().split())) for i in range(m)]
for s in std:
  ans=[]
  for i in range(m):
    ans.append([abs(s[0]-chk[i][0])+abs(s[1]-chk[i][1]),i+1])
    ans.sort()
  print(ans[0][1])

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
AB = []
CD = []
IMF = 1001001001

for i in range(N):
    AB.append(list(map(int, input().split())))

for i in range(M):
    CD.append(list(map(int, input().split())))

ans = [0] * N
for i in range(N):
    a, b = AB[i]
    t = IMF
    for j in range(M):
        c, d = CD[j]
        s = abs(a-c) + abs(b-d)
        if s < t:
            t = s
            ans[i] = j+1

print(*ans)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
ab = []
cd = []
for i in range(N):
    a = list(map(int,input().split()))
    ab.append(a)
    
for i in range(M):
    c = list(map(int,input().split()))
    cd.append(c)
ans = []
for i in range(N):
    array = []
    for j in range(M):
        array.append(abs(ab[i][0] - cd[j][0])+abs(ab[i][1] - cd[j][1]))
    ans.append(array.index(min(array))+1)
    
for i in ans:
    print(i)

Submission status: Accepted

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

ans = [0]*n

for i in range(n):
    dmin = 10**9
    for j in range(m):
        if dmin > abs(ls_ab[i][0] - ls_cd[j][0]) + abs(ls_ab[i][1] - ls_cd[j][1]):
            dmin = abs(ls_ab[i][0] - ls_cd[j][0]) + abs(ls_ab[i][1] - ls_cd[j][1])
            ans[i] = j + 1

for k in range(n):
   print(ans[k])

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N)]
CD = [tuple(map(int, input().split())) for _ in range(M)]

for a, b in AB:
    ans, maxD = 0, 10 ** 10
    for i, (c, d) in enumerate(CD):
        if abs(a - c) + abs(b - d) < maxD:
            ans, maxD = i + 1, abs(a - c) + abs(b - d)
    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)]
c=[0 for i in range(m)]
d=[0 for i in range(m)]
for i in range(n):
  x,y=map(int,input().split())
  a[i]=x
  b[i]=y
for i in range(m):
  x,y=map(int,input().split())
  c[i]=x
  d[i]=y
for i in range(n):
  x,y=a[i],b[i]
  ans=int(10**9)
  p,q,l,r=0,0,0,0
  for j in range(m):
    p=c[j]
    q=d[j]
    l=abs(x-p)+abs(y-q)
    if l<ans:
      ans=l
      r=j+1
  print(r)

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):
    a = ab[i][0]
    b = ab[i][1]

    md = float('inf')
    for j in range(m):
        c = cd[j][0]
        d = cd[j][1]

        dist = abs(a - c) + abs(b - d)
        if dist < md:
            ans = j + 1
            md = dist

    print(ans)

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)]

for a,b in AB:
    x=10**20
    for i,(c,d) in enumerate(CD):
        l=int(abs(a-c)+abs(b-d))
        if x>l:
            x=l
            num=i+1
    print(num)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
students = [list(map(int,input().split())) for _ in range(n)]
points = [list(map(int,input().split())) for _ in range(m)]
distinations = []
for i in range(n):
  point = -1
  dist = float("INF")
  x1 = students[i][0]
  y1 = students[i][1]
  for j in range(m):
    x2 = points[j][0]
    y2 = points[j][1]
    temp_dist = abs(x1 - x2) + abs(y1 - y2)
    if temp_dist < dist:
      dist = temp_dist
      point = j + 1
  distinations.append(point)
for d in distinations:
  print(d)

Submission status: Accepted

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

ab = [map(int, input().split()) for _ in range(N)]
cd = [list(map(int, input().split())) for _ in range(M)]

for n in range(N):
    ans = []
    a, b = ab[n]
    for m in range(M):
        c, d = cd[m]
        distance = abs(a - c) + abs(b - d)
        ans.append(distance)
    print(ans.index(min(ans)) + 1)

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)]
cd.reverse()

for i in range(n):
    now=float("inf")
    ans=0
    for j in range(m):
        if now>=(abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])):
            now=(abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1]))
            ans=j
    print(m-ans)

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N, M = rl()
AB = [rl() for _ in range(N)]
CD = [rl() for _ in range(M)]
for i in range(N):
    x, y = AB[i]
    length = 10 ** 9
    answer = -1
    for j in range(M):
        l = abs(x-CD[j][0]) + abs(y-CD[j][1])
        if l < length:
            answer = j
            length = l
    print(answer+1)

#22

Submission status: Accepted

Solution code:
#n = int(input())
#n,k = map(int,input().split())
#x = list(map(int,input().split()))


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

st = []
for i in range(n):
    st.append(list(map(int,input().split())))

pl = []
for i in range(m):
    pl.append(list(map(int,input().split())))


for i in range(n):
    dis = 10**9
    ans = 1
    for j in range(m-1,-1,-1):
        dis = min(dis,abs(st[i][0]-pl[j][0])+abs(st[i][1]-pl[j][1]))
        if dis == abs(st[i][0]-pl[j][0])+abs(st[i][1]-pl[j][1]):
            ans = j+1
    print(ans)

Submission status: Accepted

Solution code:
from __future__ import print_function
# import numpy as np
# import numpypy as np
import sys
input = sys.stdin.readline

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd

def lcm(n,m):
    return int(n*m/gcd(n,m))

import re
import array
import copy
import functools
import operator

import collections
import itertools
import bisect
import heapq


from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace

from queue import PriorityQueue as pq

def reduce(p, q):
    common = fractions.gcd(p, q)
    return (p//common , q//common )
# from itertools import accumulate
# from collections import deque

from operator import mul
from functools import reduce

def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

import random


def main():
    n,m = map(int, input().strip().split())
    l_ab = [[0,0] for _ in range(n)]
    l_cd = [[0,0] for _ in range(m)]
    for i in range(n):
        l_ab[i] = list(map(int, input().strip().split()))
    for i in range(m):
        l_cd[i] = list(map(int, input().strip().split()))

    l_ans = [0 for _ in range(n)]
    for i in range(n):
        dist_min=sys.maxsize
        for j in range(m):
            dist_temp=abs(l_ab[i][0] - l_cd[j][0])  +  abs(l_ab[i][1] - l_cd[j][1])
            if dist_min > dist_temp:
                dist_min = dist_temp
                l_ans[i] = j
            elif dist_min == dist_temp and j < l_ans[i]:
                l_ans[i] = j
            else:
                pass
    for i in range(n):
        print(l_ans[i]+1)
        
    return

if __name__ == '__main__':
    main()

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)]#ゴール
l=[0]*n
for i in range(n):
    ans=10**18
    
    for j in range(m):
        a=abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
        
        if ans>a:
            ans=a
            l[i]=j+1
        if ans==0:
            break
            
print(*l,sep='\n')

Submission status: Accepted

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

for i in range(N):
  minj=M
  minval=10**9
  for j in range(M):
    val=abs(stu[i][0]-check[j][0])+abs(stu[i][1]-check[j][1])
    if val<minval:
      minj=j+1
      minval=val
  print(minj)

Submission status: Accepted

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

for j in range(M):
    c1,d1=[int(j) for j in input().split()]
    c.append(c1)
    d.append(d1)

distance=[]
chkpnt=[]

for k in range(N):
    for l in range(M):
        distance.append(abs(a[k]-c[l])+abs(b[k]-d[l]))
    chkpnt.append(str(distance.index(min(distance))+1))
    distance=[]

print('\n'.join(chkpnt))

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
nlst = [[int(i) for i in input().split()] for _ in range(n)]
mlst = [[int(i) for i in input().split()] for _ in range(m)]

for i in nlst:
    tmp = [abs(i[0] - j[0]) + abs(i[1] - j[1]) for j in mlst]
    print(tmp.index(min(tmp)) + 1)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
a = []
c = []
for _ in range(N):
    a.append(list(map(int, input().split())))
for _ in range(M):
    c.append(list(map(int, input().split())))
for i in range(N):
    min = 10**9
    ans = 0
    for k in range(M):
        tmp = abs(a[i][0]-c[k][0])+abs(a[i][1]-c[k][1])
        if tmp < min:
            min = tmp
            ans = k
    print(ans+1)

Submission status: Accepted

Solution code:
#テストファイルで実行する時
import sys
if sys.platform == 'ios':
	sys.stdin=open('input_file.txt')


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)]

min = 10**9
ans = 0

for i in range(n):
	for j in range(m):
		if abs(a[i][0]-b[j][0])+abs(a[i][1]-b[j][1]) < min:
			min = abs(a[i][0]-b[j][0])+abs(a[i][1]-b[j][1])
			ans = j+1
			#print(i,j,min,ans)
	min = 10**9
	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)]

s_lst=[]

for i in range(n):
    tmp_dist=11451419191919
    tmp_ans=0
    for j in range(m):
        if tmp_dist>abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1]):
            tmp_dist=abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
            tmp_ans=j
    print(tmp_ans+1)

Submission status: Accepted

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

hito = []
chk =[]
hito = [[int(i) for i in input().split()] for _ in range(n)]
chk = [[int(i) for i in input().split()] for _ in range(m)]
#print ('hito',hito)
#print ('chk',chk) 

for i in range(n):
  a = hito[i][0]
  b = hito[i][1]
  min = 9999999999
  min_j = 0
  for j in range(m):
    c = chk[j][0]
    d = chk[j][1]
    ans =  abs(a - c) + abs(b - d)
    if min > ans:
      min = ans
      min_j = j
  print(min_j + 1)

Submission status: Accepted

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

peoples = []
checkpoints = []

for i in range(n):
    array = list(map(int, input().split()))
    peoples.append(array)

for j in range(m):
    array = list(map(int, input().split()))
    checkpoints.append(array)

for i in range(n):
    min_dist = 1000000000
    index = 0
    for j in range(m):
        dist = abs(checkpoints[j][0] - peoples[i][0]) + abs(checkpoints[j][1] - peoples[i][1])
        if dist < min_dist:
            min_dist = dist
            index = j
    print(index+1)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
S = []
for i in range(n):
  t = [int(i) for i in input().split()]
  S.append(t)
C = []
for i in range(m):
  t = [int(i) for i in input().split()]
  C.append(t)

for i in range(n):
  now = abs(S[i][0] - C[0][0]) + abs(S[i][1] - C[0][1])
  argnow = 0
  for j in range(1,m):
    noww = abs(S[i][0] - C[j][0]) + abs(S[i][1] - C[j][1])
    if noww < now:
      now = noww
      argnow = j
  print(argnow+1)

Submission status: Accepted

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

students = [list(map(int, input().split())) for _ in range(N)]
check_p = [list(map(int, input().split())) for _ in range(M)]

for s in students:
    min_distance = (10 ** 8) * 4 + 1
    ans = 0
    for m in range(M):
        distance = abs(s[0] - check_p[m][0]) + abs(s[1] - check_p[m][1])
        if min_distance > distance:
            min_distance = distance
            ans = m + 1
    print(ans)