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
from io import StringIO
import unittest

doTest=0

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline
    n,m=list(map(int, readline().strip().split()))
    a=[0]*n
    b=[0]*n
    c=[0]*m
    d=[0]*m

    for i in range(n):
        a[i],b[i]=list(map(int, readline().strip().split()))
    for i in range(m):
        c[i],d[i]=list(map(int, readline().strip().split()))

    for i in range(n):
        minDiff=999999999
        minpnt=9999999
        for j in range(m):
            diff=abs(a[i]-c[j])+abs(b[i]-d[j])
            if diff < minDiff:
                minDiff = diff
                minpnt=j
        print(minpnt+1)
    return

if doTest==0:
    resolve()
    sys.exit()

### ----------------
### ここまでコピぺえ 
### ----------------

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

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

Submission status: Accepted

Solution code:
from numpy import array
student=[]
point=[]
N,M=map(int,input().split())
for z in range(N):
    a,b=map(int,input().split())
    A=array([a,b])
    student.append(A)
for y in range(M):
    c,d=map(int,input().split())
    C=array([c,d])
    point.append(C)
for e in student:
    list=[]
    for f in point:
        g=e-f
        i=0
        for h in g:
            i+=abs(h)
        list.append(i)
    j=min(list)
    count=0
    for k in list:
        if  k==j:
            print(count+1)
            break
        else:
            count+=1

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc057/tasks/abc057_b

N, M = map(int, input().split())

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

chkpoint_list = []
for i in range(M):
    chkpoint = list(map(int, input().split()))
    chkpoint_list.append(chkpoint)

INF = 1000000000
for stu in stu_list:
    min_distance = INF
    for m in range(M):
        distance = abs(chkpoint_list[m][0] - stu[0]) + abs(chkpoint_list[m][1] - stu[1])

        if distance < min_distance:
            min_distance = distance
            ans = m + 1

    print(ans)

Submission status: Accepted

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

for i in range(n):
    a, b = 10 ** 9, 0
    for j in range(m):
        c = abs(s[i][0] - t[j][0]) + abs(s[i][1] - t[j][1])
        if c < a:
            a = c
            b = j
    print(b + 1)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

for k in range(n):
    min_ten = abs(point[0][0]-hito[k][0])+abs(point[0][1]-hito[k][1])
    min_num = 1
    for p in range(1, m):
        kyori = abs(point[p][0]-hito[k][0])+abs(point[p][1]-hito[k][1])
        if kyori < min_ten:
            min_ten = kyori
            min_num = p+1
    print(min_num)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
hito = [list(map(int, input().split())) for i in range(n)]
point = [list(map(int, input().split())) for j in range(m)]
kekka = []
for k in range(n):
    min_ten = abs(point[0][0]-hito[k][0])+abs(point[0][1]-hito[k][1])
    min_num = 1
    for p in range(1, m):
        kyori = abs(point[p][0]-hito[k][0])+abs(point[p][1]-hito[k][1])
        if kyori < min_ten:
            min_ten = kyori
            min_num = p+1
    kekka.append(min_num)
for r in kekka:
    print(r)

Submission status: Accepted

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

for x, y in stu:
    k = []
    for c, d in p:
        k.append(abs(x-c)+abs(y-d))
    print(k.index(min(k))+1)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
l = [list(map(int, input().split())) for i in range(n)]
p = [list(map(int, input().split())) for i in range(m)]
for i in range(n):
    min_l = 1000000000
    index = 0
    for j in range(m):
        d = abs(l[i][0] - p[j][0]) + abs(l[i][1] - p[j][1])
        if min_l > d:
            min_l = d
            index = j
    print(index + 1)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, M: int, a: "List[int]", b: "List[int]", c: "List[int]", d: "List[int]"):
    for ai, bi in zip(a, b):
        ans = mindist = None
        for j in range(M):
            dist = abs(ai - c[j]) + abs(bi - d[j])
            if mindist is None or dist < mindist:
                ans = j + 1
                mindist = dist
        print(ans)


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

def kyori(X,Y):
    return abs(X[0]-Y[0])+abs(X[1]-Y[1])

def near_p(hito):
    temp = []
    for _ in range(m):
        temp.append(kyori(hito,M[_]))
    return temp.index(min(temp))+1

