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:
import sys

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

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

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

for i in range(n):
    min = sys.maxsize
    ans = -1
    for j in range(m):
        distance = abs(students[i][0] -
                       checkpoints[j][0]) + abs(students[i][1] -
                                                checkpoints[j][1])
        if min > distance:
            min = distance
            ans = j + 1
    print(ans)

Submission status: Accepted

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

ans = []
for s in students:
  dist = float("inf")
  nearest = -1
  for idx, c in enumerate(checkpoints):
    d_i = abs(int(s[0])-int(c[0])) + abs(int(s[1])-int(c[1]))
    if dist > d_i:
      dist = d_i
      nearest = idx+1
  ans.append(nearest)
for a in ans:
  print(a)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
a=[]
b=[]
c=[]
d=[]
for i in range(n):
    A,B=map(int,input().split())
    a.append(A)
    b.append(B)
for j in range(m):
    C,D=map(int,input().split())
    c.append(C)
    d.append(D)
ans=[]
for k in range(n):
    L=[]
    for l in range(m):
        L.append(abs(a[k]-c[l])+abs(b[k]-d[l]))
    ans.append(L.index(min(L))+1)
for o in ans:
    print(o)

Submission status: Accepted

Solution code:
N,M = map(int,raw_input().split())
A = []
T = []
for i in range(0,N):
        a,b = raw_input().split()
        A.append(a)
        A.append(b)
        T.append(A)
        A = []
B = []
S = []
for i in range(0,M):
        c,d = raw_input().split()
        B.append(c)
        B.append(d)
        S.append(B)
        B = []
ans = []
for i in range(0,N):
        for j in range(0,M):
                t = abs(int(T[i][0])-int(S[j][0])) + abs(int(T[i][1])-int(S[j][1]))
                ans.append(t)
                #print t
        print ans.index(min(ans))+1
        ans = []

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
std = []
for i in range(n):
  std.append(list(map(int,input().split())))
chk = []
for j in range(m):
  chk.append(list(map(int,input().split())))
for i in range(n):
  can = []
  for j in range(m):
    can.append([abs(std[i][0]-chk[j][0])+abs(std[i][1]-chk[j][1]),j+1])
  print(min(can)[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)]
ans = []
for i in range(n):
    mm = 10 ** 9
    nn = 0
    for j in range(m):
        if mm > abs(a[i][0] - b[j][0]) + abs(a[i][1] - b[j][1]):
            mm = abs(a[i][0] - b[j][0]) + abs(a[i][1] - b[j][1])
            nn = j + 1
    ans.append(nn)
for i in range(n):
    print(ans[i])

Submission status: Accepted

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

ab = []
for _ 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, i + 1])

INF = 10 ** 9
def check_point(a, b): #a, bが集まるチェックポイントの番号
    distance = INF
    ans = 1
    for c, d, i in cd:
        if distance > abs(a - c) + abs(b - d):
            distance = abs(a - c) + abs(b - d)
            ans = i
    return ans

for a, b in ab:
    print (check_point(a, b))

Submission status: Accepted

Solution code:
n, m = list(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)]

ans = []
for i in range(n):
    dis = float("inf")
    index = 0
    for j in range(m):
        if dis > abs(a[i][0]-c[j][0])+abs(a[i][1]-c[j][1]):
            dis = abs(a[i][0]-c[j][0])+abs(a[i][1]-c[j][1])
            index = j+1
    ans.append(index)

for i in ans:
    print(i)

Submission status: Accepted

Solution code:
# ABC 57, mB - checkpoints

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

n, m = [int(el) for el in input().split(' ')]
S = []
for i in range(n):
    a, b = input().split(' ')
    S.append((int(a), int(b)))

T = []
for i in range(m):
    c, d = input().split(' ')
    T.append((int(c), int(d)))


