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
def MI(): return map(int,sys.stdin.readline().rstrip().split())

N,M = MI()
ab = [tuple(MI()) for _ in range(N)]
cd = [tuple(MI()) for _ in range(M)]

for i in range(N):
    a,b = ab[i]
    min_dis = 10**10
    k = 100
    for j in range(M):
        c,d = cd[j]
        if min_dis > abs(a-c) + abs(b-d):
            k = j+1
            min_dis = abs(a-c) + abs(b-d)
    print(k)

Submission status: Accepted

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

n, m = map(int, input().split())
ab = []
cd = []
for _ in range(n):
    a, b = map(int, input().split())
    ab.append((a, b))
for _ in range(m):
    c, d = map(int, input().split())
    cd.append((c, d))
ans = []
for a, b in ab:
    t = 10**18
    checkpoint = -1
    for i, cdi in enumerate(cd):
        c, d = cdi
        dist = abs(a-c)+abs(b-d)
        if dist < t:
            t = dist
            checkpoint = (i+1)
    ans.append(checkpoint)
print(*ans, sep='\n')

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

Submission status: Accepted

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

ab=[[int(a) for a in input().split()]for _ in range(n)]

cd=[[int(a) for a in input().split()]for _ in range(m)]

#print(ab,cd)
INF=float("inf")
for (a,b) in ab:
  tmp=INF
  now=0
  for i,(c,d) in enumerate(cd):
    if tmp>abs(a-c)+abs(b-d):
      now=i+1
      tmp=abs(a-c)+abs(b-d)
    else:
      pass
    
  print(now)

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

for i in range(n):
    x = 1 << 30
    y = -1
    a, b = ab[i]
    for j in range(m):
        c, d = cd[j]
        d = abs(a - c) + abs(b - d)
        if x > d:
            x = d
            y = j
    print(y + 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)]
where=[]
for i in range(n):
    distance=10**9
    for j in range(m):
        if distance>abs(s[i][0]-c[j][0])+abs(s[i][1]-c[j][1]):
            distance=abs(s[i][0]-c[j][0])+abs(s[i][1]-c[j][1])
            w=j
    where.append(w+1)
[print(i) for i in where]

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, M = mapint()
AB = [list(mapint()) for _ in range(N)]
CD = [list(mapint()) for _ in range(M)]

for a, b in AB:
    dist = 10**18
    ans = -1
    for i in range(M):
        c, d = CD[i]
        if abs(a-c)+abs(b-d)<dist:
            ans = i+1
            dist = abs(a-c)+abs(b-d)
    print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

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

result = np.zeros([m, n], dtype=np.int64)

cd = []
for i in range(m):
    c, d = map(int, input().split())
    for j, (a, b) in enumerate(ab):
        result[i, j] = abs(a - c) + abs(b - d)

print(*result.argmin(axis=0) + 1, sep="\n")

Submission status: Accepted

Solution code:
def LI():
    return list(map(int, input().split()))


def LIHW(h):
    return [list(map(int, input().split())) for _ in range(h)]


N, M = LI()
Nlist = LIHW(N)
Mlist = LIHW(M)
anslist = [0]*N
for i in range(N):
    a, b = Nlist[i]
    ans = 10**9
    for j in range(M):
        c, d = Mlist[j]
        kyori = abs(c-a)+abs(d-b)
        if ans > kyori:
            ansind = j+1
            ans = kyori
    anslist[i] = ansind

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

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

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

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

ans = []
for i in range(N):
    a, b = s[i]
    i_ans = -1
    tmp = float("inf")
    for j in range(M):
        c, d = g[j]
        dist = abs(c-a) + abs(d-b)
        # print(i, j, dist)
        if dist < tmp:
            i_ans = j
            tmp = dist
    ans.append(i_ans)

for a in ans:
    print(a+1)

Submission status: Accepted

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

for i in range(N):
    MIN = 10 ** 10
    index = -1
    for j in range(M):
        if MIN > abs(students[i][0] - points[j][0]) + abs(students[i][1] - points[j][1]):
            MIN = abs(students[i][0] - points[j][0]) + abs(students[i][1] - points[j][1])
            index = j
    print(index + 1)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(N)]
