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())
s = [0] * n
t = [0] * m
for i in range(n):
    a, b = map(int, input().split())
    s[i] = (a, b)
for j in range(m):
    c, d = map(int, input().split())
    t[j] = (c, d)

for i in range(n):
    ans = 0
    mi = float('inf')
    for j in range(m):
        u = abs(s[i][0] - t[j][0]) + abs(s[i][1] - t[j][1])
        if u < mi:
            mi = u
            ans = j + 1
    print(ans)

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

def dis(st, cp):
  return abs(st[0] - cp[0]) + abs(st[1] - cp[1])

for n in range(N):
  min_dis = dis(st[n], cp[0])
  ans = 1
  for m in range(1, M):
    cur_dis = dis(st[n], cp[m])
    if cur_dis < min_dis:
      min_dis = cur_dis
      ans = m + 1
  print(ans)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a, b, c, d = [0] * n, [0] * n, [0] * m, [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):
    min_dist, min_c = 10**9, -1
    for j in range(m):
        dist = abs(a[i]-c[j]) + abs(b[i]-d[j])
        if dist < min_dist:
            min_dist = dist
            min_c = j
    print(min_c+1)

Submission status: Accepted

Solution code:
L=list()
R=list()
N,M=map(int,input().split())
for i in range(N):
  a,b=map(int,input().split())
  L.append([a,b])
for i in range(M):
  a,b=map(int,input().split())
  R.append([a,b])
ans=[0]*M
for i in range(N):
  K=[0]*M
  a,b=L[i]
  for j in range(M):
    K[j]=abs(a-R[j][0])+abs(b-R[j][1])
  s=min(K)
  q=K.index(s)
  print(q+1)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
stu=[]
for i in range(N):
  a,b=map(int,input().split())
  stu.append([a,b])
pl=[]
for j in range(M):
  c,d=map(int,input().split())
  pl.append([c,d])
for k in range(N):
  met=4*(10**8)+1
  pr=0
  for l in range(M):
    if abs(pl[l][0]-stu[k][0])+abs(pl[l][1]-stu[k][1])<met:
      met=abs(pl[l][0]-stu[k][0])+abs(pl[l][1]-stu[k][1])
      pr=l+1
  print(pr)

Submission status: Accepted

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

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

for i in range(N):
  dist = list(map(lambda x:calc_dict(s[i],x),c))
  print(dist.index(min(dist))+1)

Submission status: Accepted

Solution code:
N, M = list(map(lambda x: int(x), input().split(" ")))
ppl = []
chk = []
for i in range(N):
  ppl.append(list(map(lambda y: int(y), input().split(" "))))
for j in range(M):
  chk.append(list(map(lambda z: int(z), input().split(" "))))

goal = [0] * N
for i in range(N):
  stu = ppl[i]
  min_d = -1
  dest = 0

  for j in range(M):
    point = chk[-j-1]
    d = abs(stu[0] - point[0]) + abs(stu[1] - point[1])
    if min_d < 0 or d <= min_d:
      min_d = d
      dest = M - j
  
  goal[i] = dest

print("\n".join([str(g) for g in goal]))

Submission status: Accepted

Solution code:
def main():
    n, m = map(int, input().split())
    A, X = [], []
    for _ in range(n):
        A.append(list(map(int, input().split())))
    for _ in range(m):
        X.append(list(map(int, input().split())))
    for a, b in A:
        ans, dist = 0, 10e+10
        for i, (x, y) in enumerate(X):
            if (d := abs(x - a) + abs(y - b)) < dist:
                dist = d
                ans = i + 1
        print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [list(input()) for _ in range(n)]


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

total = []
for i in range(n):
    temp = []
    for j in range(m):
        distance = abs(g[i][0] - c[j][0]) + abs(g[i][1] - c[j][1])
        temp.append(distance)
    total.append(temp)