for i in range(n):
    D = []
    for j in range(m):
        D.append(dist(S[i], T[j]))
    print(D.index(min(D))+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)

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

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

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
e = [list(map(int,input().split())) for i in range(n)]
f = [list(map(int,input().split())) for i in range(m)]
d_cnt = [[] for i in range(n)]
for j in range(n):
  for i in range(m):
    d_cnt[j].append(abs(e[j][0]-f[i][0])+abs(e[j][1]-f[i][1]))
for i in range(n):
  print(d_cnt[i].index(min(d_cnt[i]))+1)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=[]
b=[]
c=[]
d=[]
for i in range(n):
	aa,bb=map(int,input().split())
	a.append(aa)
	b.append(bb)
for i in range(m):
	cc,dd=map(int,input().split())
	c.append(cc)
	d.append(dd)
for i in range(n):
	dis=[]
	for j in range(m):
		dis.append(abs(a[i]-c[j])+abs(b[i]-d[j]))
	for j in range(m):
		if min(dis)==dis[j]:
			print(j+1)
			break

Submission status: Accepted

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

abLst = [list(map(int, input().split())) for i in range(N)]
cdLst = [list(map(int, input().split())) for i in range(M)]

ansLst = [0] * N

for i in range(N):
    tmpMin = 100000000000
    ans = 0
    for j in range(M):
        tmp = abs(abLst[i][0] - cdLst[j][0]) + abs(abLst[i][1] - cdLst[j][1])
        if tmpMin > tmp:
            tmpMin = tmp
            ans = j + 1
    ansLst[i] = ans

for i in ansLst:
    print(i)

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 j in range(M) ]
for i in range(N):
    ans = 0
    d = 10**9
    for j in range(M):
        tmp = abs(a[i][0]-b[j][0])+abs(a[i][1]-b[j][1])
        if tmp<d:
            d = tmp
            ans = j+1
    print(ans)

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:
  dist_p = 0
  dist_m = 4*10**8
  for idx, checkpoint in enumerate(checkpoints):
    dist_temp = abs(student[0]-checkpoint[0]) + abs(student[1]-checkpoint[1])
    if dist_temp < dist_m:
      dist_p = idx+1
      dist_m = dist_temp
  print(dist_p)

Submission status: Accepted

Solution code:
def manhattan(a,b,c,d):
    return abs(a-c)+abs(b-d)

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

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

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

for x in X:
    dist = 1e9
    choise = 1
    for n,y in enumerate(Y):
        mh = manhattan(x[0],x[1],y[0],y[1])
        if mh < dist:
            dist = mh
            choise = n+1
    print(choise)

Submission status: Accepted

Solution code:
N,M=[int(x) for x in input().split()]

def loc(ab):
  d=10**9
  t=''
  for m in range(M):
    td=abs(ab[0]-cd[m][0])+abs(ab[1]-cd[m][1])
    if td<d:
      d=td
      t=m
  return t

ab=['']*N
cd=['']*M
for i in range(N):
  ab[i]=[int(x) for x in input().split()]

for i in range(M):
  cd[i]=[int(x) for x in input().split()]

for n in range(N):
  print(loc(ab[n])+1)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
