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: Wrong Answer

Solution code:
n, m = map(int, input().split())
s = []
d = []
for i in range(n):
    x, y = map(int, input().split())
    s.append([x, y])
for i in range(m):
    x, y = map(int, input().split())
    d.append([x, y])
for i in s:
    a = m
    c = abs(i[0] - x) + abs(i[1] - y)
    for j in range(m):
        c_t = abs(i[0] - d[j][0]) + abs(i[1] - d[j][1])
        if c_t < c:
            c = min(c, c_t)
            a = j
    print(a)

Submission status: Wrong Answer

Solution code:
a = list(map(int,input().split(" ")))
b = list()
c = list()
ans = list()

for i in range(a[0]):
    b.append(list(map(int,input().split(" "))))

for i in range(a[1]):
    c.append(list(map(int,input().split(" "))))

for i in range(a[0]):
    d = 0
    e = 99999999
    for ii in range(a[1]):
        if e > abs(b[i][0] - c[ii][0]) + abs(b[i][1] - c[ii][1]):
            e = abs(b[i][0] - c[ii][0]) + abs(b[i][1] - c[ii][1])
            d = ii
    ans.append(d+1)
    
for i in range(a[0]):
    print(ans[i])

Submission status: Wrong Answer

Solution code:
a = list(map(int,input().split(" ")))
b = list()
c = list()
ans = list()

for i in range(a[0]):
    b.append(list(map(int,input().split(" "))))

for i in range(a[1]):
    c.append(list(map(int,input().split(" "))))

for i in range(a[0]):
    d = 0
    e = 99999999
    for ii in range(a[1]):
        if e > abs(b[i][0] - c[ii][0]) + abs(b[i][1] - c[ii][1]):
            e = abs(b[i][0] - c[ii][0]) + abs(b[i][1] - c[ii][1])
            d = ii
    ans.append(d)
    
for i in range(a[0]):
    print(ans[i])

Submission status: Wrong Answer

Solution code:
a = list(map(int,input().split(" ")))
b = list()
c = list()
ans = list()

for i in range(a[0]):
    b.append(list(map(int,input().split(" "))))

for i in range(a[1]):
    c.append(list(map(int,input().split(" "))))

for i in range(a[0]):
    d = 0
    e = 99999999
    for ii in range(a[1]):
        if e > abs(b[i][0] - c[ii][0]) + abs(b[i][1] - c[ii][1]):
            d = ii
    ans.append(d)
    
for i in range(a[0]):
    print(ans[i])

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

N, M = (int(i) for i in input().split(" "))
S = [input().split(" ") for i in range(N + M)]

seito = S[0:N]
check = S[N:N+M]

kyori = np.zeros(M)

for j in range(0,N):
	for i in range(0,M):
		kyori[i] = abs(int(seito[j][0]) - int(check[i][0])) + abs(int(seito[j][1]) - int(check[i][1]))
	#kyoriが一番低いiを出力する

	num = np.argmin(kyori)
	print(num)

Submission status: Wrong Answer

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

for sx, sy in students:
    mindist = 10 ** 8 + 1
    num = 0
    for i in range(M):
        cx, cy = checkpoints[i]
        dist = abs(sx-cx) + abs(sy-cy)
        if mindist > dist:
            mindist = dist
            num = i
    print(num+1)

Submission status: Wrong Answer

Solution code:
def mDistance(a, b):
    axisDist = [abs(x - y) for x, y in zip(a, b)]
    return(sum(axisDist))


N, M = map(int, input().split())
An, Am = ([], [])

while len(An) < N:
    An.append(map(int, input().split()))

while len(Am) < M:
    Am.append(map(int, input().split()))

for a in An:
    B = map(lambda b: mDistance(a, b), Am)
    I, _ = min(enumerate(list(B)), key=lambda b: b[1])
    print(I + 1)

Submission status: Wrong Answer

Solution code:
[N,M] = map(int, raw_input().split())
sl = []
for i in range(N):
    sl.append(map(int, raw_input().split()))
pl = []
for i in range(M):
    pl.append(map(int, raw_input().split()))
ans = []
for (x,y) in sl:
    dmin = 200000001
    imin = -1
    for (i, (px, py)) in enumerate(pl):
        d = abs(x - px) + abs(y - py)
        if(d < dmin):
            dmin = d
            imin = i
    ans.append(imin+1)