for i in range(n):
    print(near_p(N[i]))

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):
  x,y = a[i]
  
  count = 0
  l = abs(x-c[0][0]) + abs(y-c[0][1])
  for j in range(m):
    
    p,q = c[j]
    
    if l > abs(x-p) + abs(y-q):
      l = abs(x-p)+abs(y-q)
      count = j
      
  print(count+1)

Submission status: Accepted

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

for x, y in stu:
    k = []
    for c, d in p:
        k.append(abs(x-c)+abs(y-d))
    print(k.index(min(k))+1)

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

dist = [0] * m

for a, b in ab:
    dist = [0] * m
    for j in range(m):
        dist[j] = abs(a-cd[j][0]) + abs(b-cd[j][1])
    ans = dist.index(min(dist)) + 1
    print(ans)

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
stu,check = [],[]
for i in range(n):
    stu.append(list(map(int, input().split())))
for i in range(m):
    check.append(list(map(int, input().split())))
for i in range(n):
    dist = float("inf")
    ind = 0
    for j in range(m):
        x = abs(stu[i][0]-check[j][0])+ abs(stu[i][1]-check[j][1])
        if x < dist:
            ind = j
            dist = x
    print(ind+1)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
nx = []
ny = []
mx = []
my = []

for i in range(n):
    a,b = map(int,input().split())
    nx.append(a)
    ny.append(b)
    
for i in range(m):
    c,d = map(int,input().split())
    mx.append(c)
    my.append(d)
    
for i in range(n):
    man = []
    for j in range(m):
        k = abs(nx[i]-mx[j])+abs(ny[i]-my[j])
        man.append(k)
    print(man.index(min(man))+1)

Submission status: Accepted

Solution code:
#ABC057

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):
    x,y = a[i]
    
    count = 0
    l = abs(x-c[0][0]) + abs(y-c[0][1])
    for j in range(m):
        
        p,q = c[j]
        
        if l > abs(x-p)+abs(y-q):
            l = abs(x-p)+abs(y-q)
            count = j
    print(count+1)

Submission status: Accepted

Solution code:
def dist(a, b):
    return abs(a[0]-b[0]) + abs(a[1]-b[1])
n, m = map(int, input().split())
studs = [list(map(int, input().split())) for _ in range(n)]
checks = [list(map(int, input().split())) for _ in range(m)]
for s in studs:
    min_d = 4 * 10 ** 8 + 1
    min_idx = 0

    for idx, c in enumerate(checks):
        d = dist(s, c)
        if d < min_d:
            min_d = d
            min_idx = idx + 1

        elif d==min_d:
            min_idx = min(min_idx, idx+1)
    print(min_idx)

Submission status: Accepted

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

for i in range(N) :
    ansC = M+1
    anslen = 10**10
    for j in range(M) :
        Manh = abs(Sab[i][0] - Cab[j][0]) + abs(Sab[i][1] - Cab[j][1])
        if Manh < anslen :
            ansC = j+1
            anslen = Manh
    print(ansC)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
cd=[list(map(int,input().split())) for _ in range(m)]
for i in range(n):
  l,ans=pow(10,9),0
  for j in range(m):
    x=abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
    if l>x:                           
      ans=j+1
    l=min(l,x)
  print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

for a, b in st:
    temp_d = float('inf')
    temp_m = 0
    for i, cd in enumerate(cp):
        c, d = cd
        d = (abs(c - a) + abs(d - b))
        if d < temp_d:
            temp_m = i + 1
            temp_d = d
    print(temp_m)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
lab=[]
for i in range(N):
    lab.append(list(map(int,input().split())))
lcd=[]
#for i in range(N):
for i in range(M):#間違えた(は？)
    lcd.append(list(map(int,input().split())))
for i in range(N):
    dmin=10**9
    ans=1
    for j in range(M):

        if abs(lab[i][0]-lcd[j][0])+abs(lab[i][1]-lcd[j][1])<dmin:
            #print(abs(lab[i][0]-lcd[j][0])+abs(lab[i][1]-lcd[j][1]))
            dmin=abs(lab[i][0]-lcd[j][0])+abs(lab[i][1]-lcd[j][1])
            ans=j+1
    #print(dmin)
    #答えるものを間違えていた(は？)
    print(ans)

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

index = 0

for i in range(n):
    ans = 2 * 10 ** 16 + 1
    for j in range(m):
        cnt = abs(a[i]-c[j]) + abs(b[i]-d[j])
        if cnt < ans:
            ans = cnt
            index = j+1
    print(index)

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

def how_long(aabb, ccdd):
    return abs(aabb[0]-ccdd[0])+abs(aabb[1]-ccdd[1])

