Problem:


Score : 200 points

Problem Statement

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

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

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

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

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

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

Which checkpoint will each student go to?

Constraints

1 \leq N,M \leq 50

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

All input values are integers.

Input

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

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

Output

Print N lines.

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

Sample Input 1

2 2
2 0
0 0
-1 0
1 0

Sample Output 1

2
1

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

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

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

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

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

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

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

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

Sample Input 2

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

Sample Output 2

3
1
2

There can be multiple checkpoints at the same coordinates.

Sample Input 3

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

Sample Output 3

5
4
3
2
1



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


Sample output:
2
1

Submission status: Accepted

Solution code:
# import sys
# import math #sqrt,gcd
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
from itertools import product,permutations,combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

mod = int(1e9+7)
INF = 1<<29
lINF = 1<<35

def readInt():
    return list(map(int,input().split()))

def main():
    n,m = readInt()
    a = []
    b = []
    for i in range(n):
        x,y = readInt()
        a.append(x)
        b.append(y)
    c = []
    d = []
    for j in range(m):
        x,y = readInt()
        c.append(x)
        d.append(y)
    for i in range(n):
        length = INF
        ans = 0
        for j in range(m):
            if length>abs(a[i]-c[j])+abs(b[i]-d[j]):
                length = abs(a[i]-c[j]) + abs(b[i]-d[j])
                ans = j
        print(ans+1)
    return

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
import sys
def solve():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    S = [[int(a) for a in input().split()] for _ in range(N)]
    C = [[int(c) for c in input().split()] for _ in range(M)]
    for a, b in S:
        minDist = 10 ** 20
        minPoint = 0
        for i in range(M):
            if abs(a - C[i][0]) + abs(b - C[i][1]) < minDist:
                minDist = abs(a - C[i][0]) + abs(b - C[i][1])
                minPoint = i + 1
        print(minPoint)

    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
a = []
for _ in range(N):
  x, y = map(int, input().split())
  a.append((x, y))
b = []
for _ in range(M):
  x, y = map(int, input().split())
  b.append((x, y))

for x, y in a:
  res = 0
  for i in range(M):
    if abs(x - b[i][0]) + abs(y - b[i][1]) < abs(x - b[res][0]) + abs(y - b[res][1]):
      res = i
  print(res + 1)

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.buffer.readline
    N, M = (int(i) for i in input().split())
    AB = [[int(i) for i in input().split()] for j in range(N)]
    CD = [[int(i) for i in input().split()] for j in range(M)]
    for a, b in AB:
        mi = 10**20
        ans = -1
        for i, p in enumerate(CD):
            d = abs(p[0] - a) + abs(p[1] - b)
            if d < mi:
                mi = d
                ans = i+1
        print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

def mh(x,y,w,z):
    return abs(x-w)+abs(y-z)

for i in range(n):
    min_mh=mh(a[i],b[i],c[0],d[0])
    ansi=1
    for j in range(1,m):
        if min_mh > mh(a[i],b[i],c[j],d[j]):
            min_mh=mh(a[i],b[i],c[j],d[j])
            ansi=j+1
    print(ansi)

Submission status: Accepted

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


for person in ab:
    x, y = person
    m = 10 ** 9
    togo = 0
    for i, checkpoint in enumerate(cd):
        cx, cy = checkpoint
        dist = abs(x - cx) + abs(y - cy)
        if dist < m:
            m = dist
            togo = i
            #print(x, y, cx, cy)
    print(togo + 1)

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 a, b in S:
    ans = 0
    dmin = float('inf')
    for i, (c, d) in enumerate(C):
        d = abs(a - c) + abs(b - d)
        if d < dmin:
            ans = i + 1
            dmin = d
    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)]
ans = []
for i in range(n):
  p = 10 ** 9
  q = 1
  a, b = ab[i]
  for j in range(m):
    c, d = cd[j]
    tmp = abs(a-c) + abs(b-d)
    if tmp < p:
      p = tmp
      q = j + 1
  ans.append(q)
for p in ans:
  print(p)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
students = []
for _ in range(N):
    a, b = map(int, input().split())
    students.append([a, b])