B = [list(map(int,input().split())) for _ in range(M)]
B.insert(0,0)
for i in range(N):
    a,b = A[i]
    dmin = 10**9
    ind = M
    for j in range(M,0,-1):
        c,d = B[j]
        dist = abs(a-c)+abs(b-d)
        if dist<=dmin:
            dmin = dist
            ind = j
    print(ind)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
point = []
target = []
ans = []
for i in range(N):
    person = list(map(int,input().split()))
    point.append(person)
for j in range(M):
    goal = list(map(int,input().split()))
    target.append(goal)
for k in point:
    check = []
    for l in target:
        a = 0
        a += abs(k[0]-l[0])+abs(k[1]-l[1])
        check.append(a)
    b = min(check)
    ans.append(check.index(b))
for m in ans:
    print(m+1)

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

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

for i in range(n):
    s = student[i]
    dist = float('inf')

    num=0
    for j in range(m):
        c=checkpoint[j]
        tmp = abs(s[0]-c[0]) + abs(s[1]-c[1])

        if tmp < dist:
            dist = tmp
            num=j+1

    print(num)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
X = []
for i in range(N):
  a,b = map(int,input().split())
  X.append((a,b))
C = []
for i in range(M):
  c,d = map(int,input().split())
  C.append((c,d))
ans = [0 for _ in range(N)]
INF = float("inf")
for i in range(N):
  MIN = INF
  check = -1
  for y in range(M):
    temp = abs(X[i][0]-C[y][0]) + abs(X[i][1]-C[y][1])
    if temp < MIN:
      MIN = temp
      check = y+1
  ans[i] = check
print(*ans,sep="\n")

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

N,M = MI()
ab = [tuple(MI()) for _ in range(N)]
cd = [tuple(MI()) for _ in range(M)]

for i in range(N):
    a,b = ab[i]
    min_dis = 10**10
    k = 100
    for j in range(M):
        c,d = cd[j]
        if min_dis > abs(a-c) + abs(b-d):
            k = j+1
            min_dis = abs(a-c) + abs(b-d)
    print(k)

Submission status: Accepted

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

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


for a,b in abl:
    cmin = 10**10
    mini = -1
    for i,(c,d) in enumerate(cdl):
        v = abs(a-c)+abs(b-d)
        if v < cmin:
            cmin = v
            minc,mind = c,d
            mini = i+1
    print(mini)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(n)]
b=[list(map(int,input().split())) for _ in range(m)]
for i in range(n):
    ans=-1
    num=10**10
    for j in range(m):
        cnt=abs(a[i][0]-b[j][0])+abs(a[i][1]-b[j][1])
        if cnt<num:
            ans=j+1
            num=cnt
    print(ans)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
stu = []
for v in range(N):
    ai,bi = map(int,input().split())
    stu.append((v,ai,bi))
cp = []
for w in range(M):
    ci,di = map(int,input().split())
    cp.append((w,ci,di))
#大きい番号から調べることで同じ値のとき最小のチェックポイントに行ける
cp = cp[::-1]
ans = [0]*N
#ある学生について    
for i,x,y in stu:
    #あるチェックポイントについて
    mindist = 10**16
    cp_num = 0
    for j,k,l in cp:
        dist = abs(x-k) + abs(y-l)
        if mindist >= dist:
            mindist = dist
            cp_num = j+1
    ans[i] = cp_num
for n in ans:
    print(n)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
from scipy.special import comb
import copy
sys.setrecursionlimit(10**6)


def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()[:-1]


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


n, m = zz()
A, B = [], []
for i in range(n):
    a, b = zz()
    A.append(a)
    B.append(b)
C, D = [], []
for i in range(m):
    c, d = zz()
    C.append(c)
    D.append(d)

dist = [[0]*m for i in range(n)]
for i in range(n):
    for j in range(m):
        dist[i][j] = abs(A[i] - C[j]) + abs(B[i] - D[j])


for i in range(n):
    print(np.argmin(dist[i])+1)

Submission status: Accepted

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

for j in range(m):
    c.append(list(map(int, input().split())))
    
for k in range(n):
    cnt = []
    for l in range(m):
        kyori = abs(s[k][0]-c[l][0])+abs(s[k][1]-c[l][1])
        cnt.append(kyori)
    print(cnt.index(min(cnt))+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())))
def Mandis(x1,x2,y1,y2):
    e=abs(x1-x2)+abs(y1-y2)
    return e
