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())
students = [tuple(map(int, input().split())) for i in range(n)]
checkpoints = [tuple(map(int, input().split())) for i in range(m)]

for student in students:
    list_ = []
    for i in range(len(checkpoints)):
        list_.append((abs(student[0] - checkpoints[i][0]) + abs(student[1] - checkpoints[i][1]), i+1))
    print(sorted(list_)[0][1])

Submission status: Accepted

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

def main(N,M,A,B,C,D):
    for i in range(N):
        res = []
        for j in range(M):
            res.append(abs(A[i]-C[j])+abs(B[i]-D[j]))
        print(res.index(min(res))+1)
 
    
if __name__ == '__main__':
    N, M = map(int, input().split())
    A, B = [], []
    for i in range(N):
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)
    C, D = [], []
    for i in range(M):
        c, d = map(int, input().split())
        C.append(c)
        D.append(d)
    
    main(N,M,A,B,C,D)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
#ABC57 B

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):
    mi = float('inf')
    x,y = ab[i]
    for j in range(m):
        c,d = cd[j]
        if mi > abs(x-c) + abs(y-d):
            ans = j+1
            mi = abs(x-c) + abs(y-d)
    print(ans)

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



for i in ab:

    pno = 0
    now = float("inf")

    for j in range(M):

        if now > abs( i[0] - cd[j][0] ) + abs( i[1] - cd[j][1] ):
            
             pno = j+1
             now = abs( i[0] - cd[j][0] ) + abs( i[1] - cd[j][1] )

    print (pno)

Submission status: Accepted

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

for i in range(n):
    md = 0
    for j in range(m):
        d = abs(cs[j][0] - ss[i][0]) + abs(cs[j][1] - ss[i][1])
        if d < abs(cs[md][0] - ss[i][0]) + abs(cs[md][1] - ss[i][1]):
            md = j
    print(md + 1)

Submission status: Accepted

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

for n in range(N):
    closest = 1
    dist = abs(CD[0][0] - AB[n][0]) + abs(CD[0][1] - AB[n][1])
    for m in range(1, M):
        tmp_dist = abs(CD[m][0] - AB[n][0]) + abs(CD[m][1] - AB[n][1])
        if tmp_dist < dist:
            dist = tmp_dist
            closest = m+1
    print(closest)

Submission status: Accepted

Solution code:
N, M = map(int,input().split())
sp = []
cp = []
move = [0] * N
min_dis = 10**9

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

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

for i in range(N):
    for j in range(M):
        distance = abs(sp[i][0]-cp[j][0]) + abs(sp[i][1]-cp[j][1])
        if distance < min_dis:
            move[i] = j + 1
            min_dis = distance
    min_dis = 10**9

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

Submission status: Accepted

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

for i in range(n):
    ans = 0
    mincp = 100000000000
    for j in range(m):
        dist = abs(a[i]-c[j])+abs(b[i]-d[j])
        if dist < mincp:
            ans = j+1
            mincp = dist
    print(ans)

Submission status: Accepted

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

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

# 生徒単位でチェック
for sx,sy in student:
    dist=2*10**10
    pnum=0
    for i, p in enumerate(point):
        px,py=p[0],p[1]
        pdist=abs(sx-px)+abs(sy-py)
        if pdist<dist:
            dist=pdist
            pnum=i+1
    print(pnum)

Submission status: Accepted

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

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

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


for i in range(N):
    min_dist = float('inf')
    ans = 0
    for j in range(M):
        distance = abs(a[i] - c[j]) + abs(b[i] - d[j])
        if min_dist > distance:
            min_dist = distance
            ans = j + 1
    print(ans)

Submission status: Accepted

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

