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())
A = [list(map(int,input().split())) for _ in range(N)]
C = [list(map(int,input().split())) for _ in range(M)]
for i in range(N):
    check = 0
    point = abs(A[i][0]-C[0][0])+abs(A[i][1]-C[0][1])
    change = point
    for j in range(1,M):
        point = min(point,abs(A[i][0]-C[j][0])+abs(A[i][1]-C[j][1]))
        if point != change:
            check = j
            change = point
    print(check+1)

Submission status: Accepted

Solution code:
N,M = list(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:
    MIN = float('inf')
    MIN_I = 0
    for i,cd in enumerate(CD):
        distance = abs(ab[0]-cd[0])+abs(ab[1]-cd[1])
        if MIN > distance:
            MIN = distance
            MIN_I = i
    print(MIN_I+1)

Submission status: Accepted

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

# map(int, input().rstrip().split())

def VI(N, init=0):
  return [init for _ in range(N)]
def VVI(N, M, init=0):
  return [[init for _ in range(M)] for _ in range(N)]

def VD(N, init=0.0):
  return [init for _ in range(N)]
def VVD(N, M, init=0.0):
  return [[init for _ in range(M)] for _ in range(N)]

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

A = VI(N)
B = VI(N)
C = VI(M)
D = VI(M)

for i in range(N):
  A[i], B[i] = map(int, input().rstrip().split())

for i in range(M):
  C[i], D[i] = map(int, input().rstrip().split())

INF = int(1e18)

ans = VI(N)
for i in range(N):
  a = A[i]
  b = B[i]
  ddist = INF
  for j in range(M):
    c = C[j]
    d = D[j]
    dist = abs(a-c)+abs(b-d)
    if (dist < ddist):
      ans[i] = j+1
      ddist = dist

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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, m = map(int, readline().split())
ab = [list(map(int, readline().split())) for _ in range(n)]
cd = [list(map(int, readline().split())) for _ in range(m)]

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

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 i in range(M):
    C[i], D[i] = map(int, input().split())
    
def Main(N, M, A, B, C, D):
    ans = []
    for i in range(N):
        min_dist = 10**9
        min_ind = 1
        for j in range(M):
            dist = abs(A[i]-C[j])+abs(B[i]-D[j])
            if min_dist > dist:
                min_dist = dist
                min_ind = j+1
        ans.append(min_ind)
    return ans
    
res = Main(N, M, A, B, C, D)
for e in res:
    print(e)

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 a,b in ab:
    tmp = []
    for c,d in cd:
        tmp.append(abs(a-c)+abs(b-d))
    
    print(tmp.index(min(tmp))+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:
    l = 10**10
    index = 0
    for i, (x2, y2) in enumerate(cd):
        if l > abs(x1-x2)+abs(y1-y2):
            l = abs(x1-x2)+abs(y1-y2)
            index = i + 1
    print(index)

Submission status: Accepted

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

students = [list(map(int, input().split())) for _ in range(N)]
t_points = [list(map(int, input().split())) for _ in range(M)]

ans_list = []

for s_point in students:
    # 各学生に対して、マンハッタン距離を計算
    min_mhd = 9999999999
    p_index = 0
    for index, t_point in enumerate(t_points):
        temp_mhd = abs(s_point[0] - t_point[0]) + abs(s_point[1] - t_point[1])
        if min_mhd > temp_mhd:
            min_mhd = temp_mhd
            p_index = index
    ans_list.append(p_index+1)

for ans in ans_list:
    print(ans)

Submission status: Accepted

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

def dist(p, q):
    xp, yp = p
    xq, yq = q
    return abs(xp - xq) + abs(yp - yq)

for i in range(N):
    d = 10 ** 18
    p = -1
    for j in range(M):
        if dist(student[i], point[j]) < d:
            d = dist(student[i], point[j])
            p = j
    print(p + 1)

Submission status: Accepted

Solution code:
n, m = list(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):
    l_min = float('inf')
    ans = 0
    for j in range(m):
        l = abs(S[i][0] - C[j][0]) + abs(S[i][1] - C[j][1])
        if l < l_min:
            l_min = l
            ans = j + 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 x1, y1 in ab:
    l = 10**10
    index = 0
    for i, (x2, y2) in enumerate(cd):
        if l > abs(x1-x2)+abs(y1-y2):
            l = abs(x1-x2)+abs(y1-y2)
            index = i + 1
    print(index)

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):
  k=float('inf')
  for j in range(m):
    l=abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
    if l<k:
      k=l
      out=j+1
  print(out)

Submission status: Accepted

Solution code:
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 i in range(n):
  a, b = ab[i]
  
  dist = 1e+15
  ans = 0
  for j in range(m):
    c, d = cd[j]    

    if dist > abs(a - c) + abs(b - d):
      ans = j
      dist = abs(a - c) + abs(b - d)
  
  print(ans+1)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def Yes(): print("Yes"); return
def No(): print("No"); return

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
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

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def Base_10_to_n(X, n):
  if X//n:
    return Base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def Base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

N,M = inputIL()
n = inputILL(N)
m = inputILL(M)

ans = []
for c,d in n:
  MIN = (INF,INF)
  count = 0
  for a,b in m:
    count += 1
    dis = abs(a-c)+abs(d-b)
    if dis < MIN[0]:
      MIN = (dis,count)
  ans.append(str(MIN[1]))

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

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
student = [[0]*2 for _ in range(n)]
check = [[0]*2 for _ in range(m)]
for i in range(n):
    student[i][0],student[i][1] = map(int,input().split())
for i in range(m):
    check[i][0],check[i][1] = map(int, input().split())

INF = 10**9
for i in range(n):
    zantei = INF
    ans = 1
    for j in range(m):
        dum = abs(student[i][0] - check[j][0]) + abs(student[i][1] - check[j][1])
        if dum < zantei:
            ans = j+1
            zantei = dum
    print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N, M = map(int, input().split())
students = []
cps = []
for _ in range(N):
    students.append(list(map(int, input().split())))
for _ in range(M):
    cps.append(list(map(int, input().split())))

for std in students:
    cp_idx = 0
    dist = abs(std[0] - cps[0][0]) + abs(std[1] - cps[0][1])
    for i in range(1, M):
        new_dist = abs(std[0] - cps[i][0]) + abs(std[1] - cps[i][1])
        if new_dist < dist:
            cp_idx = i
            dist = new_dist
    print(cp_idx + 1)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    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 x,y in a:
        tmp=INF
        for i,(xx,yy) in enumerate(b):
            if abs(xx-x)+abs(yy-y)<tmp:
                tmp=abs(xx-x)+abs(yy-y)
                ans=i+1
        print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

for i in range(n):
    d = abs(ln[i][0] - lm[0][0]) + abs(ln[i][1] - lm[0][1])
    ans = 1
    for j in range(1, m):
        if d > abs(ln[i][0] - lm[j][0]) + abs(ln[i][1] - lm[j][1]):
            d = abs(ln[i][0] - lm[j][0]) + abs(ln[i][1] - lm[j][1])
            ans = j+1
    print(ans)

Submission status: Accepted

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

def dist(a, b):
    return abs(a[0] - b[0]) + abs(a[1] - b[1])

for i in range(n):
    minx = 10**9
    goto = 0
    for j in range(m):
        tmp = dist(student[i], chkpoint[j])
        if minx > tmp:
            minx = tmp
            goto = j+1
    print(goto)

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

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)