for i in ans:
    print i

Submission status: Wrong Answer

Solution code:
[N,M] = map(int, raw_input().split())
sl = []
for i in range(N):
    sl.append(map(int, raw_input().split()))
pl = []
for i in range(M):
    pl.append(map(int, raw_input().split()))
ans = []
for (x,y) in sl:
    dmin = 200000000
    imin = -1
    for (i, (px, py)) in enumerate(pl):
        d = abs(x - px) + abs(y - py)
        if(d < dmin):
            dmin = d
            imin = i
    ans.append(imin+1)
for i in ans:
    print i

Submission status: Wrong Answer

Solution code:
import numpy as np

def manhattan(x,y):
    return np.abs(x[0]-y[0]) + np.abs(x[1]-y[1])

N,M = map(int,raw_input().split())
students = np.zeros((N,2))
checkpoints = np.zeros((M,2))
for i in range(N):
    students[i][0],students[i][1] = map(int,raw_input().split())
#print a
for j in range(M):
    checkpoints[j][0],checkpoints[j][1] = map(int,raw_input().split())

min = 100
index = np.zeros(N)
for i in range(N):
    for j in range(M):
        d = manhattan(students[i],checkpoints[j])
        if min > d:
            min = d
            index[i] = j
    print (index[i]+1).astype(np.int32)

Submission status: Wrong Answer

Solution code:
import os
import sys


def manhatten(tupleA,tupleB):
	return abs(tupleA[0]-tupleB[0]) + abs(tupleA[1]-tupleB[1])

header = input().split()
N,M = int(header[0]),int(header[1])
students = []
checkpoints = []

for i in range(N):
	student = input().split()
	student = [int(x) for x in student]
	students.append(tuple(student))

for i in range(M):
	checkpoint =input().split()
	checkpoint = [int(x) for x in checkpoint]
	checkpoints.append(tuple(checkpoint))

for student in students:
	distance = []
	for checkpoint in checkpoints:
		d = manhatten(student,checkpoint)
		distance.append(d)
	print(distance)
	print(distance.index(min(distance))+ 1)

Submission status: Wrong Answer

Solution code:
def main():
    #infile = open("compprog.txt", mode="r")
    n, m = [int(x) for x in input().split()]
    students = []
    cpoints = []
    for _ in range(n):
        students.append([int(x) for x in input().split()])
    for _ in range(m):
        cpoints.append([int(x) for x in input().split()])
    for stu in students:
        res = 1
        closest_dis = man_dis(stu[0], cpoints[0][0], stu[1], cpoints[0][1])
        for c_idx in range(1, m):
            if man_dis(stu[0], cpoints[c_idx][0], stu[1], cpoints[c_idx][1]) < closest_dis:
                res = c_idx + 1
        print(res)
    #infile.close()


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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

for i, j in a:
    n = 1
    n_min = 0
    d = 10**8 + 1
    for k, l in c:
        if d > abs(i-k) + abs(j-l):
            d = abs(i-k) + abs(j-l)
            n_min = n
        n += 1
    print(n_min)

Submission status: Wrong Answer

Solution code:
def manhattan(s, c):
	x = abs(s[0] - c[0])
	y = abs(s[1] - c[1])
	return x + y

inpt = map(int, raw_input().split())

student = []
checkpoint = []

for i in range(0, inpt[0]):
	student.append(map(int, raw_input().split()))

for i in range(0, inpt[1]):
	checkpoint.append(map(int, raw_input().split()))
	
for i in range(0, inpt[0]):
	tmp = 0
	minimum = 200000001
	for j in range(0, inpt[1]):
		mnh = manhattan(student[i], checkpoint[j])
		if mnh < minimum:
			tmp = j + 1
			minimum = mnh
	print tmp

Submission status: Wrong Answer

Solution code:
def manhattan(s, c):
	x = abs(s[0] - c[0])
	y = abs(s[1] - c[1])
	return x + y

inpt = map(int, raw_input().split())

student = []
checkpoint = []

for i in range(0, inpt[0]):
	student.append(map(int, raw_input().split()))

for i in range(0, inpt[1]):
	checkpoint.append(map(int, raw_input().split()))
	
for i in range(0, inpt[0]):
	tmp = 0
	minimum = 100000001
	for j in range(0, inpt[1]):
		mnh = manhattan(student[i], checkpoint[j])
		if mnh < minimum:
			tmp = j + 1
			minimum = mnh
	print tmp

