Problem:


Score : 200 points

Problem Statement

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

The coordinates of the i-th student (1 \leq i \leq N) is (a_i,b_i), and the coordinates of the checkpoint numbered j (1 \leq j \leq M) is (c_j,d_j).

When the teacher gives a signal, each student has to go to the nearest checkpoint measured in Manhattan distance. 

The Manhattan distance between two points (x_1,y_1) and (x_2,y_2) is |x_1-x_2|+|y_1-y_2|.

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

If there are multiple nearest checkpoints for a student, he/she will select the checkpoint with the smallest index.

Which checkpoint will each student go to?

Constraints

1 \leq N,M \leq 50

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

All input values are integers.

Input

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

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

Output

Print N lines.

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

Sample Input 1

2 2
2 0
0 0
-1 0
1 0

Sample Output 1

2
1

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

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

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

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

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

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

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

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

Sample Input 2

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

Sample Output 2

3
1
2

There can be multiple checkpoints at the same coordinates.

Sample Input 3

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

Sample Output 3

5
4
3
2
1



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


Sample output:
2
1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
n, m = list(map(int, input().split()))
ab = [list(map(int, input().split())) for i in range(n)]
cd = [list(map(int, input().split())) for i in range(m)]

dist = np.zeros((n, m))
for i in range(n):
  for j in range(m):
    dist[i, j] = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])

for dis in dist:
  print(dis.argmin()+1)

Submission status: Accepted

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

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

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

def MD(P1,P2):
  return (abs(P1[0]-P2[0])+abs(P1[1]-P2[1]))

for i in range(N):
  Min_D = int(10e10)
  for j in range(M):
    D = MD(S[i],C[j])
    if Min_D > D:
      Min_D = D
      P = j+1
  print(P)

Submission status: Accepted

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

for i in range(N):
    now_x, now_y = s_locs[i]
    closest_cp_idx = None
    min_dist = float("inf")
    for j in range(M):
        dist = abs(c_locs[j][0]-now_x) + abs(c_locs[j][1]-now_y)
        if dist < min_dist:
            min_dist = dist
            closest_cp_idx = j+1
    print(closest_cp_idx)

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):
    seq_min = 1e9
    ans = -1
    for j in range(m):
        seq = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
        if seq_min > seq:
            seq_min = seq
            ans = j
    print(ans + 1)

Submission status: Accepted

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

a = []
b = []
c = []
d = []
for i in range(n):
    ax, by = map(int, input().split())
    a.append(ax)
    b.append(by)
for i in range(m):
    cx, dy = map(int, input().split())
    c.append(cx)
    d.append(dy)

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

Submission status: Accepted

Solution code:
N,M=list(map(int, input().split()))
a=[0]*N
b=[0]*N
for i in range(0,N):
    a[i],b[i]=list(map(int, input().split()))
c=[0]*M
d=[0]*M
for i in range(0,M):
    c[i],d[i]=list(map(int, input().split()))
for i in range(0,N):
    kyori=abs(a[i]-c[0])+abs(b[i]-d[0])
    ba=0
    for j in range(1,M):
        if kyori>abs(a[i]-c[j])+abs(b[i]-d[j]):
            kyori=abs(a[i]-c[j])+abs(b[i]-d[j])
            ba=j
    print(ba+1)

Submission status: Accepted