for i in range(N):
    g=0
    for j in range(M-1):
        if Mandis(ab[i][0],cd[j+1][0],ab[i][1],cd[j+1][1])<Mandis(ab[i][0],cd[g][0],ab[i][1],cd[g][1]):
            g=j+1
    print(g+1)

Submission status: Accepted

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

for i in range(n + m):
    x, y = map(int, input().split())
    lx.append(x)
    ly.append(y)

for i in range(n):
    r = []
    for j in range(n, m + n):
        r.append(abs(lx[i] - lx[j]) + abs(ly[i] - ly[j]))
    print(r.index(min(r)) + 1)

Submission status: Accepted

Solution code:
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n,m = LI()
    student = []
    spot = []
    for _ in range(n):
        a,b = LI()
        student.append([a,b])

    for _ in range(m):
        c,d = LI()
        spot.append([c,d])
    inf = float("inf")
    for x,y in student:
        near = (0,inf)
        area_num = 1
        for s,t in spot:
            dist = abs(x-s) + abs(y-t)
            if near[1] > dist:
                near = (area_num,dist)
            area_num += 1
        print(near[0])
main()

Submission status: Accepted

Solution code:
def dis(a, b, c, d):
    num = abs(a - c) + abs(b - d)
    return num

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

Submission status: Accepted

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

Submission status: Accepted

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

As = []
for _ in range(0, N):
    x, y = input().split()
    As.append((int(x), int(y)))

Cs = []
for _ in range(0, M):
    x, y = input().split()
    Cs.append((int(x), int(y)))

for a in As:
    d = {}
    minI = -1
    minM = float('inf')
    for i, c in enumerate(Cs):
        ax, ay = a
        cx, cy = c
        m = abs(ax - cx) + abs(ay - cy)
        if m < minM:
            minI = i + 1
            minM = m

    print(minI)

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rf = lambda: map(float, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n, m = rm()
stu = [rl() for _ in range(n)]
poi = [rl() for _ in range(m)]
for lis in stu:
    x, y = lis
    min_ = inf
    ans = ''
    for idx, li in enumerate(poi, 1):
        x1, y1 = li
        t = abs(x1-x)+abs(y1-y)
        if min_ > t:
            min_ = t
            ans = idx
    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):
    dis = []
    for j in range(m):
        dis.append(abs(ab[i][0]-cd[j][0]) + abs(ab[i][1]-cd[j][1]))
    print(dis.index(min(dis))+1)

Submission status: Accepted

Solution code:
from sys import stdin
def input():
    return stdin.readline().strip()

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

l = []
for i in range(n):
    ans = (float('inf'), 0)
    for j in range(m):
        distance = (abs(a[i] - c[j]) + abs(b[i] - d[j]), j)
        if distance < ans:
            ans = distance
    l.append(ans[1] + 1)

for i in l:
    print(i)

Submission status: Accepted

Solution code:
def minDistPoint(Student,List):
    ans_dist = 500000000
    res = 0
    for k,pos in List.items():
        dist = abs(Student[0]-pos[0])+abs(Student[1]-pos[1])
        if dist<ans_dist:
            ans_dist = dist
            res=k
    return res+1

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

cp = [0]*N

for i in range(len(AB)):
    cp[i] = minDistPoint(AB[i],CD)
    
for i in cp:
    print(i)

Submission status: Accepted

Solution code:
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()
P = []
C = []
for i in range(N):
    a, b = MAP()
    P.append([a, b])
for j in range(M):
    c, d = MAP()
    C.append([c, d])

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

for i in range(N):
    min_d = INF
    for j in range(M):
        tmp_d = calculate_manhattan_distance(P[i][0], P[i][1], C[j][0], C[j][1])
        if tmp_d < min_d:
            min_d = tmp_d
            ans_c_id = j + 1
    print(ans_c_id)

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()
AB = [LIST() for i in range(N)]
CD = [LIST() for i in range(M)]
ans = []
for a, b in AB:
    i = 0
    num = 0
    mi = 10 ** 9
    for c, d in CD:
        dist = abs(a - c) + abs(b - d)
        if mi > dist:
            num = i
            mi = dist
        i += 1
    ans.append(num + 1)

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

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    N, M = MAP()
    AB = [LIST() for _ in range(N)]
    CD = [LIST() for _ in range(M)]

    for a, b in AB:
        dist = INF

        for i, cd in enumerate(CD):
            if dist > abs(a - cd[0]) + abs(b - cd[1]):
                dist = abs(a - cd[0]) + abs(b - cd[1])
                num = i + 1

        print(num)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

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