for i in range(n):
    mn = 10**17
    for j in range(m)[::-1]:
        if mn >= abs(students[i][0] - checks[j][0]) + abs(students[i][1] - checks[j][1]):
            mn = abs(students[i][0] - checks[j][0]) + abs(students[i][1] - checks[j][1])
            ans = j + 1
    print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(N: int, M: int, a: "List[int]", b: "List[int]", c: "List[int]", d: "List[int]"):
    for i in range(N):
        mn = float('inf')
        for j in range(M):
            e = abs(a[i] - c[j]) + abs(b[i] - d[j])
            if e < mn:
                ret = j + 1
                mn = e
        print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    a = [int()] * (N)  # type: "List[int]" 
    b = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    c = [int()] * (M)  # type: "List[int]" 
    d = [int()] * (M)  # type: "List[int]" 
    for i in range(M):
        c[i] = int(next(tokens))
        d[i] = int(next(tokens))
    solve(N, M, a, b, c, d)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
	N, M = map(int, input().split())
	st = [0]*N
	p = [0]*M
	INF = 10**9+7
	ans = [[INF, N] for _ in range(N)]
	for i in range(N):
		st[i] = list(map(int, input().split()))
	for i in range(M):
		p[i] = list(map(int, input().split()))
	for i in range(N):
		for j in range(M):
			dist = abs(st[i][0]-p[j][0])+abs(st[i][1]-p[j][1])
			if dist < ans[i][0]:
				ans[i][0] = dist
				ans[i][1] = j

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


if __name__ == '__main__':
	main()

Submission status: Accepted

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

P = []
for _ in range(M):
    P.append(list(map(int, input().split())))

def check(i):
    min_d = 10 ** 9
    x = H[i][0]
    y = H[i][1]
    idx = -1
    for i, p in enumerate(P):
        d = abs(x - p[0]) + abs(y - p[1])
        if d < min_d:
            min_d = d
            idx = i
    return idx

for i in range(N):
    near = check(i)
    print(near + 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)]

def manhattan(place, target):
	return abs(target[0] - place[0]) + abs(target[1] - place[1])
ans = [0] * n
for i in range(n):
	dmin = manhattan(ab[i],cd[0])
	for j in range(1,m):
		d = manhattan(ab[i],cd[j])
		if dmin > d:
			dmin = d
			ans[i] = j

for i in range(n):
	print(ans[i]+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)]

def manhattan(place, target):
	return abs(target[0] - place[0]) + abs(target[1] - place[1])
ans = [0] * n
for i in range(n):
	dmin = 10**9
	for j in range(m):
		d = manhattan(ab[i],cd[j])
		if dmin > d:
			dmin = d
			ans[i] = j

for i in range(n):
	print(ans[i]+1)

Submission status: Accepted

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

for i in range(a[0]):
  d = []
  for j in range(a[1]):
    d.append(abs(b[i][0]-c[j][0])+abs(b[i][1]-c[j][1]))
  else:
    print(d.index(min(d))+1)

Submission status: Accepted

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

ans = []
for a, b in ab:
    dis = float('inf')
    num = 0
    for c, d, i in cd:
        if (abs(c-a) + abs(b-d)) < dis:
            dis = (abs(c-a) + abs(b-d))
            num = i + 1
    ans.append(num)

for i in ans:
    print(i)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
lst = []
pnt = []
for i in range(n):
    a,b = map(int,input().split())
    lst.append((a,b))

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

for e in lst:
    for j in range(m):
        d = abs(e[0]-pnt[j][0]) + abs(e[1]-pnt[j][1])
        if j==0:
            mindis = d
            loc = j+1
        elif d < mindis:
            mindis = d
            loc = j+1
    print(loc)

Submission status: Accepted

Solution code:
from sys import stdin
N,M = [int(x) for x in stdin.readline().rstrip().split()]
students = []
for _ in range(N):
    students.append([int(x) for x in stdin.readline().rstrip().split()])

checkpoints = []
for _ in range(M):
    checkpoints.append([int(x) for x in stdin.readline().rstrip().split()])

