Problem:


Score : 200 points

Problem Statement

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

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

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

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

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

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

Which checkpoint will each student go to?

Constraints

1 \leq N,M \leq 50

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

All input values are integers.

Input

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

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

Output

Print N lines.

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

Sample Input 1

2 2
2 0
0 0
-1 0
1 0

Sample Output 1

2
1

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

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

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

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

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

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

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

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

Sample Input 2

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

Sample Output 2

3
1
2

There can be multiple checkpoints at the same coordinates.

Sample Input 3

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

Sample Output 3

5
4
3
2
1



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


Sample output:
2
1

Submission status: Accepted

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

for i, (ai, bi) in enumerate(ab):
    ans = 0
    dist_min = 1000000007
    for j, (cj, dj) in enumerate(cd):
        dist_tmp = abs(ai - cj) + abs(bi - dj)
        if dist_min > dist_tmp:
            ans = j + 1
            dist_min = dist_tmp
    #
    print(ans)

Submission status: Accepted

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

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

cd = [tuple(map(int, input().split())) for j in range(M)]

ans = [0]*N

for i, x in enumerate(ab):
    a, b = x
    D = 10**9
    for j, y in enumerate(cd):
        c, d = y
        dis = abs(a-c) + abs(b-d)
        if dis < D:
            D = dis
            ans[i] = j + 1

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

ans = []

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

for k in ans:
    print(k)

Submission status: Accepted

Solution code:
import numpy as np
N, M = map(int, input().split())
a, b = np.array([input().split() for _ in range(N)], dtype=int).T
c, d = np.array([input().split() for _ in range(M)], dtype=int).T

dx = np.subtract.outer(a, c)
dy = np.subtract.outer(b, d)
dist = np.abs(dx) + np.abs(dy)
ans = np.argmin(dist, axis=1)+1
print(*ans, sep="\n")

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):
  minimum=1000000000
  ans=0
  for j in range(m):
    if abs(a[i]-c[j])+abs(b[i]-d[j])<minimum:
      minimum=abs(a[i]-c[j])+abs(b[i]-d[j])
      ans=j+1
  print(ans)

Submission status: Accepted

Solution code:
N, M = map(int,input().split())
st = [[] for _ in range(N)]
cp = [[] for _ in range(M)]
for i in range(N):
    a, b = map(int,input().split())
    st[i] = [a, b]
for j in range(M):
    c, d = map(int,input().split())
    cp[j] = [c, d]
for i in range(N):
    ne = 10**12
    p = 0
    for j in range(M):
        dis = abs(st[i][0]-cp[j][0])+abs(st[i][1]-cp[j][1])
        if dis < ne:
            p = j
            ne = dis
    print(p+1)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
students = [list(map(int,input().split())) + [float('inf'), -1] for _ in range(n)]
for i in range(m):
    x, y = map(int,input().split())
    for stu in students:
        dist = abs(stu[0]-x) + abs(stu[1]-y) 
        if dist < stu[2]: stu[2], stu[3] = dist, i+1
for stu in students: print(stu[3])

Submission status: Accepted

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

def distance(list1,list2):
    return abs(list1[0]-list2[0]) + abs(list1[1]-list2[1])

for i in range(n):
    student = s_list[i]
    distance_list = []
    for j,c in enumerate(c_list):
        dist = distance(student,c)
        distance_list.append(dist)
    print(distance_list.index(min(distance_list))+1)

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 a,b in p:
    l=[]
    for c,d in q:
        l.append(abs(a-c)+abs(b-d))
    print(l.index(min(l))+1)

Submission status: Accepted

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

ans = [] 
for i in range(n):
    mn = 10**9
    idx = 0
    for j in range(m):
        p = abs(stu[i][0] - chp[j][0]) + abs(stu[i][1] - chp[j][1])
        if p < mn:
            mn = p
            idx = j + 1
    print(idx)

Submission status: Accepted

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

ab = []
cd = []