for stu in ab:
    r = [how_long(stu,cd[i]) for i in range(m)]
    print(r.index(min(r))+1)

Submission status: Accepted

Solution code:
def d(a, b):
    return abs(a[0] - b[0]) + abs(a[1] - b[1])


n, m = map(int, input().split())
students = {}
check = {}
for i in range(1, n+1):
    x = list(map(int, input().split()))
    students[i] = x

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

for i in range(1, n+1):
    st = students[i]
    b = 10**10
    ans = 0
    for j in range(1, m+1):
        if b > d(st, check[j]):
            b = d(st, check[j])
            ans = j
    print(ans)

Submission status: Accepted

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

for i in range(n):
    min_d = 10 ** 9
    near = -1
    for j in range (m):
        if abs(nl[i][0]-ml[j][0])+abs(nl[i][1]-ml[j][1])<min_d:
            near=j+1
            min_d=abs(nl[i][0]-ml[j][0])+abs(nl[i][1]-ml[j][1])
    print(near)

Submission status: Accepted

Solution code:
n, m = (int(x) for x in input().split())
a, c  = [], []
for _ in range(n): a.append([int(x) for x in input().split()])
for _ in range(m): c.append([int(x) for x in input().split()])
ans = []
for i in range(n):
    l = [abs(a[i][0] - c[j][0]) + abs(a[i][1] - c[j][1]) for j in range(m)]
    ans.append(l.index(min(l)) + 1)
for i in range(n): print(ans[i])

Submission status: Accepted

Solution code:
def main():
    student_num, point_num = map(int, input().split())
    student_location = [tuple(map(int, input().split())) for _ in range(student_num)]
    point_location = [tuple(map(int, input().split())) for _ in range(point_num)]
    answer = [0] * student_num
    for i in range(student_num):
        min_distance = float("inf")
        for j in range(point_num):
            distance = abs(student_location[i][0] - point_location[j][0]) + abs(student_location[i][1] - point_location[j][1])
            if min_distance > distance:
                answer[i] = j + 1
                min_distance = distance
    for ans in answer:
        print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#python3
INF = 10**9
def dist(tuple_a, tuple_b):
    return abs(tuple_a[0] - tuple_b[0]) + abs(tuple_a[1] - tuple_b[1])

def main():
    n, m = map(int, input().split())
    p = []
    for _ in range(n):
        a, b = map(int, input().split())
        p.append((a, b))
    chp = []
    for _ in range(m):
        c, d = map(int, input().split())
        chp.append((c, d))
    ans = []
    for i in range(n):
        tmp = INF
        v = 0
        point = p[i]
        for j in range(m):
            di = dist(point, chp[j])
            if  di < tmp: 
                tmp = di
                v = j
        ans.append(v)
    for i in range(n):
        print(ans[i]+1)
main()

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:
    best = float('inf')
    result = -1
    for i in range(M):
        c, d = cd[i]
        t = abs(a - c) + abs(b - d)
        if t < best:
            result = i + 1
            best = t
    print(result)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
# N: student, M:check point
stu_x = {}
stu_y = {}
chk_x = {}
chk_y = {}
for i in range(N):
    stu_x[i], stu_y[i] = map(int, input().split())
for i in range(M):
    chk_x[i], chk_y[i] = map(int, input().split())

for i in range(N):
    X = stu_x[i]
    Y = stu_y[i]
    dis = []
    for j in range(M):
        row = abs(X - chk_x[j])
        col = abs(Y - chk_y[j])

        dis.append(row + col)
    index = dis.index(min(dis)) + 1
    print(index)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
now=[tuple(map(int,input().split())) for i in range(n)]
p=[tuple(map(int,input().split())) for i in range(m)]
for a in now:
  ans=10**10
  for i in range(m):
    if ans>abs(p[i][0]-a[0])+abs(p[i][1]-a[1]):
      ind=i
      ans=abs(p[i][0]-a[0])+abs(p[i][1]-a[1])
  print(ind+1)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
S = [list(map(int, input().split())) for _ in range(N)]
C = [list(map(int, input().split())) for _ in range(M)]
for a, b in S:
    dist = [abs(a-c) + abs(b-d) for c, d in C]
    print(dist.index(min(dist))+1)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

    ST = []
    for _ in range(N):
        ST.append(tuple(map(int, input().split())))

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

    # print(N, M)
    # print(ST)
    # print(CP)

    return N, M, ST, CP