Submission status: Wrong Answer

Solution code:
# coding: utf-8
def calculate_distance(x1, y1, x2, y2):
    return abs(x1 - x2) + abs(y1 - y2)

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

students = []
for student in range(N):
    x, y = map(int, input().split())
    students.append([x, y])

checkpoints = []
for point in range(M):
    x, y = map(int, input().split())
    checkpoints.append([x, y])

for s in students:
    pointnumber = 0
    minpoint = 0
    d = 200000000
    for cp in checkpoints:
        pointnumber += 1
        caldis = calculate_distance(s[0], s[1], cp[0], cp[1])
        if d > caldis:
            d = caldis
            minpoint = pointnumber
    print(minpoint)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python

nm = [int(i) for i in input().split()]
n = nm[0]
m = nm[1]

student = list()
point = list()

for i in range(n):
    student.append([int(a) for a in input().split()])

for j in range(m):
    point.append([int(b) for b in input().split()])


mat = [[abs(student[i][0]-point[j][0]) + abs(student[i][1]-point[j][1]) for i in range(n)] for j in range(m)]

for j in range(m):
    print(mat[j].index(min(mat[j]))+1)

Submission status: Wrong Answer

Solution code:
import numpy as np

N, M= list(map(int, raw_input().split()))
student = [list(map(int, raw_input().split())) for i in range(N)]
checkpoint = [list(map(int, raw_input().split())) for i in range(M)]

student = np.array(student)
checkpoint = np.array(checkpoint)

for i in range(M):
    print(np.abs(student - checkpoint[i]).sum(axis=1).argmin()+1)

Submission status: Wrong Answer

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

for i in range(M):
    cc, dd = list(map(int, input().split()))
    c.append(cc)
    d.append(dd)

ans = []
for i in range(N):
    x = a[i]
    y = b[i]
    ind = 0
    distance = 100000
    for j in range(M):
        if(distance > abs(x - c[j]) + abs(y - d[j])):
            ind = j
            distance = abs(x - c[j]) + abs(y - d[j])
    ans.append(ind)

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

Submission status: Wrong Answer

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

for i in range(M):
    cc, dd = list(map(int, input().split()))
    c.append(cc)
    d.append(dd)

ans = []
for i in range(N):
    x = a[i]
    y = b[i]
    ind = 0
    distance = 100000
    for j in range(M):
        if(distance > abs(x - c[j]) + abs(y - d[j])):
            ind = j
            distance = abs(x - c[j]) + abs(y - d[j])
    ans.append(ind)

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

Submission status: Wrong Answer

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

a = []
c = []
for i in range(0, N + M):
    s = list(map(int, input().split()))
    if  i < N:
        a.append(s)
    else:
        c.append(s)

print (a)
print (c)

for i in range(0, N):
    min_idx = 0
    min_dis = 999999999999
    for j in range(0, M):
        dis = abs(a[i][0] - c[j][0]) + abs(a[i][1] - c[j][1])
        if min_dis > dis:
            min_dis = dis
            min_idx = j + 1
    print(str(min_idx))

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
a = [i for i in range(n)]
b = [i for i in range(n)]
c = [i for i in range(m)]
d = [i for i in range(m)]
t = [10**8 for i in range(n)]
for i in range(n):
    a[i],b[i] = map(int,input().split())
for i in range(m):
    c[i],d[i] = map(int,input().split())
check = [0 for i in range(n)]
for i in range(n):
    for j in range(m):
        if t[i] > abs(a[i]-c[j]) + abs(b[i]-d[j]):
            check[i] = j
            t[i] = abs(a[i]-c[j]) + abs(b[i]-d[j])
for i in range(n):
    print(check[i]+1)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
a = [i for i in range(n)]
b = [i for i in range(n)]
c = [i for i in range(m)]
d = [i for i in range(m)]
t = [10**8 for i in range(n)]
for i in range(n):
    a[i],b[i] = map(int,input().split())
for i in range(m):
    c[i],d[i] = map(int,input().split())
check = [0 for i in range(n)]
for i in range(n):
    for j in range(m):
        if t[i] >= abs(a[i]-c[j]) + abs(b[i]-d[j]):
            check[i] = j
            t[i] = abs(a[i]-c[j]) + abs(b[i]-d[j])