Solution code:
n,m= list(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:
    kyori=1000000007
    ans=0
    for i,v in enumerate(cd):
        now=abs(a-v[0])+abs(b-v[1])
        if kyori>now:
            kyori=now
            ans=i
    print(ans+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 ab:
    l = []
    for j in cd:
        l.append(abs((j[0] - i[0])) + abs((j[1] - i[1])))
    print(l.index(min(l)) + 1)

Submission status: Accepted

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


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

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 _ in range(M):
    c, d = map(int, input().split())
    CD.append((c, d))


def f(a, b, c, d):
    return abs(a - c) + abs(b - d)


for a, b in AB:
    v, idx = 10**10, 0
    for i, (c, d) in enumerate(CD, start=1):
        # c, d = t
        d = f(a, b, c, d)
        if v > d:
            idx = i
            v = d
    print(idx)

Submission status: Accepted

Solution code:
def Distance(t_a,t_b):
    return abs(t_a[0]-t_b[0]) + abs(t_a[1]-t_b[1])

n,m = map(int,input().split(' '));
students = []
for p in range(n):
    students.append(tuple(map(int,input().split(' '))))
check = []
for q in range(m):
    check.append(tuple(map(int,input().split(' '))))
ans = ''
for s in students:
    dmin = Distance(s, check[0])
    dindex = 0
    i = 1
    while i < m:
        d0 = Distance(s, check[i])
        if d0 < dmin:
            dmin = d0
            dindex = i
        i += 1
    ans += str(dindex+1) + '\n'
print(ans)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
list_AB = [ list(map(int,input().split(" "))) for i in range(n)]
list_CD = [ list(map(int,input().split(" "))) for i in range(m)]
ans = [[0, pow(10, 12)] for _ in range(n)]

for i, l in enumerate(list_AB):
    a = l[0]
    b = l[1]
    for j, k in enumerate(list_CD):
        c = k[0]
        d = k[1]
        if abs(a-c) + abs(b-d) < ans[i][1]:
            ans[i][1] = abs(a-c) + abs(b-d)
            ans[i][0] = j + 1

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

Submission status: Accepted

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

ans = []
for a, b in students:
    curr_d = 10 ** 10
    curr_i = 0
    for i, (c, d) in enumerate(checkpoints, start=1):
        dist = abs(a - c) + abs(b - d)
        if dist < curr_d:
            curr_d = dist
            curr_i = i
    ans.append(curr_i)

print('\n'.join(map(str, ans)))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
stu = []
for i in range(n):
    stu.append(list(map(int, input().split())))
chk = []
for i in range(m):
    chk.append(list(map(int, input().split())))
    
for i in range(n):
    near = 10**10
    for j in range(m):
        mht = abs(stu[i][0]-chk[j][0])+abs(stu[i][1]-chk[j][1])
        if near > mht:
            near = mht
            idx = j
    print(idx+1)

Submission status: Accepted

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

P = []
C = []

for i in range(N):
    P += [[int(x) for x in input().split()]]
    
for i in range(M):
    C += [[int(x) for x in input().split()]]

for i in range(N):
    d_min = abs(P[i][0] - C[0][0]) + abs(P[i][1] - C[0][1])
    c_min = 1
    for j in range(M):
        d = abs(P[i][0] - C[j][0]) + abs(P[i][1] - C[j][1])
        if d < d_min:
            d_min = d
            c_min = j+1
    print(c_min)

Submission status: Accepted

Solution code:
N, M = map(int,input().split())
s = [list(map(int,input().split())) for k in range(N)]
p = [list(map(int,input().split())) for k in range(M)]
ans = []
for e in s:
    temp = float("inf")
    u = 0
    for k in range(M):
        if temp > abs(e[0]-p[k][0]) + abs(e[1]-p[k][1]):
            temp = abs(e[0]-p[k][0]) + abs(e[1]-p[k][1])
            u = k+1
    ans.append(u)
print(*ans,sep="\n")

Submission status: Accepted

Solution code:
import numpy as np
n,m=map(int,input().split())
x=np.ones((n,2))
y=np.ones((m,2))

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

for i in range(m):
    y[i]=list(map(int,input().split()))
    
def m_d(a,b):
    return(abs(a[0]-b[0])+abs(a[1]-b[1]))

for i in range(n):
    d=[]
    for j in range(m):
        d.append(m_d(x[i],y[j]))
                 
    print(d.index(min(d))+1)

Submission status: Accepted

Solution code:
import sys  
import numpy as np

input = sys.stdin.readline
N, M= map(int, input().split())
AB = []
for i in range(N):
    a, b = list(map(int, input().split()))
    AB.append([a, b])

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


for i in range(N):
    leng = []
    for j in range(M):
        temp = abs(AB[i][0]-CD[j][0]) + abs(AB[i][1]-CD[j][1])
        leng.append(temp)
    for k in range(len(leng)):
        if leng[k] == min(leng):
            print(k+1)
            break

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=[list(map(int,input().split())) for a in range(n)]
c=[list(map(int,input().split())) for b in range(m)]
dist=0
minnum=0
for indi,i in enumerate(a):
    min=10**10
    minnum=0
    for indj,j in enumerate(c):
        dist=0 
        dist+=abs(i[0]-j[0])
        dist+=abs(i[1]-j[1])
        #print("dist={}".format(dist))
        if min>dist:
            min=dist
            minnum=indj
    print(minnum+1)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=[list(map(int,input().split())) for a in range(n)]
c=[list(map(int,input().split())) for b in range(m)]
dist=0
minnum=0
for indi,i in enumerate(a):
    min=abs(i[0]-c[0][0])+abs(i[1]-c[0][1])
    minnum=0
    for indj,j in enumerate(c):
        dist=0 
        dist+=abs(i[0]-j[0])
        dist+=abs(i[1]-j[1])
        #print("dist={}".format(dist))
        if min>dist:
            min=dist
            minnum=indj
    print(minnum+1)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
s = [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 s:
    ans_num = 0
    ans_dist = 1000000007
    for i in range(len(check_points)):
        x, y = check_points[i]
        dist = abs(a - x) + abs(b - y)
        if dist < ans_dist:
            ans_num = i + 1
            ans_dist = dist
    print(ans_num)

Submission status: Accepted

Solution code:
icase=0
if icase==0:
    n,m=map(int,input().split())
    a=[]
    for i in range(n):
        xi,yi=map(int,input().split())
        a.append([xi,yi])
    c=[]
    for i in range(m):
        xi,yi=map(int,input().split())
        c.append([xi,yi])
    for i in range(n):
        idsmin=10**9
        ip=51
        for ii in range(m-1,-1,-1):
            ids=abs(a[i][0]-c[ii][0])+abs(a[i][1]-c[ii][1])
#            print(ids,i,ii)
            if ids<=idsmin:
                idsmin=ids
                ip=ii+1
        print(ip)

Submission status: Accepted

Solution code:
n , m = map(int,input().split())
p = []
q = []
for i in range(n):
    x = list(map(int,input().split()))
    p.append(x)
for j in range(m):
    y = list(map(int,input().split()))
    q.append(y)
for a,b in p:
    cou = 0
    ans = 0
    kar = 10**9
    for c,d in q:
        cou += 1
        if (abs(a-c)+abs(b-d)) < kar:
            ans = cou
            kar = (abs(a-c)+abs(b-d))
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
A=[[0,0]for i in range(n)]
B=[[0,0] for i in range(m)]
E=[1]*n
for i in range(n):
    A[i][0],A[i][1]=map(int,input().split())
for i in range(m):
    B[i][0],B[i][1]=map(int,input().split())
for i in range(n):
    c=abs(A[i][0]-B[0][0])+abs(A[i][1]-B[0][1])
    for j in range(1,m):
        if abs(A[i][0]-B[j][0])+abs(A[i][1]-B[j][1])<c:
            c=abs(A[i][0]-B[j][0])+abs(A[i][1]-B[j][1])
            E[i]=j+1
for i in range(n):
    print(E[i])

Submission status: Accepted

Solution code:
def main():
    from itertools import starmap

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

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

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

    def dist(t1, t2):
        return sum(starmap(lambda a, b: abs(a - b), zip(t1, t2)))

    ans = []
    for s_ in s:
        d = 4 * 10 ** 8 + 1
        idx = -1
        for i, p_ in enumerate(p):
            t = dist(s_, p_)
            if t < d:
                d = t
                idx = i
        ans.append(idx + 1)
    print(*ans, sep='\n')


if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())

Submission status: Accepted

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

cd = [tuple(map(int, input().split())) for i in range(M)]


for a, b in ab:
    ret = -1
    dis = 10**20
    for i, x in enumerate(cd):
        c, d = x
        if dis > abs(c-a) + abs(d-b):
            dis = abs(c-a) + abs(d-b)
            ret = i
    print(ret+1)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n)]