for i in students:
    tmp = 10**9 
    for ind,j in enumerate(checkpoints):
        dist = abs(i[0] - j[0]) + abs(i[1] - j[1])
        if dist < tmp:
            tmp = dist
            ans = ind+1
    print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

N, M = map(int, input().split())
std_li = [list(map(int, input().split())) for i in range(N)]
chk_li = [list(map(int, input().split())) for j in range(M)]
dist = 0

for i in range(N):
    ctr = 0
    min_dist = pow(10,8) * 4 + 1
    for j in range(M):
        dist = abs(std_li[i][0] - chk_li[j][0]) + abs(std_li[i][1] - chk_li[j][1])
        if dist < min_dist:
            min_dist = dist
            ctr = j + 1
    print(ctr)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
n, m = map(int,input().split())
l = [list(map(int, input().split())) for _ in range(n)]
l1 = [list(map(int,input().split())) for _ in range(m)]
#print(l)
#print(l1)
for i in l:
  l2 = []
  #print(i)
  for j in l1:
    #print(j)
    a = abs(i[0]-j[0]) + abs(i[1]-j[1])
    l2.append(a)
  print(np.argmin(l2)+1)

Submission status: Accepted

Solution code:
import numpy as np

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 (x, y) in A:
    d = np.array([])
    for (a, b) in B:
        d = np.append(d, abs(x-a) + abs(y-b))
    print(np.argmin(d) + 1)

Submission status: Accepted

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

for i in range(n):
  ans = 0
  mdist = 10**9
  for j in range(m):
    if abs(man[i][0] - point[j][0]) + abs(man[i][1] - point[j][1]) < mdist:
      ans = j+1
      mdist = abs(man[i][0] - point[j][0]) + abs(man[i][1] - point[j][1])
  print(ans)

Submission status: Accepted

Solution code:
from sys import exit, stdin

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

for i in range(N):
    answers = []
    for j in range(M):
        ans = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
        answers.append(ans)
    print(answers.index(min(answers))+1)

Submission status: Accepted

Solution code:
def dist(p1, p2):
    return abs(p1[0] - p2[0]) + abs(p1[1] - p2[1])

N, M = map(int, input().split())
students = [tuple(map(int, input().split())) for _ in range(N)]
cps = [tuple(map(int, input().split())) for _ in range(M)]
for s in students:
    ans = (float('inf'), -1)
    for i, cp in enumerate(cps, 1):
        ans = min(ans, (dist(s, cp), i))
    print(ans[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 a,b in ab:
    dec = 1e9
    for j, s in enumerate(cd):
        dist = abs(a-s[0])+abs(b-s[1])
        if dist < dec:
            idx = j
            dec = dist
    print(idx+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])
for i in range(N):
    dis=10**30
    a,b=ab[i]
    ans=-1
    for j in range(M):
        c,d=cd[j]
        if abs(a-c)+abs(b-d)<dis:
            dis=abs(a-c)+abs(b-d)
            ans=j+1
    print(ans)

Submission status: Accepted

Solution code:
n,m = (int(i) for i in input().split())
ab = [[int(i) for i in input().split()] for i in range(n)]
cd = [[int(i) for i in input().split()] for i in range(m)]
#print(cd)
for a,b in ab:
    ans,distance = 0,float('inf')
    for i,cont in enumerate(cd):
        c,d = cont
        #print(abs(a-c)+abs(b-d))
        if distance > abs(a-c)+abs(b-d):
            ans = i
            distance = abs(a-c)+abs(b-d)
    print(ans+1)
    #cd[ans] = [float('inf'),float('inf')]
    #print(cd)

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 i in range(m)]
for a,b in ab:
    ma=10**10
    tp=0
    for i in range(m):
        if ma>abs(a-cd[i][0])+abs(b-cd[i][1]):
            ma=abs(a-cd[i][0])+abs(b-cd[i][1])
            tp=i+1
    print(tp)

Submission status: Accepted