for i in range(n):
    print(check[i]+1)

Submission status: Wrong Answer

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

a = [[0, 0] for i in range(n)]

c = [[0, 0] for i in range(m)]

for i in range(n):
    a[i][0], a[i][1] = map(int, input().split())

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

index = 0

print(a,c)

for i in range(n):
    for j in range(m):
        if j == 0 :
            k = abs(a[i][0] - c[j][0]) + abs(a[i][1] - c[j][1]) +1

        di = abs(a[i][0] - c[j][0]) + abs(a[i][1] - c[j][1])
        if di < k:
            index = j + 1
            k = di
    print(index)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
a = [i for i in range(n)]
b = [i for i in range(n)]
c = [i for i in range(m)]
d = [i for i in range(m)]
t = [10**8 for i in range(n)]
for i in range(n):
    a[i],b[i] = map(int,input().split())
for i in range(m):
    c[i],d[i] = map(int,input().split())
check = [0 for i in range(n)]
for i in range(n):
    for j in range(m):
        if t[i] > abs(a[i]-c[j]) + abs(b[i]-d[j]):
            check[i] = j
            t[i] = abs(a[i]-c[j]) + abs(b[i]-d[j])
for i in range(n):
    print(check[i]+1)

Submission status: Accepted

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


for i,j in l_n:
    distance=0
    cnt = 0
    ans = float ( "inf" )
    for k,l in enumerate(l_m,1):
        a,b=l
        distance=abs(i-a)+abs(j-b)
        if ans>distance:
            ans=min(ans,distance)
            cnt=k
    print(cnt)

Submission status: Accepted

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


for i,j in l_n:
    distance=0
    cnt = 0
    ans = float ( "inf" )
    for k,l in enumerate(l_m):
        a,b=l
        distance=abs(i-a)+abs(j-b)
        if ans>distance:
            ans=min(ans,distance)
            cnt=k+1
    print(cnt)

Submission status: Accepted

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

for i in range(n):
  d = 10**9
  h = 0
  for j in range(m):
    if d > (abs(num_list[i][0]-check_list[j][0])+abs(num_list[i][1]-check_list[j][1])):
      d = abs(num_list[i][0]-check_list[j][0])+abs(num_list[i][1]-check_list[j][1])
      h = j+1
  print(h)

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)]
for i in S:
  ans = 0
  k = 10 ** 10
  for j in range(M):
    n = abs(i[0] - C[j][0]) + abs(i[1] - C[j][1])
    if k > n:
      k = n
      ans = j + 1
  else:
    print(ans)

Submission status: Accepted

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

for i in range(n):
  ans = 0
  k = 10**9
  for j in range(m):
    t = abs(pos[i][0] - check[j][0]) + abs(pos[i][1] - check[j][1])
    if k > t:
      k = t
      ans = j + 1
  print(ans)

Submission status: Accepted

Solution code:
import math
import collections
from sys import exit
from itertools import product

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n,m  = mi()
ab = [li() for _ in range(n)]
cd = [li() for _ in range(m)]

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
sd = []
cp = []

for i in range(n):
  sd.append([int(j) for j in input().split()])
for i in range(m):
  cp.append([int(j) for j in input().split()])  
  
dist = [[0 for i in range(m)] for j in range(n)]

for i in range(n):
  for j in range(m):
    dist[i][j] = abs(sd[i][0] - cp[j][0]) + abs(sd[i][1] - cp[j][1])
    
for i in range(n):
  print(dist[i].index(min(dist[i]))+1)

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from math import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
INF = float('inf')
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
    return int(readline())
n,m = readInts()
N = [readInts() for _ in range(n)]
M = [readInts() for _ in range(m)]
for a,b in N:
    pos = INF
    ans = None
    for i,(x,y) in enumerate(M):
        if abs(a-x) + abs(b-y) < pos:
            pos = abs(a-x)+abs(b-y)
            ans = i+1
    print(ans)

Submission status: Accepted

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


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):
    ans = -1
    min_dist = float("inf")
    for j in range(M):
        if (d := dist(AB[i], CD[j])) < min_dist:
            ans = j
            min_dist = d
    print(ans + 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)]