checkpoints = []
for _ in range(M):
    c, d = map(int, input().split())
    checkpoints.append([c, d])

for (a, b) in students:
    best = 1e9
    ans = -1
    for i, (c, d) in enumerate(checkpoints):
        res = abs(a - c) + abs(b - d)
        if (best > res):
            best = res
            ans = i + 1
    print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
stu = []
check = []
for i in range(N):
    s = list(map(int, input().split()))
    stu.append(s)
for i in range(M):
    c = list(map(int, input().split()))
    check.append(c)
ans = [0 for i in range(N)]
for i in range(N):
    min = 10**20
    for j in range(M):
        dis = abs(stu[i][0]-check[j][0])+abs(stu[i][1]-check[j][1])
        if min > dis:
            min = dis
            ans[i] = j+1
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = []
B = []
C = []
D = []

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

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

for i in range(N):
    m = 10**17
    for j in range(M):
        distance = abs(A[i]-C[j]) + abs(B[i]-D[j])
        if distance < m:
            m = distance
            ans = j+1

    print(ans)

Submission status: Accepted

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

person = []
point= []

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

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

for i in range(n):
    ans = []
    for j in range(m):
        ans.append(abs(person[i][0]-point[j][0]) + abs(person[i][1]-point[j][1]))
    ind = ans.index(min(ans))
    print(ind + 1)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
 
def dist(ab,cd):
  return abs(ab[0]-cd[0]) + abs(ab[1]-cd[1])
 
AB = [[int(x) for x in input().split()] for _ in range(N)]
CD = [[int(x) for x in input().split()] for _ in range(M)]
 
answer = []
for ab in AB:
  min_dist = 10**15
  target = 0
  for j,cd in enumerate(CD,1):
    x = dist(ab,cd)
    if min_dist > x:
      min_dist = x
      target = j
  answer.append(target)
 
print(*answer, sep='\n')

Submission status: Accepted

Solution code:

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

person = []
point= []

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

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

for i in range(n):
    ans = []
    for j in range(m):
        ans.append(abs(person[i][0]-point[j][0]) + abs(person[i][1]-point[j][1]))
    ind = ans.index(min(ans))
    print(ind + 1)

Submission status: Accepted

Solution code:
def main():
    N, M = map(int, input().split())
    students = [input().split() for _ in range(N)]
    checkpoints = [input().split() for _ in range(M) ]
    nearest = [None]*N

    for i, s in enumerate(students) :
        min_d = 10**9

        for j, p in enumerate(checkpoints, 1) :
            a, b = map(int, s)
            c, d = map(int, p)
            d = abs(a - c) + abs(b - d)

            if min_d > d:
                min_d = d
                nearest[i] = j

    for i in range(N):
        print(nearest[i])   
main()

Submission status: Accepted

Solution code:
def main():
    N, M = map(int, input().split())
    students = [input().split() for _ in range(N)]
    checkpoints = [input().split() for _ in range(M) ]
    nearest = [None]*N

    for i, s in enumerate(students) :
        min_d = 10**9
        index = 0

        for j, p in enumerate(checkpoints, 1) :
            a, b = map(int, s)
            c, d = map(int, p)
            d = abs(a - c) + abs(b - d)

            if min_d > d:
                min_d = d
                index = j

        nearest[i] = index

    for i in range(N):
        print(nearest[i])   
main()

Submission status: Accepted

Solution code:
def main():
    N, M = map(int, input().split())
    students = [input().split() for _ in range(N)]
    checkpoints = [input().split() for _ in range(M) ]
    nearest = [None]*N

    for i, s in enumerate(students) :
        min_d = 10**9

        for j, p in enumerate(checkpoints, 1) :
            a, b = map(int, s)
            c, d = map(int, p)
            d = abs(a - c) + abs(b - d)

            if min_d > d:
                min_d = d
                nearest[i] = j

    for i in range(N):
        print(nearest[i]) 
main()

Submission status: Accepted

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

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)]
for i in range(N):
    ans = 0
    now = 10**10
    for j in reversed(range(M)):
        if abs(a[i][0]-c[j][0])+abs(a[i][1]-c[j][1])<=now:
            ans = j+1
            now = abs(a[i][0]-c[j][0])+abs(a[i][1]-c[j][1])
    print(ans)