Solution code:
# B問題
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())))
ans = []
for i in range(N):
    tmp_lst = []
    for k in range(M):
        tmp = 0
        tmp = abs(ab[i][0] - cd[k][0]) + abs(ab[i][1] - cd[k][1])
        tmp_lst.append(tmp)
    ans.append(tmp_lst.index(min(tmp_lst)))
for i in range(N):
    print(ans[i] + 1)

Submission status: Accepted

Solution code:
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N, M = nl()

students = []
for i in range(N):
    students.append(nl())

points = []
for i in range(M):
    points.append(nl())

for student in students:
    min_dist = 300000000
    min_i = M
    for i in range(M):
        dist = abs(points[i][0] - student[0]) + abs(points[i][1] - student[1])
        if dist < min_dist:
            min_dist = dist
            min_i = i
    print(min_i+1)

Submission status: Accepted

Solution code:
def abc():
    n, m = map(int, input().split())
    a = []
    b = []
    for i in range(n):
        a.append(list(map(int, input().split())))
    for i in range(m):
        b.append(list(map(int, input().split())))
    for _a in a:
        md = 10 ** 9
        ans = 0
        for i, _b in enumerate(b):
            tmp = abs(_a[0]-_b[0])+abs(_a[1]-_b[1])
            if tmp < md:
                md = tmp
                ans = i + 1
        print(ans)


abc()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
a = [0]*n
b = [0]*n
for i in range(n):
    a[i], b[i] = map(int, input().split())
c = [0]*m
d = [0]*m
for i in range(m):
    c[i], d[i] = map(int, input().split())
ans = [0]*m
for i in range(n):
    for j in range(m):
        ans[j] = abs(a[i]-c[j]) + abs(b[i]-d[j])
    print(ans.index(min(ans))+1)
    ans = [0]*m

Submission status: Accepted

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

for i in range(n):
    z = 1
    l = abs(a[i] - c[0]) + abs(b[i] - d[0])
    for j in range(1,m):
        if abs(a[i] - c[j]) + abs(b[i] - d[j]) < l:
            z = j+1
            l = abs(a[i] - c[j]) + abs(b[i] - d[j])
    print(z)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
st = []
cp = []
for _ in range(n):
    a, b = map(int, input().split())
    st.append((a, b))
for _ in range(m):
    c, d = map(int, input().split())
    cp.append((c, d))
res = []
for i in range(n):
    dists = []
    for j in range(m):
        dist = abs(cp[j][0] - st[i][0]) + abs(cp[j][1] - st[i][1])
        dists.append(dist)
    print(dists.index(min(dists)) + 1)

Submission status: Accepted

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

for n in range(N):
    mindis = 10 ** 9
    for m in range(M):
        dis = abs(student[n][0] - point[m][0]) + abs(student[n][1] - point[m][1])
        if mindis > dis:
            mindis = dis
            ans = m + 1
    print(ans)

Submission status: Accepted

Solution code:
from itertools import permutations as perm
man = lambda a,b:abs(a[0]-b[0])+abs(a[1]-b[1])
N,M = map(int, input().split())

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

inf = float('INF')
ans_lst = [[inf, 0] for i in range(N)]
for i in range(M):
    c,d = map(int, input().split())
    for j in range(N):
        if ans_lst[j][0] > man(XY[j], [c,d]):
            ans_lst[j] = [man(XY[j], [c,d]), i+1]
for i in range(N):
    print(ans_lst[i][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)]
l = []
for i in range(n) :
	Min = 10**9
	ans = 0
	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
	l.append(ans)
for i in l :
	print(i)

Submission status: Accepted

Solution code:
from collections import Counter
from collections import deque
from functools import reduce
from pprint import pprint
import bisect
import copy
import fractions
import itertools
import math
import queue
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))