#print(total)
for i in range(n):
    midx = 0
    mv = 99999999999999999999999999
    for j in range(m):
        if (mv > total[i][j]):
            midx = j
            mv = total[i][j]
    print(midx+1)

Submission status: Accepted

Solution code:
def resolve():
    N, M = map(int, input().split())
    A = []
    B = []
    for _ in range(N):
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)
    C = []
    D = []
    for __ in range(M):
        c, d = map(int, input().split())
        C.append(c)
        D.append(d)
    for i in range(N):
        count = abs(A[i]-C[0]) + abs(B[i]-D[0])
        ans = 1
        for j in range(1, M):
            if count > abs(A[i]-C[j]) + abs(B[i]-D[j]):
                count = abs(A[i]-C[j]) + abs(B[i]-D[j])
                ans = j+1
        print(ans)
resolve()

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
lsab = []
for i in range(N):
    a,b = map(int,input().split())
    lsab.append([a,b])
lscd = []
for j in range(M):
    c,d= map(int,input().split())
    lscd.append([c,d])

lsans = []
for i in range(N):
    max1 = 4*10**8+100
    ans = 0
    for j in range(M):
        dis = abs(lsab[i][0]-lscd[j][0])+abs(lsab[i][1]-lscd[j][1])
        if dis < max1:
            ans = j+1
            max1 = dis
    lsans.append(ans)

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
stu=[[0,0] for i in range(n)]
po=[[0,0] for i in range(m)]
for i in range(n):
    a,b=map(int,input().split())
    stu[i][0]=a
    stu[i][1]=b
for i in range(m):
    c,d=map(int,input().split())
    po[i][0]=c
    po[i][1]=d
ans=[]
for i in range(n):
    x=stu[i][0]
    y=stu[i][1]
    dis=[]
    for j in range(m):
        dis.append(abs(x-po[j][0])+abs(y-po[j][1]))
    ans.append(dis.index(min(dis)))
for i in range(n):
    print(ans[i]+1)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
ss=[list(map(int,input().split())) for i in range(n)]
che=[list(map(int,input().split())) for i in range(m)]
for i in range(n):
    ans=100000000000000000000000000000000000000000000000000000
    x,y=ss[i]
    for  j in range(m):
        if ans>abs(x-che[j][0])+abs(y-che[j][1]):
            ans=abs(x-che[j][0])+abs(y-che[j][1])
            ind=j
    print(ind+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 C in range(m)]
for i in range(n):
    ans = []
    for j in range(m):
        ans.append((abs(a[i][0]-c[j][0])+abs(a[i][1]-c[j][1])))
    print(ans.index(min(ans))+1)

Submission status: Accepted

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

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

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

for student in s:
    index = 1000
    idist = 1e9

    for i in range(m):
        dist = abs(student[0] - c[i][0]) + abs(student[1] - c[i][1])
        if (dist < idist):
            idist = dist
            index = i

    print(index + 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))
  
for i in ab:
  s = float("inf")
  for j in range(m):
    t = abs(i[0]-cd[j][0]) + abs(i[1]-cd[j][1])
    if t < s:
      s = t
      ans = j+1
  print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
x=[0]*N
y=[0]*N
c=[0]*M
d=[0]*M
ans=[0]*N
for i in range(N):
  x[i],y[i]=map(int,input().split())
for i in range(M):
  c[i],d[i]=map(int, input().split())

for i in range(N):
  dmin=10**9
  for j in range(M):
    dcurr=abs(x[i]-c[j])+abs(y[i]-d[j])
    if dcurr<dmin:
      ans[i]=j+1
      dmin=dcurr

for n in ans:
  print(n)

Submission status: Accepted

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

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

check=[]

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

for s in student:
    ans=10**9
    i=0
    for j in range(m):
        c=check[j]
        dist = abs(c[0]-s[0]) + abs(c[1]-s[1])
        if dist<ans:
            ans=dist
            i=j+1

    print(i)

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)]
for i in range(n):
    a=stu[i][0]
    b=stu[i][1]
    minche=50
    minlen=10**10
    for j in range(m):
        x=che[j][0]
        y=che[j][1]
        kyori=abs(a-x)+abs(b-y)
        if kyori<minlen:
            minlen=kyori
            minche=j+1
    print(minche)