A = 0
B = 1
C = 0
D = 1

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

for _ab in ab:
    dis = []
    for _cd in cd:
        dis.append(abs(_ab[A] - _cd[C]) + abs(_ab[B] - _cd[D]))
    print(dis.index(min(dis)) + 1)

Submission status: Accepted

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

manh=[]
for k in range(n):
    for l in range(m):
        x=abs(student[k][0]-point[l][0])
        y=abs(student[k][1]-point[l][1])
        manh.append([x+y])
    
    print(manh.index(min(manh))+1)
    manh=[]

Submission status: Accepted

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

def main():
    N, M = map(int, readline().rstrip().split())
    AB = [list(map(int, readline().rstrip().split())) for _ in range(N)]
    CD = [list(map(int, readline().rstrip().split())) for _ in range(M)]
    for a, b in AB:
        dist = 10**10
        ans = -1
        for i, (c, d) in enumerate(CD):
            if abs(a-c) + abs(b-d) < dist:
                dist = abs(a-c) + abs(b-d)
                ans = i + 1
        print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

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

    for i in range(N):
        a = AB[i][0]
        b = AB[i][1]
        d_min = INF
        index = 0
        for j, cd in enumerate(CD):
            c = cd[0]
            d = cd[1]
            d = abs(a-c) + abs(b-d)
            if d<d_min:
                d_min = d
                index = j+1
        print(index)



if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

  
for i in S:
  ans = 0
  D = 10**16
  for idx,j in enumerate(T):
    if D > abs(i[0]-j[0])+abs(i[1]-j[1]):
      D = abs(i[0]-j[0])+abs(i[1]-j[1])
      ans = idx + 1
  print(ans)

Submission status: Accepted

Solution code:
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 j in range(M):
    c[j], d[j] = map(int, input().split())
for i in range(N):
    minnum = float('inf')
    for j in range(M):
        if minnum > abs(a[i]-c[j]) + abs(b[i]-d[j]):
            minnum = abs(a[i]-c[j]) + abs(b[i]-d[j])
            ans = j+1
    print(ans)

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

Submission status: Accepted

Solution code:
import numpy as np
N, M = map(int, input().split())
s = np.array([[int(v) for v in input().split()] for _ in range(N)])
c = np.array([[int(v) for v in input().split()] for _ in range(M)])

for i in range(N):
    print(np.argmin(np.sum(np.abs(s[i] - c), axis=1)) + 1)

Submission status: Accepted

Solution code:
def resolve():
    N, M = list(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)]
    for ab in AB:
        dist = float("inf")
        point = None
        for i, cd in enumerate(CD):
            if dist > abs(ab[0]-cd[0])+abs(ab[1]-cd[1]):
                dist = abs(ab[0]-cd[0])+abs(ab[1]-cd[1])
                point = i+1
        print(point)


if '__main__' == __name__:
    resolve()

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 student in ab:
    minimum = 1e+9
    for i, check in enumerate(cd):
        distance = abs(student[0] - check[0]) + abs(student[1] - check[1])
        if minimum > distance:
            ans = i+1
            minimum = distance
    print(ans)

Submission status: Accepted

Solution code:
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt, ceil
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# 素数判定
def is_prime(n):
    if n <= 1:
        return False
    p = 2
    while True:
        if p ** 2 > n:
            break
        if n % p == 0:
            return False
        p += 1
    return True


# limit以下の素数を列挙
def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P

# 同じものを含む順列
def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        # set（集合）型で重複を削除、ソート
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret


# ここから書き始める
n, m = map(int, input().split())
a = [0 for i in range(n)]
b = [0 for i in range(n)]
c = [0 for i in range(m)]
d = [0 for i in range(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())
# print("a =", a)
# print("b =", b)
# print("c =", c)
# print("d =", d)
for i in range(n):
    x1, y1 = a[i], b[i]
    d1 = INF
    ans = 0
    for j in range(m):
        x2 = c[j]
        y2 = d[j]
        d2 = abs(x1 - x2) + abs(y1 - y2)
        # if i == 0:
            # print("d2 =", d2)
        if d1 > d2:
            ans = j + 1
            d1 = d2
    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):
    ans = 0
    ans_dis = float("inf")
    for j in range(M):
        distance = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
        if distance < ans_dis:
            ans = j + 1
            ans_dis = distance
    print(ans)

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