ans = []
INF = 10**9+7
for x in s:
  d = INF
  ind = INF
  for i,y in enumerate(c):
    exd = d
    d = min(d,abs(x[0]-y[0])+abs(x[1]-y[1]))
    if d != exd:
      ind = i
  ans.append(ind+1)
for x in ans:
  print(x)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
A=[]
B=[]
C=[]
D=[]
for i in range(N):
	x,y=map(int,input().split())
	A.append(x)
	B.append(y)
for i in range(M):
	x,y=map(int,input().split())
	C.append(x)
	D.append(y)
for i in range(N):
	ans=[]
	for j in range(M):
		tmp=abs(A[i]-C[j])+abs(B[i]-D[j])
		ans.append(tmp)
	T=len(ans)
	for k in range(T):
		if ans[k]==min(ans):
			print(k+1)
			break

Submission status: Accepted

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


for x in X:
    d1 = sum(x)
    d2 = x[0] - x[1]
    z = 10 ** 9
    for i, y in enumerate(Y, 1):
        D1 = sum(y)
        D2 = y[0] - y[1]
        Z = max(abs(D1 - d1), abs(D2 - d2))
        if z > Z:
            z = Z
            ans = i
    print(ans)

Submission status: Accepted

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

for j in range(n):
    a, b = ab[j][0], ab[j][1]
    ans, res = 0, 1001001001
    for i in range(m):
        c, d = cd[i][0], cd[i][1]
        if abs(a-c)+abs(b-d) < res:
            res = abs(a-c)+abs(b-d)
            ans = i+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 a,b in ab:
    ans = []
    for c,d in cd:
        ans.append(abs(a-c)+abs(b-d))
    print(ans.index(min(ans))+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):
    c,d = map(int, input().split())
    CD.append((c,d))

for a, b in AB:
    min_ = 10**18
    j = -1
    for i, (c, d) in enumerate(CD):
        x = abs(c-a)+abs(d-b)
        if x < min_:
            j = i+1
            min_ = x
    print(j)

Submission status: Accepted

Solution code:
from typing import List


def manhattan_distance(student: List[int], check_point: List[int]) -> int:
    return abs(check_point[0] - student[0]) + abs(check_point[1] - student[1])


def answer(n: int, m: int, students: List[List[int]], check_points: List[List[int]]) -> str:
    students_destination = []
    for student in students:
        mds = {}
        for i, check_point in enumerate(check_points, start=1):
            md = manhattan_distance(student, check_point)
            if md not in mds.keys():
                mds[md] = str(i)
        students_destination.append(mds[min(mds.keys())])

    return '\n'.join(students_destination)


def main():
    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)]
    print(answer(n, m, ab, cd))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
Nlist, Mlist = [], []
res = []

for i in range(N):
    ab = list(map(int, input().split()))
    Nlist.append(ab)

for i in range(M):
    cd = list(map(int, input().split()))
    Mlist.append(cd)

for i in range(N):
    res = 0
    mini = float('inf')
    for j in range(M):
        calc = abs(Nlist[i][0] - Mlist[j][0]) + abs(Nlist[i][1] - Mlist[j][1])
        if calc < mini:
            mini = calc
            res = j+1
    print(res)

Submission status: Accepted

Solution code:
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
ips = lambda:input().split()
import collections
import math
import itertools
import heapq as hq
import sys
n,m = ma()
ckp = []
st = []

for i in range(n):
    st.append(lma())
for i in range(m):
    ckp.append(lma())
for a,b in st:
    tmp=10**15
    ans=0
    for i  in range(m):
        c,d=ckp[i]
        if tmp>abs(a-c)+abs(b-d):
            tmp=abs(a-c)+abs(b-d)
            ans=i+1
    print(ans)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
ab = [0]*n
cd = [0]*m

for i in range(n):
  ab[i] = input().split()
  
for i in range(m):
  cd[i] = input().split()
  
for i in range(n):
  tmp = []
  for j in range(m):
    tmp.append(abs (int(ab[i][0]) - int(cd[j][0])) + abs(int(ab[i][1]) - int(cd[j][1])))
  x = min(tmp) 
  ans = tmp.index(x)
  print(ans+1)

Submission status: Accepted

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

def check(a,b):
    x = a[0] - b[0]
    y = a[1] - b[1]
    if x < 0:
        x = -x
    if y < 0:
        y = -y
    return x + y