cd=[list(map(int,input().split())) for i in range(m)]
ans=[-1]*n
i=0
for a,b in ab:
  t=10**12
  j=0
  for c,d in cd:
    if abs(a-c)+abs(b-d)<t:
      t=abs(a-c)+abs(b-d)
      ans[i]=j+1
    j+=1
  i+=1
print(*ans,sep='\n')

Submission status: Accepted

Solution code:
def resolve():
    n,m=map(int,input().split())
    ab=[]
    check=[]
    for i in range(n):
        tmp=list(map(int,input().split()))
        ab.append(tmp)
    for i in range(m):
        tmp=list(map(int,input().split()))
        check.append(tmp)
    for i in range(n):
        num=1
        ans=1000000000
        for j in range(m):
            len=abs(ab[i][0]-check[j][0])+abs(ab[i][1]-check[j][1])
            if ans>len:
                tmp=num
                ans=len
            num+=1
        print(tmp)
resolve()

Submission status: Accepted

Solution code:
import numpy as np
N,M = list(map(int,input().split()))
XY = []
D = []
for n in range(N):
  XY.append(tuple(map(int,input().split())))

for m in range(M):
  D.append(tuple(map(int,input().split())))

XY = np.array(XY)
D = np.array(D)
for i in np.argmin(np.sum(np.abs(XY[:,None,:] - D[None,:,:]),axis=2),axis=1):
  print(i+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)]