n, m = MI()
student = [LI() for i in range(n)]
checkpoint = [LI() for i in range(m)]
for i in student:
    tmp = INF
    ans = 0
    for index, j in enumerate(checkpoint):
        if abs(i[0] - j[0]) + abs(i[1] - j[1]) < tmp:
            tmp = abs(i[0] - j[0]) + abs(i[1] - j[1])
            ans = index + 1 
    print(ans)

Submission status: Accepted

Solution code:
n,m=map(int, input().split())
s=[list(map(int, input().split())) for _ in range(n)]
o=[list(map(int, input().split())) for _ in range(m)]
for a,b in s:
  k=[]
  for c,d in o:
    k.append(abs(a-c)+abs(b-d))
  print(k.index(min(k))+1)

Submission status: Accepted

Solution code:
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys
import string

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

N, M = list(map(int, sys.stdin.readline().split()))
A, B = list(zip(*[map(int, sys.stdin.readline().split()) for _ in range(N)]))
C, D = list(zip(*[map(int, sys.stdin.readline().split()) for _ in range(M)]))

C = np.array(C)
D = np.array(D)

for a, b in zip(A, B):
    c = abs(C - a)
    d = abs(D - b)
    xy = (c + d).argmin()
    print(xy + 1)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
ab = [input() for _ in range(n)]
cd = [input() for _ in range(m)]
target = []
for x1y1 in ab:
    x1, y1 = map(int, x1y1.split())
    dist = float('inf')
    for i, x2y2 in enumerate(cd):
        x2, y2 = map(int, x2y2.split())
        temp_dist = abs(x1 - x2) + abs(y1 - y2)
        if temp_dist < dist:
            dist = temp_dist
            temp_target = i+1
    target.append(temp_target)
for i in target:
    print(i)

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
dat_n = []
dat_m = []
for i in range(n):
    a,b = map(int, input().split())
    dat_n.append((a, b))
for i in range(m):
    a,b = map(int, input().split())
    dat_m.append((a, b))
for i in range(n):
    a, b = dat_n[i]
    index = -1
    distance = 1000000001
    for j in range(m):
        c,d = dat_m[j]
        t = abs(a-c) + abs(b-d)
        if t < distance:
            index = j + 1
            distance = t
    print(index)

Submission status: Accepted

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

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

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


for i in range(n):
    num=0
    dist=10**20
    for j in range(m):
        dist1=abs(xy[i][0]-xy1[j][0])+abs(xy[i][1]-xy1[j][1])
        if dist>dist1:
            dist=dist1
            num=j+1
    print(num)

Submission status: Accepted

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

def dist(ab,cd):
  return abs(ab[0]-cd[0]) + abs(ab[1]-cd[1])

AB = [[int(x) for x in input().split()] for _ in range(N)]
CD = [[int(x) for x in input().split()] for _ in range(M)]

answer = []
for ab in AB:
  min_dist = 10**15
  target = 0
  for j,cd in enumerate(CD,1):
    x = dist(ab,cd)
    if min_dist > x:
      min_dist = x
      target = j
  answer.append(target)

print(*answer, sep='\n')

Submission status: Accepted

Solution code:
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)]

for student in students:
    dist=10**10
    ans=0
    for i,point in enumerate(points,start=1):
        if abs(student[0]-point[0])+abs(student[1]-point[1]) < dist:
            dist=abs(student[0]-point[0])+abs(student[1]-point[1])
            ans=i
    print(ans)

Submission status: Accepted

Solution code:
N, M = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for _ in range(N)]
C = [[int(i) for i in input().split()] for _ in range(M)]

for a, b in A:
    mi = 1e10
    ans = 0
    for i, (c, d) in enumerate(C):
        t = abs(a - c) + abs(b - d)
        if t < mi:
            mi = t
            ans = i
    print(ans + 1)

Submission status: Accepted

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

for px,py in pl: 
  ans = 0
  cnt = 1
  minmd = 10**10
  for cx,cy in cp:
    nowmd = abs(px-cx) + abs(py-cy)
    if nowmd < minmd:
      ans = cnt
      minmd = nowmd
    cnt += 1
  print(ans)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