def solve(N, M, ST, CP):
    def get_dist(xy1, xy2):
        x1, y1 = xy1
        x2, y2 = xy2

        return abs(x1 - x2) + abs(y1 - y2)

    res = []
    for st in ST:
        min_cp, min_dist = 0, float("inf")
        for i, cp in enumerate(CP):
            dist = get_dist(st, cp)
            if dist < min_dist:
                min_dist = dist
                min_cp = i
        res.append(min_cp + 1)

    return res


if __name__ == '__main__':
    ans = solve(*args())
    for a in ans:
        print(a)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
stdt = []
chpt = []
for _ in range(N):
    a, b = map(int, input().split())
    stdt.append((a, b))
for _ in range(M):
    a, b = map(int, input().split())
    chpt.append((a, b))

for s in stdt:
    a, b, = s[0], s[1]
    m = 100000000000000
    i = 0
    for j in range(M):
        d = abs(a - chpt[j][0]) + abs(b - chpt[j][1])
        if m > d:
            m = d
            i = j + 1
    print(i)

Submission status: Accepted

Solution code:
n, m = [int(i) for i in 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 i in range(n):
    l = [abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1]) for j in range(m)]
    print(l.index(min(l)) + 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)]

for i in range(n):
  a, b = ab[i]
  
  dis = 10 ** 20
  res = 0
  for i, check in enumerate(cd):
    tmp_dis = abs(a - check[0]) + abs(b - check[1])
    if dis == tmp_dis:
      continue
    if tmp_dis < dis:
      dis = tmp_dis
      res = i + 1
  
  print(res)

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:
    n = float('inf')
    ans = 0
    for i, tmp in enumerate(cd):
        c, d = tmp
        m = abs(a-c)+abs(b-d)
        if n > m:
            n = m
            ans = i+1
    print(ans)

Submission status: Accepted

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

ans = []
for i in range(N):
    tmp = [0]*M
    for j in range(M):
        tmp[j] = abs(student[i][0]-checkpoint[j][0])+abs(student[i][1]-checkpoint[j][1])
    ans.append(tmp.index(min(tmp)))

[print(i+1) for i in ans]

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
s = []
p = []
for i in range(n):
  x,y = map(int,input().split())
  s += [(x,y)]
for i in range(m):
  x,y = map(int,input().split())
  p += [(x,y)]

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


for i in range(n):
  ans = 1
  min_d = dist(s[i], p[0])
  for j in range(1, m):
    d = dist(s[i], p[j])
    if d < min_d:
      ans = j+1
      min_d = d
  print(ans)

Submission status: Accepted

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

ans = []

for i in a:
  count = 10**10
  check = 0
  for j in range(m):
    if count > abs(i[0]-b[j][0])+abs(i[1]-b[j][1]):
      check = j+1
      count = abs(i[0]-b[j][0])+abs(i[1]-b[j][1])
    
  ans.append(check)
for i in ans:
  print(i)

Submission status: Accepted

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

min_dist = 10 ** 10
min_num = M
for i in range(N) :
    for j in range(M) :
        dist = abs(stu_li[i][0] - chk_li[j][0]) + abs(stu_li[i][1] - chk_li[j][1])
        if dist < min_dist : 
            min_dist = dist
            min_num = j
    print(min_num + 1)
    min_dist = 10 ** 10
    min_num = M

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=[]
b=[]
c=[]
d=[]
for i in range(n):
    a_i,b_i=map(int,input().split())
    a.append(a_i)
    b.append(b_i)
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):
    a_i=a[i]
    b_i=b[i]
    dis=-1
    for j in range(m):
        buf=abs(a_i-c[j])+abs(b_i-d[j])
        if dis<0 or buf<dis:
            dis=buf
            ans=j+1
    print(ans)

Submission status: Accepted

Solution code:
[n,m]=list(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):
    kyorimin=10**9
    for j in range(m):
        kyori=abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
        if kyorimin>kyori:
            goal=j+1
            kyorimin=kyori
    ans.append(goal)
for i in range(len(ans)):
    print(ans[i])

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
cd=[list(map(int,input().split())) for _ in range(m)]
for i in range(n):
  mn=1000000000
  ans=0
  for j in range(m):
    d=abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
    if d<mn:
      mn=d
      ans=j+1
  print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