ans = 0
starts =np.array(a)
goals = np.array(b)

for start in range(n):
    dist = 10000000000
    ans = 0
    for goal in range(m):
        if dist > abs(goals[goal][0]-starts[start][0]) + abs(goals[goal][1]-starts[start][1]):
            dist = abs(goals[goal][0]-starts[start][0]) + abs(goals[goal][1]-starts[start][1])
            ans = goal+1
    print(ans)

Submission status: Accepted

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

for i in range(n):
    tmp = float("inf")
    ans = 0
    y = float("inf")
    for j in range(m):
        x = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
        if x < tmp or x == tmp and i < y:
            tmp = x
            ans = j + 1
            y = i
    print(ans)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
student = []
check = []
for i in range(n):
    ab = [int(i) for i in input().split()]
    student.append(ab)
for j in range(m):
    cd = [int(i) for i in input().split()]
    check.append(cd)
mn = 10**13
for ax,by in student:
    for i in range(m):
        dist = abs(ax-check[i][0]) + abs(by-check[i][1])
        if mn > dist:
            ans = i+1
            mn = dist
    print(ans)
    mn = 10**13

Submission status: Accepted

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

l_ans = [] 
for i in range(N):
  a,b = ln[i][0],ln[i][1]
  dis = float("inf")
  ch = 0
  for j in range(M):
    c,d = lm[j][0],lm[j][1]
    if dis > abs(a-c)+abs(b-d):
      dis = abs(a-c)+abs(b-d)
      ch = j+1
  l_ans.append(ch)

for i in l_ans:
  print(i)

Submission status: Accepted

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

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

INF = 10 ** 8 * 4
for s in ss:
    dist = INF
    c_point = 0
    a, b = s
    for i, v in enumerate(p):
        c, d = v
        manhattan = abs(a - c) + abs(b - d)
        if manhattan < dist:
            c_point = i + 1
            dist = manhattan
    print(c_point)

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

Submission status: Accepted

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

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

for i in range(0,N):
    a,b=student[i]
    ans=10**20
    anscheck=0
    for j in range(0,M):
        c,d=checkpoint[j]
        if ans>abs(a-c)+abs(b-d):
            anscheck=j
            ans=abs(a-c)+abs(b-d)

    print(anscheck+1)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=[list(map(int,input().split())) for i in range(n)]
c=[list(map(int,input().split())) for i in range(m)]
def d(x,y):
    return abs(x[0]-y[0])+abs(x[1]-y[1])
for i in a:
    ans=10101001010
    ch=0
    for j in range(m):
        if d(i,c[j])<ans:
            ch=j
            ans=d(i,c[j])
    print(ch+1)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=[]
b=[]
c=[]
d=[]
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)

import numpy as np
c=np.array(c)
d=np.array(d)

for i in range(n):
    tmp_x=a[i]
    tmp_y=b[i]
    dis_arr=(abs(c - tmp_x)+abs(d - tmp_y)).tolist()
    print(dis_arr.index(min(dis_arr))+1)