res_min = [10**9]*N #各人の最小距離
res = [0]*N #出力する答え

#全探索
for i in range(N):
    for j in range(M):
        temp = abs(a[i]-c[j]) + abs(b[i]-d[j])
        if res_min[i] > temp:
            res_min[i] = temp
            res[i] = j+1
for i in range(N):
    print(res[i])

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
stu=[]
poi=[]
for i in range(n):
    a,b=map(int,input().split())
    stu.append([a,b])
for i in range(m):
    a,b=map(int,input().split())
    poi.append([a,b])
for i in stu:
    ans=float("inf")
    ans_index=0
    ans_lis=[abs(i[0]-j[0])+abs(i[1]-j[1]) for j in poi]
    print(ans_lis.index(min(ans_lis))+1)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
stu_loc=[list(map(int,input().split())) for i in range (N)]
ch_loc=[list(map(int,input().split())) for i in range (M)]
for i in range(N):
    dist = 10**9
    num = 100
    for j in range(M):
        #print(abs(stu_loc[i][0]-ch_loc[j][0])+abs(stu_loc[i][1]-ch_loc[j][1]))
        if dist>abs(stu_loc[i][0]-ch_loc[j][0])+abs(stu_loc[i][1]-ch_loc[j][1]):
            dist=abs(stu_loc[i][0]-ch_loc[j][0])+abs(stu_loc[i][1]-ch_loc[j][1])
            num=j
    print(num+1)