people = [list(map(int, input().split())) for i in range(N)]
point = [list(map(int, input().split())) for i in range(M)]
ans = [-1] * N
def calc_dist(a, b):
    return abs(a[0] - b[0]) + abs(a[1] - b[1])


for i in range(len(people)):
    tmp = 1000000000
    for j in range(len(point)):
        dist = calc_dist(people[i], point[j])
        if dist < tmp:
            ans[i] = j
            tmp = dist

for i in ans:
    print(i+1)

Submission status: Accepted

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

for i in range(n):
    x = 10**9
    for j in range(m):
        man = abs(stu[i][0] - che[j][0]) + abs(stu[i][1] - che[j][1])
        if man < x:
            c_num = j + 1
            x = man
    ans.append(c_num)
for k in ans:
    print(k)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
a=[]
b=[]
c=[]
d=[]
x=[]
y=[]
for i in range(N):
  a_i,b_i=map(int,input().split())
  a.append(a_i)
  b.append(b_i)
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):
  x=[]
  for j in range(M):
    l=abs(a[i]-c[j])+abs(b[i]-d[j])
    x.append(l)
    u=min(x)
    w=x.index(u)+1
  y.append(w)
for k in range(N):
  print(y[k])

Submission status: Accepted

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

def manhattan(lis1,lis2):
    d=0
    for i in range(len(lis1)):
        d+=abs(lis1[i]-lis2[i])
    return d
  
for i in range(n):
    d=3*10**8
    idx=1
    for j in range(m):
        d_new = manhattan(lis1[i],lis2[j])
        if d_new < d:
            d = d_new
            idx = j+1
    print(idx)

Submission status: Accepted

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

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

xy = []
for _ in range(m):
    x, y = map(int, input().split())
    xy.append((x, y))

# O(nm)
for s, t in students:
    MIN = float('infinity')
    checkpoint = 0
    for i in range(len(xy)):
        x, y = xy[i]
        distance = abs(s - x) + abs(t - y)
        if distance < MIN:
            MIN = distance
            checkpoint = i
    print(checkpoint + 1)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=[[int(i) for i in input().split()] for l in range(n)]
b=[[int(i) for i in input().split()] for l in range(m)]
for A in a:
    c=1
    r=0
    m=10000000000
    for B in b:
        k=abs(A[0]-B[0])+abs(A[1]-B[1])
        if m>k:
            m=k
            r=c
        c+=1
    print(r)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
f = lambda k:[list(map(int,input().split())) for _ in range(k)]
n,m = map(int,input().split())
lln = f(n)
llm = f(m)

for a,b in lln:
  mi,p = 10**9,m
  for i, [c,d] in enumerate(llm):
    di = abs(c-a)+abs(d-b)
    if di < mi:
      mi,p = di,i+1
  print(p)

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.append(A)
    b.append(B)
c=[]
d=[]
for i in range(M):
    C,D=map(int,input().split())
    c.append(C)
    d.append(D)
ans=[]
for i in range(N):
    ans.append(10**9)
for i in range(N):
    for j in range(M):
        m=abs(a[i]-c[j])+abs(b[i]-d[j])
        ans[i]=min(m,ans[i])

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

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):
    d = [0]*m
    for j in range(m):
        d[j] = abs(A[i]-C[j])+abs(B[i]-D[j])
    print(d.index(min(d))+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)]

for i in range(n):
    x=ab[i][0]
    y=ab[i][1]
    ans = [float('inf')] * 2
    for j in range(m):
        man=abs(x-cd[j][0])+abs(y-cd[j][1])
        if ans[0]>man:
            ans=[man,j+1]

    print(ans[1])

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 a, b in student:
    dst_min = float('inf')
    ans = float('inf')
    for i, (c, d) in enumerate(check_points):
        now = abs(a - c) + abs(b - d)
        if now < dst_min:
            dst_min = now
            ans = i + 1
    print(ans)

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())
E=[10000000000]*N
F=[1]*N
tmp=('inf')
for i in range (N):
	for j in range (M):
		tmp=(abs(A[i]-C[j])+abs(B[i]-D[j]))
		if E[i]>tmp:
			F[i]=j+1
			E[i]=tmp
		
for i in range (N):
	print(F[i])

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

ans = []
for a, b in AB:
    dist = 10 ** 9
    goal = -1
    for i, cd in enumerate(CD):
        c, d = cd
        di = abs(a-c)+abs(b-d)
        if di < dist:
            goal = i + 1
            dist = di
    ans.append(goal)

print(*ans, sep="\n")