p=[]
for i in range(n):
    p.append(tuple(map(int,input().split())))
c=[]
for i in range(m):
    c.append(tuple(map(int,input().split())))
for e in p:
    ans=0
    mh=float('inf')
    for i,f in enumerate(c,1):
        tmp=abs(e[0]-f[0])+abs(e[1]-f[1])
        if tmp<mh:
            mh=tmp
            ans=i
    print(ans)

Submission status: Accepted

Solution code:
N, M = tuple(map(int, input().split()))
student = []
check = []
ans = []

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

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

for s in student:
    x = 10**9
    tmp = 0
    index = 1
    for c in check:
        y = abs(s[0]-c[0])+abs(s[1]-c[1])
        if (x > y):
            x = y
            tmp = index
        index+=1
    ans.append(tmp)

for a in ans:
    print(a)

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 j in range(m):
    cd.append(list(map(int,input().split())))

for i in range(n):
    far=float("inf")
    number=0
    for j in range(len(cd)):
        ans0=abs(ab[i][0]-cd[j][0])
        ans1=abs(ab[i][1]-cd[j][1])
        ans=ans0+ans1
        if far>ans:
            far=ans
            number=j+1
    print(number)

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 a, b in AB:
    res = [0, float("inf")]
    for i, (c, d) in enumerate(CD):
        if res[1] > abs(a - c) + abs(b - d):
            res[0] = i
            res[1] = abs(a - c) + abs(b - d)
    print(res[0] + 1)

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 j in range(m):
    cd.append(list(map(int,input().split())))

#print(ab)
#print(cd)

for i in range(len(ab)):
    number=0
    far=float("inf")
    for j in range(len(cd)):
        ans0=abs(ab[i][0]-cd[j][0])
        ans1=abs(ab[i][1]-cd[j][1])
        ans=ans0+ans1
        if far>ans:
            far=ans
            number=j+1
    print(number)

Submission status: Accepted

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

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)]
tmp = 0

for i in range(len(ab)):
    mnh = 10**20
    for j in range(len(cd)):
        a, b = ab[i]
        c, d = cd[j]
        if mnh > abs(a-c) + abs(b-d):
            mnh = abs(a-c) + abs(b-d)
            tmp = j
    print(tmp+1)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
students = []
for i in range(0, N):
	students.append(list(map(int, input().split())))
checkpoints = []
for i in range(0, M):
	checkpoints.append(list(map(int, input().split())))
for i in range(0, N):
	nearest = 0
	min = 5000000000000000
	for j in range(0, M):
		d = abs(students[i][0]-checkpoints[j][0]) + abs(students[i][1]-checkpoints[j][1])
		if d < min:
			min = d
			nearest = j+1
	print(nearest)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
ab = [list(map(int, input().split())) for x in range(N)]
cd = [list(map(int, input().split())) for x in range(M)]
for i in range(N):
    ans = 0
    dist = 10 ** 9
    for j in range(M):
        di = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
        if di < dist:
            dist = di
            ans = j + 1

    print(ans)

Submission status: Accepted

Solution code:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

n, m = readmi()
N = []
M = []
for i in range(n):
    N.append(readl())
for i in range(m):
    t = list(readl())
    t.append(i + 1)
    M.append(t)

for i in N:
    s = 0xFFFFFFFF
    index = 0
    nx = i[0]
    ny = i[1]
    for j in M:
        mx = j[0]
        my = j[1]
        mindex = j[2]
        t = abs(nx - mx) + abs(ny - my)
        if s > t:
            s = t
            index = mindex
    print(index)

Submission status: Accepted

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


for i in range(n):
    cnt = 10**9
    num = 0
    for j in range(m):
        c = abs(ab[i][0]-cd[j][0]) + abs(ab[i][1]-cd[j][1])
        if c<cnt:
            cnt = c
            num = j+1
    print(num)