Submission status: Accepted

Solution code:
import numpy as np,sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N,M = LI()
ab = np.array([LI() for _ in range(N)])
cd = np.array([LI() for _ in range(M)])
for x in ab:
    print(np.abs(cd-x).sum(axis=1).argmin()+1)

Submission status: Accepted

Solution code:
N,M=list(map(int,input().split()))
l=[]
for i in range(N):
   l.append(list(map(int,input().split())))
point=[]
for i in range(M):
   point.append(list(map(int,input().split())))
for i in range(N):
   X1,Y1=l[i]
   ans=float("INF")
   f_ans=0
   for j in range(M):
      X2,Y2=point[j]
      distance=abs(X1-X2)+abs(Y1-Y2)
      if ans > distance:
         ans=distance
         f_ans=j
   print(f_ans+1)

Submission status: Accepted

Solution code:
import numpy as np,sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N,M = LI()
ab = np.array([LI() for _ in range(N)])
cd = np.array([LI() for _ in range(M)])
for x in ab:
    print(abs(cd-x).sum(axis=1).argmin()+1)

Submission status: Accepted

Solution code:
import numpy as np,sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N,M = LI()
ab = np.array([LI() for _ in range(N)])
cd = np.array([LI() for _ in range(M)])
for x in ab:
    print(np.argmin(np.sum(np.abs(cd-x),axis=1))+1)

Submission status: Accepted

Solution code:
import numpy as np,sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N,M = LI()
ab = np.array([LI() for _ in range(N)],dtype=int)
cd = np.array([LI() for _ in range(M)],dtype=int)
for x in ab:
    vector = np.sum(np.abs(cd-x),axis=1).tolist()
    print(vector.index(min(vector))+1)

Submission status: Accepted

Solution code:
import numpy as np,sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N,M = LI()
ab = np.array([LI() for _ in range(N)])
cd = np.array([LI() for _ in range(M)])
for x in ab:
    vector = np.sum(np.abs(cd-x),axis=1).tolist()
    print(vector.index(min(vector))+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)]
dist = 10**9


for i, j in ab:
    for o, (p, q) in enumerate(cd):
        dist1 = abs(i - p) + abs(j - q)
        if dist1 < dist:
            dist = dist1
            ch = o + 1
    print(ch)
    dist = 10**9

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)]
dist = 10**9


for i, j in ab:
    for k in range(m):
        dist1 = abs(i - cd[k][0]) + abs(j - cd[k][1])
        if dist1 < dist:
            dist = dist1
            ch = k + 1
    print(ch)
    dist = 10**9

Submission status: Accepted

Solution code:
import numpy as np

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

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

ab = np.array(ab)
dist = np.full([N, M], np.inf)

for m in range(M):
    tmp = np.array(list(map(int, input().split())))
    for n in range(N):
        dist[n, m] = np.abs(ab[n] - tmp).sum()

dist = dist.astype("int")

for d in dist:
    print(d.argmin()+1)

Submission status: Accepted

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

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

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

for i in range(n):
    distance=10**9
    for j in range(m):
        if distance!=min(distance,man(a[i],b[i],c[j],d[j])):
            point=j+1
            distance=min(distance,man(a[i],b[i],c[j],d[j]))

    print(point)

Submission status: Accepted