x = [list(map(int,input().split())) for i in [0]*(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())
x = [list(map(int,input().split())) for i in range(n)]
y = [list(map(int,input().split())) for i in range(m)]
for a,b in x:
  l = [abs(a-c)+abs(b-d) for c,d in y]
  print(l.index(min(l))+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
stu = [list(map(int,input().split())) for i in range(n)]
chk = [list(map(int,input().split())) for i in range(m)]
for ab in stu:
  manh = [abs(ab[0]-cd[0])+abs(ab[1]-cd[1]) for cd in chk]
  print(manh.index(min(manh))+1)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
s = []
l = []
for i in range(n):
    a = list(map(int,input().split()))
    s.append(a)
for i in range(m):
    b = list(map(int,input().split()))
    l.append(b)
ansl = []
for i in range(n):
    ans1 = abs(s[i][0]-l[0][0]) + abs(s[i][1]-l[0][1])
    ans = 1
    for j in range(m):
        ans2 = abs(s[i][0] - l[j][0]) + abs(s[i][1] - l[j][1])
        if ans2 < ans1:
            ans1 = ans2
            ans = j + 1
    ansl.append(ans)
for i in range(n):
    print(ansl[i])

Submission status: Accepted

Solution code:
def main():
    N, M = map(int, input().split())
    S = []
    for n in range(N):
        x, y = map(int, input().split())
        S.append((x, y))
    C = []
    for m in range(M):
        x, y = map(int, input().split())
        C.append((x, y))
    ans = []
    for i, s in enumerate(S):
        d = float('INF')
        ans.append(0)
        for j, c in enumerate(C):
            dd = abs(s[0] - c[0]) + abs(s[1] - c[1])
            if d > dd:
                ans[i] = j + 1
                d = dd
    print('\n'.join(map(str, ans)))


main()

Submission status: Accepted

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

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

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

for i in range(len(la)):
    mi = 1000000001
    ans = 0
    for j in range(len(ca)):
        p = abs(la[i][0]-ca[j][0]) + abs(la[i][1]-ca[j][1])
        if  p < mi:
            mi = p
            ans = j+1
    print(ans)

Submission status: Accepted

Solution code:
N, M = [int(x) for x in input().split()]
students = []
checkpoints = []

for i in range(N):
	students.append([int(x) for x in input().split()])
for i in range(M):
	checkpoints.append([int(x) for x in input().split()])
def distance(s, c):
  return abs(s[0]- c[0]) + abs(s[1]- c[1])

for s in students:
	mind = 10**10
	mini = -1
	for i, c in enumerate(checkpoints):
		d = distance(s, c)
		if d < mind:
			mind = d
			mini = i+1
	print(mini)

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

def calc_nearest(student,checkpoints):
    nearest_idx = 50
    max_dist = 10**9
    i = 1
    for checkpoint in checkpoints:
        dist = abs(student[0]-checkpoint[0]) + abs(student[1]-checkpoint[1])
        if max_dist > dist:
            nearest_idx = i
            max_dist = dist
        i += 1
    return nearest_idx

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, fractions, itertools


def solve(N: int, M: int, a: "List[int]", b: "List[int]", c: "List[int]", d: "List[int]"):
    for i in range(N):
        mn = 1e9
        idx = -1
        for j in range(M):
            dis = abs(a[i] - c[j]) + abs(b[i] - d[j])
            if dis < mn:
                mn = dis
                idx = j+1
        print(idx)

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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:
n, m = map(int, input().split())
students = []
for _ in range(n):
    students.append(list(map(int, input().split())))

points = []
for i in range(m):
    c, d = map(int, input().split())
    points.append([c, d, i + 1])


for s in students:
    tmp_d, tmp_i = 10 ** 18, -1
    for p in points:
        dif = abs(s[0] - p[0]) + abs(s[1] - p[1])
        if dif < tmp_d:
            tmp_d = dif
            tmp_i = p[2]
    print(tmp_i)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
S = [input().split() for i in range(N)]
T = [input().split() for j in range(M)]

L = 0
t = 0

for k in range(N):
    L = 1000000000000
    for l in range(M):
        if L > abs(int(S[k][0]) - int(T[l][0])) + abs(int(S[k][1]) - int(T[l][1])):
            L = abs(int(S[k][0]) - int(T[l][0])) + abs(int(S[k][1]) - int(T[l][1]))
            t = l+1
    print(t)

Submission status: Accepted

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

for a,b in students:
    min_d = 10**9 
    min_i = 0
    for i,(c,d) in enumerate(checks):
        dis = abs(a-c) + abs(b-d)
        if dis < min_d:
            min_d = dis
            min_i = i
#         print(a,b,c,d,dis,min_d,min_i,i)
    print(min_i+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())

check = [[0]*M for _ in range(N)]

for i in range(N):
    for j in range(M):
        check[i][j] = max(a[i]-c[j],c[j]-a[i]) + max(b[i]-d[j],d[j]-b[i])
    print(check[i].index(min(check[i])) + 1)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a_b = [list(map(int, input().split())) for _ in range(n)]
c_d = [list(map(int, input().split())) for _ in range(m)]
ans = []
for i in range(n):
    ans_sub = []
    for j in range(m):
        ans_sub.append(abs(a_b[i][0]-c_d[j][0]) + abs(a_b[i][1]-c_d[j][1]))
    ans.append(ans_sub.index(min(ans_sub)) + 1)
for i in range(n):
    print(ans[i])

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
students=[]
checkpoints=[]
for i in range(n):
  students.append(input().split())
for j in range(m):
  checkpoints.append(input().split())
#print(students,checkpoints)
nearest=m
nearestdistance=2*10**8
distance=0
for s in range(n):
  for c in range(m):
    distance=abs(int(students[s][0])-int(checkpoints[c][0]))+abs(int(students[s][1])-int(checkpoints[c][1]))
    if distance<nearestdistance:
      nearest=c+1
      nearestdistance=distance
      #print('too near')
  print(nearest)
  nearest=m
  nearestdistance=2*10**8

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 i in range(N):
  d=10**9
  n=0
  for j in range(M):
    x=abs(s[i][0]-c[j][0])+abs(s[i][1]-c[j][1])
    if x<d:
      d=x
      n=j+1
  print(n)

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 a, b in ab :
    mi, mv = 0, float('inf')
    for i, (c, d) in enumerate(cd) :
        if abs(a-c) + abs(b-d) < mv :
            mi = i
            mv = abs(a-c) + abs(b-d)
    print(mi+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 j in range(m)]
for i in range(n):
    dist = []
    x = ab[i][0]
    y = ab[i][1]
    for j in range(m):
        dist.append(abs(x - cd[j][0]) + abs(y - cd[j][1]))

    print(dist.index(min(dist))+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 i in range(m):
    cd.append(list(map(int, input().split())))
for i in range(n):
    dis = []
    for j in range(m):
        dis.append(abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1]))
    print(dis.index(min(dis)) + 1)

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
c = []
d = []
g = []
for i in range(a):
    e, f = map(int, input().split())
    c.append([e, f])
for i in range(b):
    e, f = map(int, input().split())
    d.append([e, f])
for i in range(a):
    f = 10 ** 9
    h = 0
    for j in range(b):
        if f > abs(c[i][0] - d[j][0]) + abs(c[i][1] - d[j][1]):
            f = abs(c[i][0] - d[j][0]) + abs(c[i][1] - d[j][1])
            h = j + 1
    g.append(h)
for i in g:
    print(i)

Submission status: Accepted

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

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

for s in student_list:
    tmp = []
    for c in check_list:
        tmp.append(abs(s[0]-c[0]) + abs(s[1]-c[1]))
    print(tmp.index(min(tmp))+1)

Submission status: Accepted

Solution code:
N,M = list(map(int,input().split()))
s = [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):
  d = []
  for j in range(M):
    d.append(abs(s[i][0]-c[j][0])+abs(s[i][1]-c[j][1]))
  print(d.index(min(d))+1)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
student=[list(map(int,input().split())) for _ in range(n)]
checkpoint=[list(map(int,input().split())) for _ in range(m)]
for i in range(n):
    distance=[]
    for j in range(m):
        calc=0
        calc=abs(student[i][0]-checkpoint[j][0])+abs(student[i][1]-checkpoint[j][1])
        distance.append(calc)
    print(distance.index(min(distance))+1)

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
c = [list(map(int, input().split()))for _ in range(a)]
d = [list(map(int, input().split()))for _ in range(b)]
e = []
for i in range(a):
    f = 10 ** 9
    g = 0
    for j in range(b):
        if f > abs(c[i][0] - d[j][0]) + abs(c[i][1] - d[j][1]):
            f = abs(c[i][0] - d[j][0]) + abs(c[i][1] - d[j][1])
            g = j + 1
    e.append([g, f])
for i in range(a):
    print(e[i][0])

Submission status: Accepted

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


for i in range(m):
    temp = list(map(int, input().split()))
    c.append(temp[0])
    d.append(temp[1])

ans = []

for i in range(n):
    min_dis = 10 ** 9
    for j in range(m):

        distance = abs(c[j] - a[i]) + abs(d[j] - b[i])

        #print("学生{}, {} チェックポイント{}, {}".format(a[i], b[i], c[j], d[j]))
        #print("距離番号{} = {}".format(j, distance))
        
        if min_dis > distance:
            min_dis = distance
            min_num = j
            #print("更新")
        
    ans.append(min_num)
    
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 _ in range(N)]
CD = [list(map(int,input().split()))+[i] for i in range(M)]
INF = 10**10

