Problem: 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?

Submission attempts (in order):
N,M = (int(i) for i in input().split())


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

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

minimum = N*[""]
number = N*[0]



for i in range(N):
    minimum[i] = abs(student[i][0]-point[0][0]) + abs(student[i][1]-point[0][1])
    for j in range(M):
        distance = abs(student[i][0]-point[j][0]) + abs(student[i][1]-point[j][1])
        if distance<= minimum[i]:
            number[i] = j+1
        minimum[i] = min(distance,minimum[i])

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


N,M = (int(i) for i in input().split())

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

points = []
for i in range(M):
    c,d = (int(k) for k in input().split())
    points.append([a,b])
    
distance = []
kyori = []


for i in range(N):
    for j in range(1):
        kyori.append(abs(student[i][0]-points[j][0]) + abs(student[i][1]-points[j][1]))
    distance.append(min(kyori[j]))

for i in range(N):
    for j in range(1,M):
        kyori[j] = abs(student[i][0]-points[j][0]) + abs(student[i][1]-points[j][1])
    distance.append(min(kyori[j]))

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

N,M = (int(i) for i in input().split())

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

points = []
for i in range(M):
    c,d = (int(k) for k in input().split())
    points.append([a,b])
    
distance = []
kyori = []

'''
for i in range(N):
    for j in range(1):
        kyori.append(abs(student[i][0]-points[j][0]) + abs(student[i][1]-points[j][1]))
    distance.append(min(kyori))

for i in range(N):
    for j in range(1,M):
        kyori[j] = abs(student[i][0]-points[j][0]) + abs(student[i][1]-points[j][1])
    distance.append(min(kyori))
'''

for i in range(1):
    for j in range(M):
        kyori.append(abs(student[i][0]-points[j][0]) + abs(student[i][1]-points[j][1]))
        print(kyori)
    distance.append(min(kyori))

for i in range(1,N):
    for j in range(M):
        kyori[j] = abs(student[i][0]-points[j][0]) + abs(student[i][1]-points[j][1])
        print(kyori)
    distance.append(min(kyori))

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

N,M = (int(i) for i in input().split())
a=[]
b=[]
c=[]
d=[]

for i in range(N):
    A,B = (int(i) for i in input().split())
    a.append(A)
    b.append(B)

for i in range(M):
    C,D = (int(i) for i in input().split())
    c.append(C)
    d.append(D)


closest = N*[0]

for i in range(N):
    minimum = abs(a[i]-c[0])+abs(b[i]-d[0])
    number = 1
    for j in range(1,M):
        distance = abs(a[i]-c[j])+abs(b[i]-d[j])
        if distance < minimum:
            minimum = distance
            number = j+1
    closest[i] = number

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

Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Accepted