Solution code:
# ABC057
# B
# Checkpoints

n, m = map(int, input().split())
ax = [None]*n
by = [None]*n
cx = [None]*m
dy = [None]*m

d_list = [[None]*m for i in range(n)]

for i in range(n):
    ax[i],by[i] = map(int, input().split())
for i in range(m):
    cx[i],dy[i] = map(int, input().split())

for i in range(n):
    for j in range(m):
        d_list[i][j] = abs(ax[i]-cx[j]) + abs(by[i]-dy[j])
        
for i in range(n):
    print(d_list[i].index(min(d_list[i]))+1)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
a_b_tuple = [tuple(map(int, input().split())) for _ in range(N)]
c_d_tuple = [tuple(map(int, input().split())) for _ in range(M)]
for a_b in a_b_tuple:
    flg = 0
    tmp = 20000000000
    for i, c_d in enumerate(c_d_tuple):
        if tmp > abs(a_b[0] - c_d[0]) + abs(a_b[1] - c_d[1]):
            tmp = abs(a_b[0] - c_d[0]) + abs(a_b[1] - c_d[1])
            flg = i
    print(flg + 1)

Submission status: Accepted

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

def d(s,p):
  return abs(s[0]-p[0]) + abs(s[1] - p[1])

for std in stds:
  ans = (-1, float('inf'))
  for i, pnt in enumerate(points):
    dst = d(std,pnt)
    if dst < ans[1]:
      ans = (i, dst)
  print(ans[0]+1)

Submission status: Accepted

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

ans_list = []
for i in range(N):
    a, b = students[i]
    min_d = float("inf")
    ans = -1
    for j in range(M):
        x, y = check[j]
        d = abs(a-x) + abs(b-y)
        if d < min_d:
            min_d = d
            ans = j
    ans_list.append(ans)
    
for i in range(N):
    print(ans_list[i]+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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 a, b in ab:
    near = 10**32
    for i, n in enumerate(cd):
        tmp = abs(a-n[0])+abs(b-n[1])
        if near == tmp:
            continue
        near = min(near, tmp)
        if near == tmp:
            ans = i + 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())

x = [0]*M
y = [0]*M

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

for i in range(N):
    dis = 10000000000000000
    res = 0
    for j in range(M):
        if dis > (abs(a[i]-x[j])+abs(b[i]-y[j])):
            dis = min(dis,(abs(a[i]-x[j])+abs(b[i]-y[j])))
            res = j

    print(res+1)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Thu May 14 16:46:38 2020