for pos in AB:
    dist = INF
    res = 0
    ai = pos[0]
    bi = pos[1]
    for check in CD:
        ci = check[0]
        di = check[1]
        t = abs(ai-ci)+abs(bi-di)
        if t < dist:
            dist = t
            res = check[2]+1
    print(res)

Submission status: Accepted

Solution code:

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def main():
    num_people, num_check = map(int, input().split())
    data_people = [list(map(int, input().split())) for i in range(num_people)]
    data_check = [list(map(int, input().split())) for i in range(num_check)]

    for i in range(num_people):
        ans_ind = 1
        kyori = abs(data_people[i][0] - data_check[0][0]) + abs(data_people[i][1] - data_check[0][1])
        for j in range(1, num_check):
            kari = abs(data_people[i][0] - data_check[j][0]) + abs(data_people[i][1] - data_check[j][1])
            if kari < kyori:
                kyori = kari
                ans_ind = j + 1
        print(ans_ind)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b = LI()
    print((a+b)%24)
    return

#B
def B():
    n, m = LI()
    ab = LIR(n)
    cd = LIR(m)
    for a, b in ab:
        ans = inf
        an = 0
        for num, cdi in enumerate(cd):
            c, d = cdi
            if ans > abs(a - c) + abs(b - d):
                ans = abs(a - c) + abs(b - d)
                an = num
        print(an+1) 
    return