Submission status: Accepted

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

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

sci = []

for i in range(N):
    mindis = 0
    minind = 0
    for j in range(M):
        m = mah(sp[i], cp[j])
        if j == 0 or mindis > m:
            mindis = m
            minind = j
    sci.append(minind+1)

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

Submission status: Accepted

Solution code:
(n, _), *d = [list(map(int, s.split())) for s in open(0)]
for i, j in d[:n]:
    l = [abs(x - i) + abs(y - j) for x, y in d[n:]]
    print(l.index(min(l)) + 1)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
st = [list(map(int, input().split())) for i in range(n)]
cp = [list(map(int, input().split())) for i in range(m)]
for s in st:
  ans = -1
  dmin = 10**9
  for i, c in enumerate(cp):
    dist = abs(c[0] - s[0]) + abs(c[1] - s[1])
    if dist < dmin:
      dmin = dist
      ans = i + 1
  print(ans)

Submission status: Accepted

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

N, M = map(int, input().split())
a, b = [0] * N, [0] * N
for i in range(N):
  a[i], b[i] = map(int, input().split())
c, d = [0] * M, [0] * M
for i in range(M):
  c[i], d[i] = map(int, input().split())

for i in range(N):
  min_dist = float("inf")
  ans = -1
  for j in range(M):
    dist = abs(a[i] - c[j]) + abs(b[i] - d[j])
    if dist < min_dist:
      min_dist = dist
      ans = j + 1
    elif dist == min_dist:
      ans = min(ans, j + 1)
  print(ans)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
ab = []
for i in range(N):
    a,b = list(map(int,input().split()))
    a -= 1
    b -= 1
    ab.append([a,b])
cd = []
for i in range(M):
    c,d = list(map(int,input().split()))
    c -= 1
    d -= 1
    cd.append([c,d])
ans = []
for a,b in ab:
    dis = float('inf')
    for i in range(M):
        if dis > abs(cd[i][0]-a)+abs(cd[i][1]-b):
            dis = abs(cd[i][0]-a)+abs(cd[i][1]-b)
            ind = i
    ans.append(ind)
for i in ans:
    print(i+1)

Submission status: Accepted

Solution code:
# ABC 057: B – Checkpoints
n, m = map(int, input().split())
studentPoints = [list(map(int, input().split())) for _ in range(n)]
checkPoints = [list(map(int, input().split())) for _ in range(m)]

for i in range(n):
    distances = [abs(studentPoints[i][0] - checkPoints[k][0]) + abs(studentPoints[i][1] - checkPoints[k][1]) for k in range(m)]
    print(distances.index(min(distances)) + 1)

Submission status: Accepted

Solution code:
# ABC 057: B – Checkpoints
studentPoints = []
checkPoints = []
n, m = map(int, input().split())
for _ in range(n):
    studentPoints.append([int(s) for s in input().split()])
for _ in range(m):
    checkPoints.append([int(s) for s in input().split()])

for i in range(n):
    distances = [abs(studentPoints[i][0] - checkPoints[k][0]) + abs(studentPoints[i][1] - checkPoints[k][1]) for k in range(m)]
    print(distances.index(min(distances)) + 1)

Submission status: Accepted

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

def distance(x1, x2, y1, y2):
    return abs(x1 - x2) + abs(y1 - y2)

ans_distance = [float('inf')] * N
ans = [float('inf')] * N
for i in range(N):
    for j in range(M):
        #print(distance(ab[i][0], cd[j][0], ab[i][1], cd[j][1]))
        if ans_distance[i] > distance(ab[i][0], cd[j][0], ab[i][1], cd[j][1]):
            ans_distance[i] = distance(ab[i][0], cd[j][0], ab[i][1], cd[j][1])
            ans[i] = j+1

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# AtCoder
N, M = map(int, input().split())
nlst = [list(map(int, input().split())) for i in range(N)]
mlst = [list(map(int, input().split())) for i in range(M)]