Submission status: Accepted

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

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

for a,b in St:
    dis = [abs(a-c)+abs(b-d)for c,d in Pt]
    print(dis.index(min(dis))+1)

Submission status: Accepted

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

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

for a,b in St:
    dis = [abs(a-c)+abs(b-d)for c,d in Pt]
    print(dis.index(min(dis))+1)

Submission status: Accepted

Solution code:
import math


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    N, M = read_ints()
    students, checkpoints = [], []
    for _ in range(N):
        students.append(read_ints())
    for _ in range(M):
        checkpoints.append(read_ints())
    for s in students:
        min_dist = math.inf
        min_j = math.inf
        for j, c in enumerate(checkpoints, start=1):
            if abs(s[0]-c[0])+abs(s[1]-c[1]) < min_dist:
                min_dist = abs(s[0]-c[0])+abs(s[1]-c[1]) 
                min_j = j
        print(min_j)


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

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

for a,b in St:
    dis = [abs(a-c) + abs(b-d) for c,d in Pt]
    print(dis.index(min(dis)) + 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())))
# print(ab)
# print(cd)

for i in range(n):
    r = 999999999999999999
    cp = -1
    for j in range(m):
        if abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1]) < r:
            r = abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
            cp = j
    print(cp+1)

Submission status: Accepted

Solution code:
#11
n,m = map(int,input().split())
ab = []
cd = []
for i in range(n):
    ab.append(list(map(int,input().split())))
for i in range(m):
    cd.append(list(map(int,input().split())))
    
for i in range(n):
    Min = [0,float("inf")]
    for j in range(m):
        l = abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
        if Min[1]>l:
            Min = [j+1,l]
    print(Min[0])

Submission status: Accepted

Solution code:
#11
n,m = map(int,input().split())
ab = []
cd = []
for i in range(n):
    ab.append(list(map(int,input().split())))
for i in range(m):
    cd.append(list(map(int,input().split())))
    
for i in range(n):
    Max = [0,float("inf")]
    for j in range(m):
        l = abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
        if Max[1]>l:
            Max = [j+1,l]
    print(Max[0])

Submission status: Accepted

Solution code:
N, M = list(map(int, input().split()))
P, CP = [], []

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

for i in range(N):
    a, b = P[i][0], P[i][1]
    now = 10**10
    for j in reversed(range(M)):
        c, d = CP[j][0], CP[j][1]
        distance = abs(a-c)+abs(b-d)
        if distance <= now:
            result = j+1
            now = distance
    print(result)

Submission status: Accepted

Solution code:
n, m = [int(x) for x in input().split()]
s_list = [[int(x) for x in input().split()] for _ in range(n)]
c_list = [[int(x) for x in input().split()] for _ in range(m)]
for i in range(n):
    d = 10 ** 9
    p = 0
    for j in range(m):
        temp_d = abs(s_list[i][0] - c_list[j][0]) + abs(s_list[i][1] - c_list[j][1])
        if temp_d < d:
            d = temp_d
            p = j + 1
    print(p)

Submission status: Accepted

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

for j in range(n):
  best=100000000000
  for i in range(m):
    d=abs(ml[i][0]-nl[j][0]) + abs(ml[i][1]-nl[j][1])
    if best>d:
      best=d
      ans=i+1
  print(ans)

Submission status: Accepted