Submission status: Accepted

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

for x in range(N):
    min_y = 0
    min_value = 10**12
    for y in range(M):
        distance = abs(n_student[x][0] - m_point[y][0]) + \
            abs(n_student[x][1] - m_point[y][1])
        if distance < min_value:
            min_value = distance
            min_y = y + 1
    print(min_y)

Submission status: Accepted

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

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

ans = [0] * N

for i in range(N):
    jdg = float("INF")
    for k in range(M):
        a, b = sdt[i]
        c, d = chk[k]
        if jdg > abs(a-c)+abs(b-d):
            ans[i] = k+1
            jdg = abs(a-c)+abs(b-d)

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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, m = map(int, readline().split())
ab = [list(map(int, readline().split())) for _ in range(n)]
cd = [list(map(int, readline().split())) for _ in range(m)]
inf = float('inf')
for a, b in ab:
    cnt = inf
    ans = 0
    for i in range(m):
        v = abs(a - cd[i][0]) + abs(b - cd[i][1])
        if cnt > v:
            cnt = v
            ans = i + 1
    print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N, M = map(int, input().split())

A = [tuple(map(int, input().split())) for _ in [0]*N]
C = [tuple(map(int, input().split())) for _ in [0]*M]


for a, b in A:
    mind = 10**10
    mini = -1
    for i, (c, d) in enumerate(C):
        if mind > abs(c-a)+abs(d-b):
            mind = abs(c-a)+abs(d-b)
            mini = i
    print(mini+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):
    a,b=map(int,input().split())
    cd.append((a,b))

for _ in range(n):
    ans=9e9
    ret=0
    a=ab[_][0]
    b=ab[_][1]
    for i,j in enumerate(cd):
        c=j[0]
        d=j[1]
        man=abs(a-c)+abs(b-d)
        if man<ans:
            ans=man
            ret=i+1
    print(ret)

Submission status: Accepted

Solution code:
import math

INF = 1001001001

def resolve():
  n, m = map(int, input().split())
  s = []
  c = []

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

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

  for a in s:
    ans = 0
    dist = INF
    for i in range(m):
      if abs(a[0] - c[i][0]) + abs(a[1] - c[i][1]) < dist:
        dist = abs(a[0] - c[i][0]) + abs(a[1] - c[i][1])
        ans = i+1
    print(ans)
  return

if __name__ == "__main__":
  resolve()

Submission status: Accepted

Solution code:
import numpy as np
N,M=map(int, input().split())
human=[]
for i in range(N):
  a,b=map(int, input().split())
  human.append((a,b))
C=[]
for i in range(M):
  c,d=map(int, input().split())
  C.append((c,d))
  
for h in human:
  a,b=h
  now=0
  mini=np.inf
  for i,ch in enumerate(C):
    c,d=ch
    L=abs(a-c)+abs(b-d)
    if mini>L:
      mini=L
      now=i+1
  print(now)

Submission status: Accepted

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

n,m = map(int,input().split())
CD = [tuple(map(int,input().split())) for i in range(n)]
AB = [tuple(map(int,input().split())) for i in range(m)]
for c,d in CD:
  print(min(range(m),key = lambda x:abs(AB[x][0]-c) + abs(AB[x][1]-d))+1)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
ls1 = []
ls2 = []
for i in range(N):
  ls1.append(list(map(int,input().split())))
for i in range(M):
  ls2.append(list(map(int,input().split())))
for i in range(N):
  minimum = 10**18
  check = 0
  for j in range(M):
    K = abs(ls1[i][0]-ls2[j][0])+abs(ls1[i][1]-ls2[j][1])
    if K < minimum:
      minimum = K
      check = j
  print(check+1)

Submission status: Accepted

Solution code:
def resolve():
    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):
        mdis = float("inf")
        goal = -1
        x, y = s[i][0], s[i][1]
        for j in range(m):
            cx, cy = c[j][0], c[j][1]
            dis = abs(x-cx)+abs(y-cy)
            if mdis > dis:
                mdis = dis
                goal = j+1
        print(goal)