for i in range(N):
    mn = []
    x1 = nlst[i][0]
    y1 = nlst[i][1]
    for j in range(M):
        x2 = mlst[j][0]
        y2 = mlst[j][1]

        dis = abs(x1-x2) + abs(y1-y2)
        mn.append(dis)
    minn = min(mn)
    print(mn.index(minn)+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 i in range(len(ab)):
  x = [10000000000000000, 1000]
  for j in range(len(cd)):
    if x[0] > abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1]):
      x[0] = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
      x[1] = j

  print(x[1] + 1)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
st=[list(map(int,input().split())) for i in range(n)]
cheak=[list(map(int,input().split())) for i in range(m)]
# print(st)
# print(cheak)
ans=[]
for i in st:
    for k in cheak:
        res=abs(i[0]-k[0])+abs(i[1]-k[1])
        ans.append(res)
    x=min(ans)
    print(ans.index(x)+1)
    ans.clear()

Submission status: Accepted

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

for person in people:
  mini = 1000000000
  minIndex = 0
  for i in range(m):
    distance = abs(person[0]-points[i][0]) + abs(person[1]-points[i][1])
    
    if mini > distance:
      mini = distance
      minIndex = i
  print(minIndex+1)

Submission status: Accepted

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

G,C = [],[]

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

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

ans_L = []
for i in range(n):
    ans = float("inf")
    a,b = G[i]
    idx = 0
    for j in range(m):
        c,d = C[j]
        ten = abs(a-c) + abs(b-d)
        if ans != min(ans,ten):
            ans = ten
            idx = j+1

    ans_L.append(idx)

for i in ans_L:
    print(i)

Submission status: Accepted

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

for i in range(N):
  a = int(SP[i][0])
  b = int(SP[i][1])
  k = 0
  md = abs(int(CP[0][0])-a)+abs(int(CP[0][1])-b)
  for j in range(M):
    x = abs(int(CP[j][0])-a)+abs(int(CP[j][1])-b)
    if x < md:
      md = x
      k = j
  print(k+1)

Submission status: Accepted

Solution code:
INF=1000000007
N,M=map(int,input().split())
A=[]
B=[]
for i in range(N):
  a,b=list(map(int,input().split()))
  A.append([a,b])
for i in range(M):
  c,d=list(map(int,input().split()))
  B.append([c,d])
for i in A:
  m=INF
  p=0
  for j in range(M):
    d=abs(i[0]-B[j][0])+abs(i[1]-B[j][1])
    if m>d:
      m=d
      p=j+1
  print(p)

Submission status: Accepted

Solution code:
#学生，チェックポイント
n, m = map(int, input().split())
#学生の位置
students = [list(map(int, input().split())) for i in range(n)]
#ポイントの位置
points = [list(map(int, input().split())) for i in range(m)]

for i in range(n): #生徒
    for j in range(m): #チェックポイント
        dist = abs(students[i][0]-points[j][0]) + abs(students[i][1]-points[j][1])
        if j < 1:
            min_dist = dist
            min_id = j + 1
        else:
            if min_dist > dist:
                min_dist = dist
                min_id = j + 1
    print(int(min_id))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
students = []
checkpoints = []
INF = 10**19

for _ in range(N):
    ai, bi = map(int, input().split())
    students.append((ai, bi))

for _ in range(M):
    ci, di = map(int, input().split())
    checkpoints.append((ci, di))

for item in students:
    tmp = INF
    ans = INF, INF
    for i in range(M):
        manhattan = abs(item[0] - checkpoints[i][0]) + abs(item[1] - checkpoints[i][1])
        if tmp > manhattan:
            tmp = manhattan
            ans = i+1
    print(ans)

Submission status: Accepted

Solution code:
def dis(j,i):
    return abs(c[j]-a[i])+abs(d[j]-b[i])

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

close = 0
for i in range(n):
    for j in range(m-1):
        if dis(j+1,i) < dis(close, i):
            close = j+1
    print(close+1)
    close = 0

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
np = list()
for _ in range(n):
    np.append(list(map(int, input().split())))
mp = list()
for _ in range(m):
    mp.append(list(map(int, input().split())))