Solution code:
class Coodinate (object):
    """Coodinate object
    This class contains infomation about the coodinates.
    Each instance can have up to 3-dimensional(x,y,z) space coodinates.
    
    params
    ------------------------------
    x : int or floot ,default 0
    y : int or floot ,default 0
    z : int or floot ,default 0


    This class have following methods.
    ------------------------------
    distance : Calculate the straight-line distance between 2 points in Euclidean space.
    midpoint : Calculate the midpoint(halfway) between 2 points.
    manhattan_distance : Calculate the distance between 2 points that is sum of the absolute values their Cartesian coordinates.
    """

    def __init__(self,x=0,y=0,z=0):
        self.x=x
        self.y=y
        self.z=z
    
    def distance(self,other):
        """Calculate the straight-line distance between 2 points in Euclidean space.

        params
        ----------
        self : Coodinate object
        other : Coodinate object

        return
        ----------
        distance : floot

        """
        x_diff_sq=(self.x-other.x)**2
        y_diff_sq=(self.y-other.y)**2
        z_diff_sq=(self.z-other.z)**2
        return (x_diff_sq + y_diff_sq +z_diff_sq)**0.5
    

    def midpoint(self,other):
        """Calculate the midpoint(halfway) between 2 points.

        params
        ----------
        self : Coodinate object
        other : Coodinate object

        return
        ----------
        midpoint : tupul
        
        """
        x_midpoint=(self.x+other.x)/2
        y_midpoint=(self.y+other.y)/2
        z_midpoint=(self.z+other.z)/2
        if self.z == other.z ==0 :
            if self.y == other.y==0:
                return(x_midpoint)
            else:
                return(x_midpoint,y_midpoint) 
        return(x_midpoint,y_midpoint,z_midpoint)

    def manhattan_distance(self,other):
        """Calculate the distance between 2 points that is sum of the absolute values their Cartesian coordinates.

        params
        ----------
        self : Coodinate object
        other : Coodinate object

        return
        ----------
        manhattan_distance : floot

        """

        x_diff_abs=abs(self.x - other.x)
        y_diff_abs=abs(self.y - other.y)
        z_diff_abs=abs(self.z - other.z)
        return(x_diff_abs + y_diff_abs + z_diff_abs)




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

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

for k in range (N):
    t1=10**9
    t2=-1
    for l in range (M):
        temp=Coodinate.manhattan_distance(S[k],C[l])
        if temp<t1:
            t1=temp
            t2=l+1
    print(t2)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N,M = [int(i) for i in input().split()]
student = [[int(i) for i in input().split()] for j in range(N)]
check = [[int(i) for i in input().split()] + [j+1] for j in range(M)]
print("\n".join(map(str, [min(check, key=lambda x: abs(i[0] - x[0]) + abs(i[1] - x[1]))[-1] for i in student])))

Submission status: Accepted

Solution code:
n , m = map(int , input().split())
a =[]
b=[]
for i in range(n):
	a.append(list(map(int , input().split())))
for i in range(m):
	b.append(list(map(int, input().split())))
for i in range(n):
	now =10**9+90000
	idx=0
	for j in range(m):
		d=abs(a[i][0]-b[j][0])+abs(a[i][1]-b[j][1])
		if(d<now):
			now=d
			idx=j+1
	print(idx)

Submission status: Accepted

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

for a, b in l1:
    res_d = float('inf')
    res_n = 0
    for i in range(m):
        c, d = l2[i]
        if res_d > abs(a - c) + abs(b - d):
            res_d = abs(a - c) + abs(b - d)
            res_n = i + 1
    print(res_n)

Submission status: Accepted

Solution code:
def calc_dist(pos_a,pos_b):
  return abs(pos_a[0] - pos_b[0])+abs(pos_a[1] - pos_b[1])

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