ANS = [[] for _ in range(n)]
for i, (a,b) in enumerate(AB,1):
    ans = 10**9
    for j, (c,d) in enumerate(CD,1):
        dst = abs(a-c) + abs(b-d)
        if dst < ans:
            ans = dst
            ANS[i-1] = j
for a in ANS:
    print(a)

Submission status: Accepted

Solution code:
import sys

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 = [0 for _ in range(n)]

for i in range(n):
    dis = sys.maxsize
    for j in range(m):
        abs_dis = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
        if dis > abs_dis:
            ans[i] = j + 1
            dis = abs_dis

for n in range(len(ans)):
    if n == len(ans) - 1:
        print(ans[n], end="")
    else:
        print(ans[n])

Submission status: Accepted

Solution code:
#ABC057-B
n,m = map(int,input().split())
students = [list(map(int,input().split())) for _ in range(n)]
points = [list(map(int,input().split())) for _ in range(m)]
def manhattan(s,points):
    lst = []
    for i in points:
        lst.append(abs(s[0] - i[0]) + abs(s[1] - i[1]))
    return lst.index(min(lst))+1

for i in students:
    print(manhattan(i,points))

Submission status: Accepted

Solution code:
def func(x1,y1,x2,y2):
    return abs(x1-x2)+abs(y1-y2)
n,m = map(int,input().split())
g = [list(map(int,input().split())) for _ in range(n)]
c = [list(map(int,input().split())) for _ in range(m)]
index = 0
for k in g:
    num = 10**9
    for i,d in enumerate(c):
        tmp = func(k[0],k[1],d[0],d[1])
        if tmp < num:
            num = tmp
            index = i
    print(index+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 x1,y1 in ab:
    tmp = float('inf')
    ans = None
    for num,xy2 in enumerate(cd):
        x2 = xy2[0]
        y2 = xy2[1]
        dist = abs(x1-x2)+abs(y1-y2)
        if dist < tmp:
            tmp = dist
            ans = num + 1
    print(ans)

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

for i in range(N):
  dmin=2*10**8
  cnum=0
  for j in range(M):
    d=abs(a[i][0]-c[j][0])+abs(a[i][1]-c[j][1])
    if d<dmin:
      dmin=d
      cnum=j
  ans.append(cnum+1)
print(*ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
n,m=mii()

arr =[]
for i in range(n):
    a,b=mii()
    arr.append([a,b])
mat = []
for i in range(m):
    c,d=mii()
    mat.append([c,d])
ans=[]
for i,j in arr:
    num = 10**100
    c1,c2=0,0
    cnt=0
    p=0
    for c,d in mat:
        cnt+=1
        if abs(i-c)+abs(j-d) <num:
            c1,c2=c,d
            num = abs(i-c)+abs(j-d)
            p=cnt
            
    ans.append(p)

print(*ans)

Submission status: Accepted

Solution code:
# 2020/04/26
# AtCoder Beginner Contest 057 - B

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

stds = list()
chkp = list()

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

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

# Calc
for i in range(n):
    mindist = 10**9
    ans = -1
    for j in range(m):
        dist = abs(chkp[j][0] - stds[i][0]) + abs(chkp[j][1] - stds[i][1])
        if dist < mindist:
            mindist = dist
            ans = j + 1

    # Output
    print(ans)

Submission status: Accepted

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

for i in range(N):
    dis=[]
    for k in range(M):
        dis.append(abs(stu[i][0]-che[k][0])+abs(stu[i][1]-che[k][1]))
    shortest=min(dis)
    print(dis.index(shortest)+1)

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

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

for a,b in ab:
    idx = 0
    for i in range(m):
        if dist(a,b,cd[i][0],cd[i][1]) < dist(a,b,cd[idx][0],cd[idx][1]):
            idx = i
    print(idx+1)

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):
    distance = abs(a[i] - c[0]) + abs(b[i] - d[0])
    check = 0
    for j in range(1,m):
        temp = abs(a[i] - c[j]) + abs(b[i] - d[j])
        if distance > temp:
            distance = temp 
            check = j
    print(check + 1)

Submission status: Accepted

Solution code:
def distance(a,b,c,d):
  return abs(a-c)+abs(b-d)

N,M=map(int, input().split())
Alist = []
Blist = []
for i in range(N):
  a,b=map(int, input().split())
  Alist.append(a)
  Blist.append(b)
Clist = []
Dlist = []
for i in range(M):
  c,d=map(int, input().split())
  Clist.append(c)
  Dlist.append(d)

for i in range(N):
  min_d = 10**10
  a = Alist[i]
  b = Blist[i]
  for k in range(M):
    c = Clist[k]
    d = Dlist[k]
    if min_d > distance(a,b,c,d):
      min_d = distance(a,b,c,d)
      kiroku = k
#    print(a,b,c,d,distance(a,b,c,d),min_d)
  print(kiroku+1)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
stu = [list(map(int, input().split())) for _ in range(n)]
che = [list(map(int, input().split())) for _ in range(m)]
for i in range(n):
    dmin = abs(stu[i][0] - che[0][0]) + abs(stu[i][1] - che[0][1])
    ans = 1
    for j in range(1, m):
        d = abs(stu[i][0] - che[j][0]) + abs(stu[i][1] - che[j][1])
        if d < dmin:
            ans = j + 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):
    nearest = 10**9
    idx = None
    for j in range(m):
        a, b = ab[i]
        c, d = cd[j]
        if abs(a-c)+abs(b-d) < nearest:
            nearest = abs(a-c)+abs(b-d)
            idx = j+1
    ans.append(idx)