for N in np:
    tmp = list()
    for M in mp:
        tmp.append([abs(N[0]-M[0])+abs(N[1]-M[1]), mp.index(M)+1])

    tmp.sort()
    print(tmp[0][1])

Submission status: Accepted

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

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

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

for i in range(N):
    saitei = float("inf")
    ans = 0
    for j in range(M):
        if abs(A[i][0]-B[j][0]) + abs(A[i][1]-B[j][1]) < saitei:
            saitei = abs(A[i][0]-B[j][0]) + abs(A[i][1]-B[j][1])
            ans = j+1   
    print(ans)

Submission status: Accepted

Solution code:
import numpy as np
from scipy.spatial.distance import minkowski

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

for i in range(n):
    c = np.array([minkowski(a[i], j , 1) for j in b], dtype=np.int64)
    ans = np.argmin(c) + 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):
    a, b = AB[i]
    res = float("inf")
    for j in range(m):
        c, d = CD[j]
        dist = abs(a - c) + abs(b - d)
        if res > dist:
            res = dist
            ans = j + 1
    print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
p = [list(map(int, input().split())) for _ in range(N)]
q = [list(map(int, input().split())) for _ in range(M)]
for i in range(N):
  m = 1000000000
  cnt = -1
  pnt = p[i][:]
  for j in range(M):
    d = abs(pnt[0] - q[j][0]) + abs(pnt[1] - q[j][1])
    if m > d:
      cnt = j
      m = d
  print(cnt+1)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(N)]
cd = [list(map(int,input().split())) for _ in range(M)]
INF = 4*10**9+1

for i in range(N):
    ans,dist = 0,INF
    for j in range(M):
        if dist > abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1]):
            ans = j + 1
            dist = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
    print(ans)

Submission status: Accepted

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

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

check=[]
for i in range(m):
    check.append([int(i) for i in input().split()])
ans=[]
for i in students:
    x,y=i
    move=None
    minhat=1000000000
    for j in  range(m):
        x2,y2=check[j]
        manhat=abs(x-x2)+abs(y-y2)
        if manhat<minhat:
            minhat=manhat
            move=j
    ans.append(move+1)
for i in range(len(ans)):
    print(ans[i])

Submission status: Accepted

Solution code:

import math
#import itertools
#import statistics
#import numpy as np
#import collections
#n = int(input())
n, m = list(map(int, input().split()))
#a = list(map(int, input().split()))
a = []
b = []
c = []
d = []

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

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

for i in range(n):
    dist_min = 1000000000
    dist_index = n+m
    for j in range(m):
        dist = abs(a[i]-c[j]) + abs(b[i]-d[j])
        if dist <= dist_min:
            if dist!=dist_min:
                dist_index = j
            dist_min = dist

        
        #print("dist="+str(dist)+" distmin="+str(dist_min)+" distidx="+str(dist_index))
    print(dist_index+1)

Submission status: Accepted

Solution code:
#マンハッタン距離 |x| + |y| で 一番近いチェックポイント
#
#この問題では、xy格子上を縦、横に無駄なく歩いた場合の距離がマンハッタン距離。
#人がいる座標 (a, b) N 個、チェックポイントの座標 (c,d) M 個を 「リスト」 に格納。
#各人ごとに M 個 のチェックポイントをテストすることで、各人のマンハッタン距離が
#一番近いチェックポイントを求めることができる


INF = 1000000007

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

ab = []

for i in range(N):
    ab.append([int(i) for i in input().split()])

cd = []

for i in range(M):
    cd.append([int(i) for i in input().split()])

for i in range(N):
    ans = 0
    dst = INF
    for j in range(M):
        tmp = abs(cd[j][0] - ab[i][0]) + abs(cd[j][1] - ab[i][1])

        if tmp < dst:
            # 0-indexed
            dst = tmp
            ans = j + 1

    print(ans)

Submission status: Accepted

Solution code:
import math

n, m = map(int, input().split())
ns, ms = range(n), range(m)
students = []
for i in ns:
    a, b = map(int, input().split())
    students.append([a, b])
checkpoints = []
for i in ms:
    c, d = map(int, input().split())
    checkpoints.append([c, d])