for a_pos in a:
  min_d=float("inf")
  min_d_i=-1
  for i,b_pos in enumerate(b):
    d=calc_dist(a_pos,b_pos)
    if d < min_d:
      min_d=d
      min_d_i=i+1
  print(min_d_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:
    mx, j = 10**20, 0
    for i in range(m):
        c, d = cd[i]
        l = abs(a-c) + abs(b-d)
        if l < mx: 
            j = i
            mx = l
    ans.append(j+1)

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

Submission status: Accepted

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

for a, b in student:
    pos = 0
    dis = 10**9
    for i, x in enumerate(check, 1):
        c, d = x
        mdis = abs(a-c) + abs(b - d)
        if mdis < dis:
            pos = i
            dis = mdis
    print(pos)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
sts = [list(map(int, input().split())) for i in range(N)]
checkp = [[i+1]+list(map(int, input().split())) for i in range(M)]
rt = [None] * N
distances = [2*(10**8)] * N
for s in range(N):
  for c in checkp:
    dist = abs(sts[s][0]-c[1]) + abs(sts[s][1]-c[2])
    if rt[s] is None:
      rt[s] = c[0]
      distances[s] = dist
    else:
      if distances[s] > dist:
        rt[s] = c[0]
        distances[s] = dist
for i in rt:
  print(i)

Submission status: Accepted

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

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

for px, py in persons:
    i = 0
    min_dist = -1
    for k, (cx, cy) in enumerate(checks):
        m = abs(px-cx) + abs(py-cy)
        if k==0 or (k>0 and m < min_dist):
            i = k
            min_dist = m
    print(i+1)

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

for ab in abl:
    dis=10**18
    num=0
    for i in range(m):
        x2,y2=cd[i]
        if dis>abs(ab[0]-x2)+abs(ab[1]-y2):
            dis=abs(ab[0]-x2)+abs(ab[1]-y2)
            num=i
    print(num+1)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
stu=[list(map(int,input().split())) for _ in range(n)]
cp=[list(map(int,input().split())) for _ in range(m)]
for x1,y1 in stu:
    dist=10**18
    num=0
    for i in range(m):
        x2,y2=cp[i]
        if dist>abs(x1-x2)+abs(y1-y2):
            dist=abs(x1-x2)+abs(y1-y2)
            num=i
    print(num+1)

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)]
ans=[0]*n

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

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)]
ans=[0]*n

for i in range(n):
    distance=10**9
    index=0
    for j in range(m):
        if abs(student[i][0]-checkpoint[j][0])+abs(student[i][1]-checkpoint[j][1])<distance:
            distance=abs(student[i][0]-checkpoint[j][0])+abs(student[i][1]-checkpoint[j][1])
            index=j
    ans[i]=index+1
for i in range(n):
    print(ans[i])

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

anslst = []
for i in range(n):
    distance = 10 ** 9
    num = -1
    for j in range(m):
        tmp = abs(students[i][0] - points[j][0]) + abs(students[i][1] - points[j][1])
        if tmp < distance:
            distance = tmp
            num = j + 1
    anslst.append(num)

for p in anslst:
    print(p)

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 a:
    ans = 10**9
    num = 0
    for j in c:
        if abs(i[0]-j[0]) + abs(i[1]-j[1]) < ans:
            num = c.index(j)+1
        ans = min(ans, abs(i[0]-j[0]) + abs(i[1]-j[1]))
    print(num)

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    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)]

    ans = [0] * N
    for i, (a, b) in enumerate(AB):
        dist = INF
        for j, (c, d) in enumerate(CD):
            if dist > abs(a - c) + abs(b - d):
                dist = abs(a - c) + abs(b - d)
                res = j
        ans[i] = res + 1

    print(*ans, sep='\n')
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
ListS = []
for i in range (a):
  ListS.append(list(map(int, input().split())))
ListP = []
for i in range (b):
  ListP.append(list(map(int, input().split())))
List = [100]*a
mid = 0
dist = 10000000000000000000
for i in range(a):
  for j in range(b):
    mid = abs(ListP[j][0]-ListS[i][0])+abs(ListP[j][1]-ListS[i][1])
    if dist > mid:
      dist = mid
      List[i] = j+1
    elif mid == dist:
      List[i] = min(List[i],j+1)
    else:
      pass
  dist = 10000000000000000000