for i in range(len(ans)):
    print(ans[i])

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)]
min = 5e+8
c = 0

for i in range(n):
    for j in range(m):
        d = abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
        if d<min:
            min=d
            c = j+1
    min = 5e+8
    print(c)

Submission status: Accepted

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

a, b = [0] * n, [0] * n
c, d = [0] * m, [0] * m
for i in range(n):
    a[i], b[i] = map(int, input().split())
for i in range(m):
    c[i], d[i] = map(int, input().split())
for i in range(n):
    ans = 0
    min = 10 ** 20
    for j in range(m):
        dis = abs(a[i] - c[j]) + abs(b[i] - d[j])
        if min > dis:
            min = dis
            ans = j + 1
    print(ans)

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 i in range(m):
    c[i], d[i] = map(int, input().split())

import numpy as np
for i in range(n):
    min_distance = np.inf
    checkpoint = 0
    for j in range(m):
        distance = abs(a[i] - c[j]) + abs(b[i] - d[j])
        if distance == min_distance:
            checkpoint = min(checkpoint, j)
        elif distance < min_distance:
            checkpoint = j
            min_distance = distance
    print(checkpoint + 1)

Submission status: Accepted

Solution code:
n, m = map(int,input().split())
ab_l = []
for _ in range(n):
    ab_l.append(list(map(int,input().split())))
cd_l = []
for _ in range(m):
    cd_l.append(list(map(int,input().split())))
ans_l = [0]*n

for i in range(n):
    distance_min = float('inf')
    for j in range(m):
        distance = abs(ab_l[i][0]-cd_l[j][0]) + abs(ab_l[i][1]-cd_l[j][1])
        if distance < distance_min:
            distance_min = distance
            ans_l[i] = j+1

for val in ans_l:
    print(val)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
# input = sys.stdin.readline
from itertools import accumulate