for i in ns:
    ans = [0, float('inf')]
    for j in ms:
        dist = abs(students[i][0] - checkpoints[j][0]) + abs(students[i][1] - checkpoints[j][1])
        if dist < ans[1]:
            ans = [j + 1, dist]
    print(ans[0])

Submission status: Accepted

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

Submission status: Accepted

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

for i in ab:
    ans = []
    for j in cd:
        ans.append(abs(i[0] - j[0]) + abs(i[1] - j[1]))
    print(ans.index(min(ans))+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# B - Checkpoints
# 標準入力の取得
N,M = list(map(int, input().split()))
a,b = [],[]
for n in range(N):
    a_n,b_n = [int(i) for i in input().split()]
    a.append(a_n)
    b.append(b_n)
c,d = [],[]
for m in range(M):
    c_m,d_m = [int(i) for i in input().split()]
    c.append(c_m)
    d.append(d_m)

# 全探索により、最も近いチェックポイントを算出
nearest_checkpoint_list = []
for n in range(N):
    a_n = a[n]
    b_n = b[n]

    nearest_checkpoint = 0
    min_manhattan_distance = abs(a_n - c[0]) + abs(b_n - d[0])

    for m in range(1, M):
        manhattan_distance = abs(a_n - c[m]) + abs(b_n - d[m])
        if min_manhattan_distance > manhattan_distance:
            min_manhattan_distance = manhattan_distance
            nearest_checkpoint = m

    nearest_checkpoint_list.append(nearest_checkpoint + 1)

# 結果出力
for n in range(N):
    print(nearest_checkpoint_list[n])

Submission status: Accepted

Solution code:
def distance(ab, cd):
  return abs(ab[0] - cd[0]) + abs(ab[1] - cd[1])

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

check_index = []
for i, ab in enumerate(AB):
  min_index = 0
  for j, cd in enumerate(CD):
    check_dis = distance(ab, cd)
    min_dis = distance(ab, CD[min_index])
    if(min_dis > check_dis):
      min_index = j
  
  check_index.append(min_index)

for ci in check_index:
  print(ci + 1)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
man = [[int(x) for x in input().split()] for _ in range(N)]
check = [[int(x) for x in input().split()] for _ in range(M)]

for a, b in man:
    tmp = 1000000000
    ans = 1
    for i, (c, d) in enumerate(check):
        if tmp > (abs(a-c) + abs(b-d)):
            tmp = min(tmp, abs(a-c) + abs(b-d))
            ans = i+1
    print(ans)

Submission status: Accepted

Solution code:
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""

# Written by NoKnowledgeGG @YlePhan

#import math
#mod = 10**9+7



def main():
  n,m = map(int,input().split())
  
  AB = [map(int,input().split()) for _ in range(n)]
  CD = [list(map(int,input().split())) for _ in range(m)]
  idx = 1

  for i in range(n):
    a,b = AB[i]
    man = float("inf")
    for j in range(m-1,-1,-1):
      c,d = CD[j]
      if abs(a-c) + abs(b-d) <= man:
        man = abs(a-c) + abs(b-d)
        idx = j
    print(idx+1)
      
  
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)] #student
cd=[list(map(int,input().split())) for _ in range(m)] #check point
for i in range(n):
    l=[]
    for j in range(m):
        l.append(abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1]))
    k=l.index(min(l))+1
    print(k)

Submission status: Accepted

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

for a,b in ab:
    ans = 10000000000000000000000
    for k,c in enumerate(cd):
        memo = abs(a-c[0])+abs(b-c[1])
        if memo<ans:
            ans=memo
            ansnum=k
    print(ansnum+1)

Submission status: Accepted

Solution code:
n, m = [int(_) for _ in input().split()]
student = [[int(x) for x in input().split()] for i in range(n)]
check = [[int(x) for x in input().split()] for i in range(m)]
for s in student:
  d = 10**12
  i = -1
  for ii, c in enumerate(check, 1):
    dd = abs(s[0] - c[0]) + abs(s[1] - c[1])
    if dd < d:
      d = dd
      i = ii
  print(i)