ans=[0 for i in range(N)]
for i in range(N):
    dis=10**9
    for j in range(M):
        xx=abs(ab[i][0]-cd[j][0])
        yy=abs(ab[i][1]-cd[j][1])
        temp=xx+yy
        if dis>temp:
            dis=temp
            ans[i]=j
for a in ans:
    print(a+1)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
stu=[0 for i in range(N)]
che=[0 for j in range(M)]

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

for j in range(M):
    che[j]=list(map(int,input().split()))

for s in range(N):
    x=[]
    a,b=stu[s]
    for t in range(M):
        c,d=che[t]
        x.append(abs(a-c)+abs(b-d))
    num=x.index(min(x))
    print(num+1)

Submission status: Accepted

Solution code:
# coding = SJIS

n, m = map(int, input().split())
ab = []
for i in range(n):
    an, bn = map(int, input().split())
    ab.append([an, bn])
cd = []
for i in range(m):
    cn, dn = map(int, input().split())
    cd.append([cn, dn])

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]))
    print((dis.index(min(dis)) + 1))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
N, M = map(int, input().split())
a = [0] * N
b = [0] * N
for i in range(N):
    a[i], b[i] = map(int, input().split())
c = [0] * M
d = [0] * M
for i in range(M):
    c[i], d[i] = map(int, input().split())

for i in range(N):
    x = 0
    y = 0
    dist = 10**20
    ans = 0
    for j in range(M):
        x = abs(a[i] - c[j])
        y = abs(b[i] - d[j])
        if x + y < dist:
            dist = x + y
            ans = j + 1
    print(ans)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
stu=[list(map(int,input().split()))for i in range(N)]
zahyou=[list(map(int,input().split()))for i in range(M)]
ans=list()
for i in range(N):
    tmp=10**10
    tmp2=0
    for j in range(M):
        dist=abs(stu[i][1]-zahyou[j][1])+abs(stu[i][0]-zahyou[j][0])
        if dist <tmp:
            tmp=dist
            tmp2=j+1
    ans.append(tmp2)        
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
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)]

    for s in ab:
        tmp = 10 ** 10
        ans = 0
        for i, t in enumerate(cd, 1):
            if tmp > abs(s[0]-t[0]) + abs(s[1]-t[1]):
                ans = i
                tmp = abs(s[0]-t[0]) + abs(s[1]-t[1])
        print(ans)


if __name__ == "__main__":
    main()

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 a in A:
    m=float('Inf')
    p=0
    for i,b in enumerate(B):
        if m>abs(a[0]-b[0])+abs(a[1]-b[1]):
            m=abs(a[0]-b[0])+abs(a[1]-b[1])
            p=i+1
    print(p)

Submission status: Accepted

Solution code:
N,M = (int(T) for T in input().split())
Stud = [[] for TN in range(0,N)]
Check = [[] for TM in range(0,M)]
for TN in range(0,N):
    Stud[TN] = [int(T) for T in input().split()]
for TM in range(0,M):
    Check[TM] = [int(T) for T in input().split()]

GoPoint = [0]*N
for TN in range(0,N):
    MIND = 10**9
    for TM in range(0,M):
        Dist = abs(Stud[TN][0]-Check[TM][0])+abs(Stud[TN][1]-Check[TM][1])
        if Dist<MIND:
            MIND = Dist
            MINI = TM
    GoPoint[TN] = MINI+1
print('\n'.join(str(T) for T in GoPoint))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
student = [[0] for _ in range(N+1)]
point = [[0] for _ in range(M+1)]
for i in range(1, N+1):
    student[i] = list(map(int, input().split()))
for i in range(1, M+1):
    point[i] = list(map(int, input().split()))

for i in range(1, N+1):
    this_ans = 0
    pre_min_dict = 2000000001 * 2
    for j in range(1, M+1):
        this_dict = abs(student[i][0] - point[j][0]) + abs(student[i][1] - point[j][1])
        if pre_min_dict > this_dict:
            this_ans = j
            pre_min_dict = this_dict
    print(this_ans)

Submission status: Accepted

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