def readlines(n):
    for _ in range(n):
        x, y = map(int, input().split())
        yield x, y

def main():
    n, m = map(int, input().split())
    
    stu = list(readlines(n))
    check = list(readlines(m))
    
    def distances(a, b):
        for i, cd in enumerate(check, 1):
            c, d = cd
            yield abs(a - c) + abs(b - d), i

    for a, b in stu:
        yield str(min(distances(a, b))[1])



print("\n".join(main()))

Submission status: Accepted

Solution code:
def resolve():
	n, m = map(int, input().split())
	a, b = [-1]*n, [-1]*n
	c, d = [-1]*m, [-1]*m
	ans = []
	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):
		low_i = -1
		low_v = float('inf')
		for j in range(m):
			v = abs(a[i] - c[j]) + abs(b[i] - d[j])
			if v < low_v:
				low_v = v
				low_i = j
		ans.append(low_i+1)
	for i in ans:
		print(i)
resolve()

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):
    tmp = []
    for j in range(M):
        tmp.append(abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1]))
    print(tmp.index(min(tmp))+1)

Submission status: Accepted

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

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

for i in range(n):
    ans = 10000000000000
    for j in range(m):
        x = abs(a[i][0]-b[j][0]) + abs(a[i][1]-b[j][1])
        if x < ans:
            ans = x
            y = j
    print(y+1)

Submission status: Accepted

Solution code:
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# import re
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

# slist = "abcdefghijklmnopqrstuvwxyz"
N,M = map(int,input().split())
times = N
AB = []
for _ in range(times):
    AB.append(list(map(int,input().split()))) # 行列の場合
times = M
CD = []
for _ in range(times):
    CD.append(list(map(int,input().split()))) # 行列の場合

AB = np.array(AB)
CD = np.array(CD)
for ab in AB:
    arr = np.sum(abs(ab-CD),axis=1)
    # print(arr)
    print(np.argmin(arr)+1)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))

Submission status: Accepted

Solution code:
def myAnswer(N:int,M:int,A:list,B:list,C:list,D:list) ->int:
   for a,b in zip(A,B):
      ans = 10**10
      no = 0
      for n in range(M):
         c = C[n]
         d = D[n]
         distance = abs(a - c) + abs(b - d)
         if(ans > distance):
            ans = distance
            no = n+1
      print(no)


def modelAnswer():
   return
def main():
   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)
   myAnswer(N,M,A[:],B[:],C[:],D[:])

if __name__ == '__main__':
   main()

Submission status: Accepted

Solution code:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n,m = iim()

pe = []
ch = []
for i in range(n):
    pe.append(iil())

for j in range(m):
    ch.append(iil())

for k in pe:
    dist = 1000000000
    point = 0
    for ind,l in enumerate(ch):
        if abs(k[0]-l[0])+abs(k[1]-l[1]) < dist:
            dist = abs(k[0]-l[0])+abs(k[1]-l[1])
            point = ind+1
    print(point)

Submission status: Accepted

Solution code:
def resolve():
    '''
    code here
    '''
    N, M = [int(item) for item in input().split()]
    students = [[int(item) for item in input().split()] for _ in range(N)]
    cps = [[int(item) for item in input().split()] for _ in range(M)]

    for i in range(N):
        min_dist = 10**9
        min_dist_index = 0
        for j in range(M):
            x_dist = abs(students[i][0] - cps[j][0])
            y_dist = abs(students[i][1] - cps[j][1])
            man_dist = x_dist + y_dist

            if min_dist > man_dist:
                min_dist = man_dist
                min_dist_index = j

        print(min_dist_index+1)

if __name__ == "__main__":
    resolve()

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):
    ans = -1
    MIN = float('inf')
    for j in range(M):
        a, b = students[i]
        c, d = points[j]
        if MIN > abs(a-c) + abs(b-d):
            MIN = abs(a-c) + abs(b-d)
            ans = j + 1
    print(ans)