#C
def C():
    return

#D
def D():
    return

#Solve
if __name__ == '__main__':
    B()

Submission status: Accepted

Solution code:
def main():
    n,m=map(int,input().split(' '))
    n_list=[[int(i) for i in list(input().split(' '))] for i in range(n)]
    m_list=[[int(i) for i in list(input().split(' '))] for i in range(m)]
    inf = 4*10**8+1
    for i in n_list:
        tmp = inf
        ans = 1
        for num,j in enumerate(m_list):
            m_dis=abs(i[0]-j[0]) +abs(i[1]-j[1])
            if m_dis < tmp:
                tmp = m_dis
                ans = num+1
        print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    n, m = map(int, input().split())
    students = [tuple(map(int, input().split())) for i in range(n)]
    check_points = [tuple(map(int, input().split())) for i in range(m)]

    for a, b in students:
        dist = [abs(a - c) + abs(b - d) for c, d in check_points]
        print(dist.index(min(dist)) + 1)

    # for st in students:
    #     min_pt = check_points[0]
    #     for pt in check_points:
    #         if abs(pt[0] - st[0]) + abs(pt[1] - st[1]) < \
    #            abs(min_pt[0] - st[0]) + abs(min_pt[1] - st[1]):
    #             min_pt = pt
    #     print(check_points.index(min_pt) + 1)


if __name__ == "__main__":

    main()

Submission status: Accepted

Solution code:
def main():
    n, m = map(int, input().split())
    students = [tuple(map(int, input().split())) for i in range(n)]
    check_points = [tuple(map(int, input().split())) for i in range(m)]

    for st in students:
        min_pt = check_points[0]
        for pt in check_points:
            if abs(pt[0] - st[0]) + abs(pt[1] - st[1]) < \
               abs(min_pt[0] - st[0]) + abs(min_pt[1] - st[1]):
                min_pt = pt
        print(check_points.index(min_pt) + 1)