closest = {}
for s in student:
    min_dist = 'INF'
    ans = 1
    for c in checkpoint:
        dist = abs(s[0]-c[0]) + abs(s[1]-c[1])
        if min_dist == 'INF' or dist < min_dist:
            min_dist = dist
            closest[s] = ans
        ans += 1

for s in student:
    print(closest[s])

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def main():
    N, M = map(int, input().split())
    student = []
    for _ in range(N):
        a, b = map(int, input().split())
        student.append((a, b))
    checkpoint = []
    for _ in range(M):
        c, d = map(int, input().split())
        checkpoint.append((c, d))

    for a, b in student:
        point, dist = -1, 10**18
        for i in range(M):
            c, d = checkpoint[i]
            if abs(a - c) + abs(b - d) < dist:
                point = i
                dist = abs(a - c) + abs(b - d)
        print(point + 1)



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from operator import itemgetter
n,m = map(int,input().split())
stu = list(list(map(int,input().split())) for i in range(n))
cp = list(list(map(int,input().split())) for i in range(m))

for sx,sy in stu:
    dis = {}
    cnt = 1
    for cx,cy in cp:
        dis[cnt] = (abs(sx - cx) + abs(sy - cy))
        cnt += 1
    print(min(dis.items(), key = itemgetter(1))[0])

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)]
for i in range(N):
    m = 0
    for j in range(M):
        if abs(s[i][0]-c[m][0]) + abs(s[i][1]-c[m][1]) > abs(s[i][0]-c[j][0]) + abs(s[i][1]-c[j][1]):
            m = j
    print(m+1)

Submission status: Accepted

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

c = []
for _ in range(m):
    c.append([int(i) for i in input().split()])

for i in range(n):
    ans = 0
    l = 10**16
    for j in range(m):
        tmp = abs(g[i][0] - c[j][0]) + abs(g[i][1] - c[j][1])
        
        if tmp < l:
            l = tmp
            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())))

ans = [0 for i in range(N)]
for i in range(N):
    d = 1000000000
    for j in range(M):
        if d > abs(ab[i][0]-cd[j][0]) + abs(ab[i][1]-cd[j][1]):
            ans[i] = j+1
            d = abs(ab[i][0]-cd[j][0]) + abs(ab[i][1]-cd[j][1])

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

Submission status: Accepted

Solution code:
from scipy.spatial.distance import cityblock

N,M = [int(i) for i in input().split()]
S = [[int(i) for i in input().split()] for _ in range(N)]
C = [[int(i) for i in input().split()] for _ in range(M)]
d = [0]*M

for i in range(N):
    for j in range(M):
        d[j] = cityblock(S[i],C[j])
    print(d.index(min(d))+1)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
s=[list(map(int,input().split())) for _ in range(n)]
p=[list(map(int,input().split())) for _ in range(m)]
for a,b in s:
    k=float('inf')
    f=0
    for i,(c,d) in enumerate(p,start=1):
        t=abs(a-c)+abs(b-d)
        if k>t:
            k=t
            f=i
    print(f)

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)]
for i in range(n):
    for j in range(m):
        ans[i].append(abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1]))
for i in range(n):
    print(ans[i].index(min(ans[i]))+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 ab in AB:
    a = ab[0]
    b = ab[1]

    mr = 10 ** 9
    cp = 1

    for i, cd in enumerate(CD, 1):
        c = cd[0]
        d = cd[1]

        l = abs(a-c) + abs(b-d)

        if l < mr:
            mr = l
            cp = i

    print(cp)

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()

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(AB)
#print(CD)

for i in range(n):
    dist_list = []
    for j in range(m):
        dist = abs(AB[i][0] - CD[j][0]) + abs(AB[i][1] - CD[j][1])
        dist_list.append(dist)
    #print(dist_list)
    print(dist_list.index(min(dist_list))+1)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
stud = []
poit = []
for i in range(n):
    a, b = map(int, input().split())
    stud.append([a, b])
for i in range(m):
    c, d = map(int, input().split())
    poit.append([c, d])
    
for a, b in stud:
    dist = float('inf')
    for i, info in enumerate(poit):
        c = info[0]
        d = info[1]
        mdist = abs(a-c) + abs(b-d)
        if dist > mdist:
            dist = mdist
            ans = i+1
    print(ans)
    # print(i, info)