@author: shinba
"""

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

A = []
B = []

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

C = []
D = []

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

for i in range(n):
    ans = float("inf")
    for j in range(m):
        if ans > abs(A[i]-C[j])+abs(B[i]-D[j]):
            ans = abs(A[i]-C[j])+abs(B[i]-D[j])
            num = j+1
    else:
        print(num)

Submission status: Accepted

Solution code:

n,m =map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
dxy = [list(map(int, input().split())) for _ in range(m)]

for i in range(n):
    dt = 10**9
    for j in range(m):
        dx = abs(ab[i][0]-dxy[j][0])
        dy = abs(ab[i][1]-dxy[j][1])
        if dt > dx+dy:
            ij = j
            dt = dx+dy
    print(ij+1)

Submission status: Accepted

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

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

for a, b in start_pos:
    min_dist = 1_000_000_000
    min_dist_pos = 0
    for i, pos in enumerate(check_point):
        c, d = pos
        tmp = abs(a - c) + abs(b - d)
        if tmp < min_dist:
            min_dist = tmp
            min_dist_pos = i + 1

    print(min_dist_pos)

Submission status: Accepted

Solution code:
def main():
    n, m = map(int, input().split())
    ABs = [list(map(int, input().split())) for _ in range(n)]
    CDs = [list(map(int, input().split())) for _ in range(m)]

    for AB in ABs:
        thresh = float('inf')
        for i, CD in enumerate(CDs, start=1):
            thresh_temp = abs(AB[0]-CD[0])+abs(AB[1]-CD[1])
            if thresh == thresh_temp:
                continue
            if thresh_temp < thresh:
                ans = i
                thresh = thresh_temp
        print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#print#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
from fractions import gcd
import math
def resolve():
    N,M=pin()
    students=[tupin() for i in range(N)]
    checkpoints=[tupin() for j in range(M)]
    for stu in range(N):
        temp=10**10
        ind=0
        for pt in range(M):
            dis=abs(students[stu][0]-checkpoints[pt][0])\
            +abs(students[stu][1]-checkpoints[pt][1])
            #print(dis)
            if dis<temp:
                temp=dis
                ind=pt+1
        print(ind)
            
            
#%%submit!      
resolve()

Submission status: Accepted

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

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


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

for i in range(n):
  d=1000000000
  ans=0
  for j in range(m):
    if d>dist(ab[i],cd[j]):
      ans=j+1
      d=dist(ab[i],cd[j])
  print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N, M = map(int, input().split())
A, B = np.array(tuple(tuple(map(int, input().split())) for _ in range(N)), dtype=np.int64).T
C, D = np.array(tuple(tuple(map(int, input().split())) for _ in range(M)), dtype=np.int64).T
print(*((np.abs(np.subtract.outer(A, C)) + np.abs(np.subtract.outer(B, D))).argmin(axis=1) + 1), sep="\n")

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in [0]*n]
cd = [list(map(int, input().split())) for _ in [0]*m]
for a, b in ab:
    t = 1001001001
    ti = 0
    for i, (c, d) in enumerate(cd):
        e = abs(a-c)+abs(b-d)
        if t > e:
            t = e
            ti = i+1
    print(ti)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
stu_list = [list(map(int,input().split())) for nesya in range(n)]
che_list = [list(map(int,input().split())) for mootsu in range(m)]
for stu in stu_list:
  x = stu[0]
  y = stu[1]
  poge = 10**9
  hoge = 0
  i = 0
  for che in che_list:
    hoge += 1
    a = che[0]
    b = che[1]
    l = abs(x-a)+abs(y-b)
    if poge > l:
      poge = l
      i = hoge
  print(i)

Submission status: Accepted

Solution code:
import sys

N, M = map(int, input().split())
AB = [list(map(int, sys.stdin.readline().rsplit())) for _ in range(N)]
CD = [list(map(int, sys.stdin.readline().rsplit())) for _ in range(M)]

for a, b in AB:
    tmp_d = 10 ** 9
    for i in range(M):
        d = abs(a - CD[i][0]) + abs(b - CD[i][1])
        if d < tmp_d:
            tmp_d = d
            tmp_i = i + 1
    print(tmp_i)

Submission status: Accepted

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

for i in range(n):
    distance = []
    minDistance = 10 ** 16
    checkPoint = 1
    for j in range(m):
        distance.append(abs(a[i] - c[j]) + abs(b[i] - d[j]))
        if minDistance > distance[j]:
            minDistance = distance[j]
            checkPoint = j + 1
    print(checkPoint)

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline

def d(a, x):
    return abs(a[0] - x[0]) + abs(a[1] - x[1])

def main():
    N, M = map(int, readline().split())
    people = []
    for _ in range(N):
        people.append(tuple(map(int, readline().split())))
    check = []
    for _ in range(M):
        check.append(tuple(map(int, readline().split())))
    
    for i in range(N):
        tmp = float('inf')
        jtmp = 0
        for j in range(M):
            dtmp = d(people[i], check[j])
            if dtmp < tmp:
                tmp = dtmp
                jtmp = j
        print(jtmp+1)
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
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)]

def distance(i,j):
    return abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
ans = []
for i in range(n):
    mn = 10**18
    s = 0
    for j in range(m):
        if mn > distance(i,j):
            s = j
            mn = distance(i,j)
    ans.append(s)

for i in range(n):
    print(ans[i]+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)]

for i in range(N):
  mind = 10**9
  ans = 0
  for j in range(M):
    MD = abs(C[j][0] - S[i][0]) + abs(C[j][1] - S[i][1])
    if MD < mind:
      mind = MD
      ans = j+1
  print(ans)