if __name__ == "__main__":

    main()

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 a,b in S:
	m=10**9
	cnt=0
	for c,d in C:
		l=abs(c-a)+abs(d-b)
		cnt+=1
		if m>l:
			m=min(m,l)
			ans=cnt
	print(ans)

Submission status: Accepted

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

starts = [0]*N
for _ in range(N):
    starts[_] = list(map(int, input().split()))

ends = [0]*M
for _ in range(M):
    ends[_] = list(map(int, input().split()))

for _ in range(N):
    cand = [abs(starts[_][0] - e[0]) + abs(starts[_][1] - e[1]) for e in ends]
    print(cand.index(min(cand))+1)

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

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

Submission status: Accepted

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

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

for i in range(n):
    ans = []
    for j in range(m):
        s = abs(li_student[i][0] - li_check[j][0]) + abs(li_student[i][1] - li_check[j][1])
        ans.append(s)
    t = ans.index(min(ans)) + 1
    print(t)

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
c = [list(map(int, input().split()))for _ in range(a)]
d = [list(map(int, input().split()))for _ in range(b)]
for i in range(len(c)):
    e = 10**9
    f = 0
    for j in range(len(d)):
        g = abs(c[i][0] - d[j][0]) + abs(c[i][1] - d[j][1])
        if e > g:
            e = g
            f = j + 1
    print(f)

Submission status: Accepted

Solution code:
#入力
n,m=map(int,input().split())
a=[]
b=[]
c=[]
d=[]
ans=[]
for i in range(n):
    tmp_a,tmp_b=map(int,input().split())
    a.append(tmp_a)
    b.append(tmp_b)
for i in range(m):
    tmp_c,tmp_d=map(int,input().split())
    c.append(tmp_c)
    d.append(tmp_d)

#n人の生徒それぞれについて、m個のポイントへのマンハッタン距離を算出し、距離が最小のポイントをansリストに代入
for i in range(n):
    tmp_ans=[]
    for j in range(m):
        tmp_ans.append(abs(a[i]-c[j])+abs(b[i]-d[j]))
    ans.append(tmp_ans.index(min(tmp_ans))+1)
for i in range(n):
    print(ans[i])

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):
    min_dist=abs(a[i]-c[0])+abs(b[i]-d[0])
    checkpoint=1
    for j in range(1,m):
        cur_dist=abs(a[i]-c[j])+abs(b[i]-d[j])
        if min_dist>cur_dist:
            min_dist = cur_dist
            checkpoint = j+1
    print(checkpoint)

Submission status: Accepted

Solution code:
MOD = 10**9 + 7

N,M = map(int,input().split())
a = [0] * N
b = [0] * N
c = [0] * M
d = [0] * M
min = [MOD] * N
min_num = [0] * N
for i in range(N): a[i],b[i] = map(int,input().split())
for t in range(M): c[t],d[t] = map(int,input().split())

for j in range(N):
    for q in range(M):
        dist = abs(a[j] - c[q]) + abs(b[j] - d[q])
        if dist < min[j]:
            min[j] = dist
            min_num[j] = q + 1
for k in min_num: print(k)

Submission status: Accepted

Solution code:
MOD = 10**9 + 7

N,M = map(int,input().split())
a = [0] * N
b = [0] * N
c = [0] * M
d = [0] * M
min = [MOD] * N
min_num = [0] * N
for i in range(N):
    a[i],b[i] = map(int,input().split())
for t in range(M):
    c[t],d[t] = map(int,input().split())

for j in range(N):
    for q in range(M):
        dist = abs(a[j] - c[q]) + abs(b[j] - d[q])
        if dist < min[j]:
            min[j] = dist
            min_num[j] = q + 1
for k in min_num:
    print(k)

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)]
INF=10**9+7
for i in a:
    ans=INF
    for j in range(m):
        tmp=abs(i[0]-c[j][0])+abs(i[1]-c[j][1])
        if tmp<ans:
            ans=tmp
            num=j+1
    print(num)