for a in al:
    min = 1000000000
    cnt = 1
    for b in bl:
        tmp = check(a,b)
        if tmp < min:
            ans = cnt
            min = tmp
        cnt += 1
    print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

students = [0] * n
for i in range(n):
    a, b = map(int, input().split())
    students[i] = (a + b, a - b)
checkpoints = [0] * m
for i in range(m):
    c, d = map(int, input().split())
    checkpoints[i] = (c + d, c - d)

for a_p_b, a_m_b in students:
    current_distance = 10 ** 10
    current_point = None
    for i, c_d in enumerate(checkpoints):
        c_p_d, c_m_d = c_d
        if max(abs(a_p_b - c_p_d), abs(a_m_b - c_m_d)) < current_distance:
            current_point = i + 1
            current_distance = max(abs(a_p_b - c_p_d), abs(a_m_b - c_m_d))
    print(current_point)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
lst = input().split()

N = int(lst[0])
M = int(lst[1])

students = []
checkpoints = []

for i in range(N):
   students.append(input().split())

for i in range(M):
   checkpoints.append(input().split())

def distance(P, Q):
   return abs(int(P[0]) - int(Q[0])) + abs(int(P[1]) - int(Q[1]))

for s in students:
   l1 = [10 ** 10]
   l2 = [0]
   for i in range(M):
      if distance(s, checkpoints[i]) < l1[-1]:
         l1.append(distance(s, checkpoints[i]))
         l2.append(i+1)
   print(l2[-1])

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
ab = []
for _ in range(N):
    ab.append(list(map(int, input().split())))
cd = []
for _ in range(M):
    cd.append(list(map(int, input().split())))
    
for x in ab:
    a = x[0]
    b = x[1]
    cnt = []
    for y in cd:
        c = y[0]
        d = y[1]
        k = abs(a-c)+abs(b-d)
        cnt.append(k)
    print(cnt.index(min(cnt))+1)

Submission status: Accepted

Solution code:
def f(gx,gy):
    ans = 10**9
    no = 0
    for i in range(m):
        tmp = abs(gx-checkpoint[i][0]) + abs(gy-checkpoint[i][1])
        if tmp < ans:
            ans = tmp
            no = i
    return no+1

n,m = map(int,input().split())
gakusei = []
for i in range(n):
    x,y = map(int,input().split())
    gakusei.append([x,y])
checkpoint = []
for j in range(m):
    x,y = map(int,input().split())
    checkpoint.append([x,y])

#print(gakusei,checkpoint)
for i in range(n):
    print(f(gakusei[i][0],gakusei[i][1]))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
s_pos = []
c_pos = []

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

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

for i in range(n):
    min_dist = 10 ** 16
    c_index = 0
    for j in range(m):
        dist = abs(s_pos[i][0] - c_pos[j][0]) + abs(s_pos[i][1] - c_pos[j][1])
        if dist < min_dist:
            min_dist = dist
            c_index = j + 1
    print(c_index)

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=[]
for i in range(n):
  dis = 10**9
  plc = -1
  for j in range(m):
    if dis > abs(AB[i][0]-CD[j][0])+abs(AB[i][1]-CD[j][1]):
      plc = j+1
      dis = abs(AB[i][0]-CD[j][0])+abs(AB[i][1]-CD[j][1])
  ans.append(plc)
for i in range(n):
  print(ans[i])

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
st = []
co = []
for i in range(n):
  a,b = map(int,input().split())
  st.append([a,b])
for i in range(m):
  c,d = map(int,input().split())
  co.append([c,d])
for a,b in st:
  tmp = 10**9
  output = 0
  for i in range(m):
    if tmp > (new:=abs(a-co[i][0])+abs(b-co[i][1])):
      output = i+1
      tmp = new
  print(output)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
a = []; b = []; c = []; d = []

for i in range(N):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)
for i in range(M):
    x, y = map(int, input().split())
    c.append(x)
    d.append(y)

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

Submission status: Accepted

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

for i in range(n):
    distance = 10000000000
    for j in range(m):
        temp = abs(int(a[i][0]) - int(b[j][0])) + abs(int(a[i][1]) - int(b[j][1]))
        if distance > temp:
            ans = j + 1
        distance = min(temp,distance)
    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)]

for ax, ay in a:
  c = []
  for bx, by in b:
    c.append(abs(bx-ax)+abs(by-ay))
  print(c.index(min(c)) + 1)