for element in List:
  print(element)

Submission status: Accepted

Solution code:
inf = 10**9


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

def calcNearestCheckpoints(person,checkpoints):
  ans = -1
  min_distance = inf
  for i in range(len(checkpoints)):
    distance = calcDistance(person,checkpoints[i])
    if distance < min_distance:
      ans = i+1
      min_distance = distance

  return ans

def main():
  N,M = map(int,input().split())
  people      = [list(map(int,input().split())) for _ in range(N)]
  checkpoints = [list(map(int,input().split())) for _ in range(M)]
  for i in range(N):
    person = people[i]
    print(calcNearestCheckpoints(person,checkpoints))

main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n, m = [int(w) for w in input().split()]
ls = [[int(w) for w in input().split()] for _ in range(n)]
lp = [[int(w) for w in input().split()] for _ in range(m)]

for a, b in ls:
    ans = -1
    dist = 10e10
    for i, (c, d) in enumerate(lp):
        d = abs(a-c) + abs(b-d)
        if d < dist:
            ans = i
            dist = d
    print(ans+1)

Submission status: Accepted

Solution code:
import sys

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)]
inf=10**9
def findcp(st):
    dist=inf
    i=0
    for j in range(M):
        if abs(st[0]-c[j][0])+abs(st[1]-c[j][1])<dist:
            dist=abs(st[0]-c[j][0])+abs(st[1]-c[j][1])
            i=j
    return i+1

for i in range(N):
    print(findcp(s[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 i in range(M)]
for i in range(N):
    l=[]
    for j in range(M):
        l.append(abs(a[i][0]-b[j][0])+abs(a[i][1]-b[j][1]))
    print(l.index(min(l))+1)

Submission status: Accepted

Solution code:
import itertools,collections
def main():
    n,m=map(int, input().split())
    pos = []
    checkp = []
    for i in range(n):
        a,b=map(int, input().split())
        pos.append((a,b))
    for i in range(m):
        c,d = map(int, input().split())
        checkp.append((c,d))

    res = []
    for i in range(n):
        shortes = 10000000000
        index = 1000
        for j in range(m):
            if(shortes>abs(pos[i][0]-checkp[j][0]) + abs(pos[i][1]-checkp[j][1])):
                shortes=abs(pos[i][0]-checkp[j][0]) + abs(pos[i][1]-checkp[j][1])
                index = j

        res.append(index+1)
    for i in res:
        print(i)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

for a, b in AB:
  check, distance = 1, 400000001
  for i, [c, d] in enumerate(CD):
    if distance > abs(a-c) + abs(b-d):
      distance = abs(a-c) + abs(b-d)
      check = i+1
  print(check)

Submission status: Accepted

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

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

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

for s in crd_std:
    min_crd = 10**9
    ans_crd_idx = 100
    for c in range(len(crd_chk)):
        if abs(s[0] - crd_chk[c][0]) + abs(s[1] - crd_chk[c][1]) < min_crd:
            min_crd = abs(s[0] - crd_chk[c][0]) + abs(s[1] - crd_chk[c][1])
            ans_crd_idx = c+1
    ans.append(ans_crd_idx)

for i in ans:
    print(i)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
N, M = map(int, input().split())
S = [[*map(int, input().split())] for _ in range(N)]
C = [[*map(int, input().split())] for _ in range(M)]
for a, b in S:
    mi = 10**9
    ans = 51
    for i in range(M):
        c, d = C[i]
        if abs(a - c) + abs(b - d) < mi:
            ans = i + 1
            mi = abs(a - c) + abs(b - d)
    print(ans)

Submission status: Accepted

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

for i in range(N):
  x,y=A[i]
  temp=10**9
  ans=1
  for j in range(M):
    X,Y=B[j]
    manhattan=abs(x-X)+abs(y-Y)
    if temp>manhattan:
      temp=min(temp,manhattan)
      ans=j+1
  else:
    print(ans)