resolve()

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

Submission status: Accepted

Solution code:
def main():
    n, m = map(int, input().split())
    student = []
    for _ in range(n):
        student.append([int(x) for x in input().split()])
    check_point = []
    for _ in range(m):
        check_point.append([int(x) for x in input().split()])
    answer = ["0" for _ in range(n)]
    for i in range(n):
        now_ans = 0
        now_dist = float("inf")
        for j in range(m):
            dist = abs(student[i][0] - check_point[j][0]) + abs(student[i][1] - check_point[j][1])
            if dist < now_dist:
                now_ans = j + 1
                now_dist = dist
        answer[i] = str(now_ans)
    print("\n".join(answer))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
b = [list(map(int, input().split())) for _ in range(m)]
for x,y in a:
    c = float("inf")
    for j in range(m):
        if c > abs(x-b[j][0])+abs(y-b[j][1]):
            c = abs(x-b[j][0])+abs(y-b[j][1])
            ans = j+1
    print(ans)

Submission status: Accepted

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

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

for i in g:
    a,b=i[0],i[1]
    dis=10**10
    ind=1
    for j in range(m):
        x,y=c[j][0],c[j][1]
        now=abs(a-x)+abs(b-y)
        if now<dis:
            dis=now
            ind=j+1
    print(ind)

Submission status: Accepted

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

students = []
checkpoints = []

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

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

for i, j in students:
    min_dist = 10**10
    point = -1
    for x in range(m):
        dist = abs(checkpoints[x][0] - i) + abs(checkpoints[x][1] - j)
        if dist < min_dist:
            min_dist = dist
            point = x + 1
    print(point)

Submission status: Accepted

Solution code:
[n,m] = [int(i) for i in input().split()]
ls_st = []
ls_ch = []
for j in range(n):
    ls_st.append([int(i) for i in input().split()])
for j in range(m):
    ls_ch.append([int(i) for i in input().split()])
ans = []
for i in range(n):
    dist = 10**20;
    place = -1
    for j in range(m):
        if dist > (abs(ls_st[i][0] - ls_ch[j][0])+abs(ls_st[i][1] - ls_ch[j][1])):
            dist = (abs(ls_st[i][0] - ls_ch[j][0])+abs(ls_st[i][1] - ls_ch[j][1]))
            place = j+1
    ans.append(place)
for i in range(n):
    print(ans[i])

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n, m = na()
ab = nan(n)
cd = nan(m)

ans = [0] * n
for i in range(n):
    a, b = ab[i]
    cur = inf
    p = -1
    for j in range(m):
        c, d = cd[j]
        dist = abs(a - c) + abs(b - d)
        if dist < cur:
            cur = dist
            p = j + 1
    ans[i] = p

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

Submission status: Accepted

Solution code:
N,M = list(map(int, input().split()))
a = []
b = []
c = []
d = []
for _ in range(N):
    A,B = list(map(int, input().split()))
    a.append(A)
    b.append(B)
for _ in range(M):
    C,D = list(map(int, input().split()))
    c.append(C)
    d.append(D)
inf = float('inf')

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

Submission status: Accepted

Solution code:
import sys
from collections import deque
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N,M = IL()
ab = [IL() for i in range(N)]
cd = [IL() for i in range(M)]

for a,b in ab:
  ans = ""
  num = MAX_INT
  for i in range(M):
    tmp = abs(a-cd[i][0]) + abs(b-cd[i][1])
    if tmp < num:
      ans = i+1
      num = tmp
  print(ans)

Submission status: Accepted

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

students = tuple(tuple(map(int,input().split())) for _ in range(N))
checks = tuple(tuple(map(int,input().split())) for _ in range(M))

print(*(c for _,c in (min((abs(x0-x1)+abs(y0-y1),i+1)  for i,(x0,y0) in enumerate(checks)) for x1,y1 in students)), sep='\n')

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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):
    res = 10**10
    for j in range(M):
        if dist(ab[i][0], ab[i][1], cd[j][0], cd[j][1]) < res:
            res = dist(ab[i][0], ab[i][1], cd[j][0], cd[j][1])
            ans = j+1
    print(ans)