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

student = [None]*n
for i in range(n):
  student[i] = tuple(map(int, input().split()))

point = [None]*m
for i in range(m):
  point[i] = tuple(map(int, input().split()))

for i in range(n):
  dist = pow(10, 9)
  ans = 0
  x, y = student[i]
  for j in range(m):
    sub = abs(point[j][0]-x) + abs(point[j][1]-y)
    if dist > sub:
      dist = sub
      ans = j+1
  print(ans)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for p in range(n)]
cd = [list(map(int, input().split())) for q in range(m)]
for i in range(n):
    x = 10**10
    ans = 0
    for j in range(m):
        if abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1]) < x:
            ans = j+1
            x = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
    print(ans)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
stu = []
che = []
kyori = []
ans = []
for _ in range(n):
  stu.append(list(map(int,input().split())))
for _ in range(m):
  che.append(list(map(int,input().split())))
for x in range(n):
  for y in range(m):
    kyori.append(abs(stu[x][0]-che[y][0])+abs(stu[x][1]-che[y][1]))
  z = min(kyori)
  ans.append(kyori.index(z)+1)
  kyori = []
for i in range(len(ans)):
  print(ans[i])

Submission status: Accepted

Solution code:
n, m = map(int,input().split())
s_x_plus_y = []
s_x_minus_y = []
p_x_plus_y = []
p_x_minus_y = []

for student in range(n):
    x, y = map(int,input().split())
    s_x_plus_y.append(x + y)
    s_x_minus_y.append(x - y)

for i in range(m):
    x, y = map(int,input().split())
    p_x_plus_y.append(x + y)
    p_x_minus_y.append(x - y)


for i in range(n):
    p_dist = []
    for j in range(m):
        p1 = abs(s_x_plus_y[i] - p_x_plus_y[j])
        p2 = abs(s_x_minus_y[i] - p_x_minus_y[j])
        d = max(p1, p2)
        p_dist.append(d)
    print(p_dist.index(min(p_dist))+1)

Submission status: Accepted

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

for i in range(n):
  min_dist = 10**18
  idx = 0
  for j in range(m):
    dist = abs(P[i][0]-C[j][0]) + abs(P[i][1]-C[j][1])
    if min_dist > dist:
      idx = j + 1
      min_dist = dist
  print(idx)

Submission status: Accepted

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

for i in range(n):
  d = 10**18
  t = 0
  for j in range(m):
    dist = abs(P[i][0]-C[j][0]) + abs(P[i][1]-C[j][1])
    if d > dist:
      t = j
      d = dist
  print(t+1)

Submission status: Accepted

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

for i in range(N):
  dist = float("inf")
  ans = 0
  a,b = ab[i][0],ab[i][1]
  
  for j in range(M)[::-1]:
    c,d = cd[j][0],cd[j][1]
    if abs(a-c) + abs(b-d) <= dist:
      dist = abs(a-c) + abs(b-d)
      ans = j + 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 i in range(m):
    c[i],d[i]=map(int,input().split())

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
X = []
for i in range(N):
    x = list(map(int, input().split()))
    X.append(x)
Y = []
for i in range(M):
    y = list(map(int, input().split()))
    Y.append(y)


for i in X:
    len = []
    for j in Y:
        len.append(abs(i[0]-j[0])+abs(i[1]-j[1]))
    print(len.index(min(len))+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)]

def distance(x,y,i,j):
    return abs(x-i) + abs(y-j)

for a,b in ab:
    # 各チェックポイントとの距離
    dists = [distance(a, b, c, d) for c,d in cd]
    print(dists.index(min(dists)) + 1)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
cd = [list(map(int, input().split())) for _ in range(m)]
for i in range(n):
    num = 0
    ans = float('inf')
    for j in range(m):
        man = abs(ab[i][0]-cd[j][0]) + abs(ab[i][1] - cd[j][1])
        if man < ans :
            ans = man
            num = j
    print(num+1)

Submission status: Accepted

Solution code:
N,M = [int(c) for c in input().split()]
ab = [list(map(int,input().split())) for c in range(N)]
cd = [list(map(int,input().split())) for c in range(M)]
for i in range(N):
    mi = 10**9
    for j in range(M):
        tmp = abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
        if mi > tmp:
            mi = tmp
            ans = j+1
    print(ans)

Submission status: Accepted

Solution code:
N,M = [int(c) for c in input().split()]
ab = [list(map(int,input().split())) for c in range(N)]
cd = [list(map(int,input().split())) for c in range(M)]
for i in range(N):
    mi = 2*10**9
    for j in range(M):
        tmp = abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
        if mi > tmp:
            mi = tmp
            ans = j+1
    print(ans)

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):
    shortest = 4*10**8 + 5
    for j in range(m):
        distance = abs(a[i][0] - b[j][0]) + abs(a[i][1] - b[j][1])
        if distance < shortest:
            idx = j
            shortest = distance
    print(idx + 1)

Submission status: Accepted

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

for i in range(N):
    k=0
    d=abs(ab[i][0]-cd[0][0])+abs(ab[i][1]-cd[0][1])
    for j in range(1,M):
        if abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])<d:
            k=j
            d=abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
    print(k+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 = M
  d = abs(A[i][0] - B[M-1][0]) + abs(A[i][1] - B[M-1][1])
  for j in range(M-2, -1, -1):
    dis = abs(A[i][0] - B[j][0]) + abs(A[i][1] - B[j][1])
    if d >= dis:
      d = dis
      ans = j + 1
  print(ans)

Submission status: Accepted

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

targets = [list(map(int, input().split())) for i in range(m)]
x = 0
snumber = [(0, x)] * n
  
def md(s, t):
  d = abs(s[0] - t[0]) + abs(s[1] - t[1])
  return d

for i in range(n):
  x = 4 * 10 ** 8
  for j in range(m):    
    if x > md(students[i], targets[j]):
      x = md(students[i], targets[j])
      snumber[i] = (j+1, md(students[i], targets[j]))
      
for i in range(n):      
  print(snumber[i][0])

Submission status: Accepted

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

for a in al:
    ans = 1001001001
    no = 0
    for i in range(m):
        dis = abs(a[0]-cl[i][0])+abs(a[1]-cl[i][1])
        if dis < ans:
            ans = dis
            no = i
    print(no+1)

Submission status: Accepted

Solution code:
n,m= map(int, input().split())
ab=[]
cd=[]
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 a,b in ab:
  cpt=-1
  mind=10**9
  for j in range(len(cd)):
    c,d=cd[j]
    d=abs(a-c)+abs(b-d)
    if d<mind:
      cpt=j+1
      mind=min(mind,d)
  print(cpt)

Submission status: Accepted

Solution code:
import itertools
url = "https://atcoder.jp//contests/abc057/tasks/abc057_a"

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


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 i in range(n):
    c = float("inf")
    e = 0
    g = 0
    for j in range(m):
        d = abs(a[i][0]-b[j][0])+abs(a[i][1]-b[j][1])
        g+=1
        if d <c:
            c,e=d,g
    print(e)

Submission status: Accepted

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

    for ab in ab_list:
        a = ab[0]
        b = ab[1]
        min_diff = 10 ** 9
        ans = 0
        for i in range(m):
            c = cd_list[i][0]
            d = cd_list[i][1]
            diff = abs(a - c) + abs(b - d)
            if diff < min_diff:
                min_diff = diff
                ans = i + 1
        print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20
MOD = 10**9+7

def mint():
    return map(int,input().split())
def lint():
    return map(int,input().split())
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)

N,M = mint()
student = [0]*N
point = [0]*M
for i in range(N):
    x,y = mint()
    student[i] = (x,y)
for j in range(M):
    x,y = mint()
    point[j] = (x,y)
    
ans = [0]*N
for i in range(N):
    x1,y1 = student[i]
    tmp = INF
    k = 0
    for j in range(M):
        x2,y2 = point[j]
        if abs(x1-x2)+abs(y1-y2)<tmp:
            tmp = abs(x1-x2)+abs(y1-y2)
            k = j+1
    ans[i] = str(k)

lprint(ans)

Submission status: Accepted

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

a_lis=[list(map(int,input().split())) for i in range(n)]
c_lis=[list(map(int,input().split())) for i in range(m)]

for i in range(n):
  num=0
  ans=10**10
  for j in reversed(range(m)):
    a=a_lis[i]
    c=c_lis[j]
    num=abs(a[0]-c[0])+abs(a[1]-c[1])
    ans=min(ans,num)
    if num==ans:
      cnt=j+1
  print(cnt)

Submission status: Accepted

Solution code:
n,m=map(int,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)]

for a,b in ab:
  ans=list()
  for c,d in cd:
    ans.append(abs(a-c)+abs(b-d))
  print(ans.index(min(ans))+1)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
ab = tuple(tuple(a for a in map(int, input().split())) for _ in range(N))
cd = tuple(tuple(a for a in map(int, input().split())) for _ in range(M))
for i in range(N):
	ckp = 1
	dist_min = 10**9
	for j in range(M):
		dist = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
		if dist < dist_min:
			dist_min = dist
			ckp = j + 1
	print(ckp)

Submission status: Accepted

Solution code:
n,m=map(int,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)]

for a,b in ab:
  ans=list()
  for c,d in cd:
    ans.append(abs(a-c)+abs(b-d))
  print(ans.index(min(ans))+1)

Submission status: Accepted

Solution code:
# B - Checkpoints
def main():
    n, m = map(int, input().split())
    a_b = [input().split() for i in range(n)]
    c_d = [input().split() for i in range(m)]

    for i in range(n):
        temp = []
        for j in range(m):
            temp.append(abs(int(a_b[i][0])-int(c_d[j][0]))+abs(int(a_b[i][1])-int(c_d[j][1])))
        else:
            print(temp.index(min(temp))+1)


        
if __name__ == '__main__':
    main()

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

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
st = []
pt = []
ch = []
for i in range(n):
  st.append(list(map(int, input().split())))
for i in range(m):
  pt.append(list(map(int, input().split())))
for j in st:
  for k in pt:
    d = abs(j[0]-k[0]) + abs(j[1]-k[1])
    ch.append(d)
  print(ch.index(min(ch))+1)
  ch = []

Submission status: Accepted

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

for i in range(n):
    distance = 0
    shortest_cp = 0
    for j in range(m):
        if j == 0:
            distance = 1
            shortest_cp = abs(st[i][0]-cp[j][0]) + abs(st[i][1]-cp[j][1])
        else:
            if (abs(st[i][0]-cp[j][0]) + abs(st[i][1]-cp[j][1])) < shortest_cp:
                distance = j + 1
                shortest_cp = abs(st[i][0]-cp[j][0]) + abs(st[i][1]-cp[j][1])
                
    print(distance)

Submission status: Accepted

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

for i in range(N):
    idx = 1
    mindis = abs(students[i][0]-checkPoints[0][0])+ abs(students[i][1]-checkPoints[0][1])
    sx,sy = students[i]
    for j in range(1,M):
        cx,cy = checkPoints[j]
        distance = abs(sx-cx)+ abs(sy-cy)
        if mindis > distance:
            idx = j+1
            mindis = distance
    print(idx)

Submission status: Accepted

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

for i in range(N):
    idx = -1
    mindis = 3*10**8
    sx,sy = students[i]
    for j in range(M):
        cx,cy = checkPoints[j]
        distance = abs(sx-cx)+ abs(sy-cy)
        if mindis > distance:
            idx = j+1
            mindis = distance
    print(idx)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
Std = [tuple(map(int, input().split())) for _ in range(N)]
Chp = [tuple(map(int, input().split())) for _ in range(M)]
INF = 10e9
Arrv = []
Mdist = lambda x,y,u,v:abs(x-u)+abs(y-v)
for s in Std:
    close = INF
    for i in range(M):
        dist = Mdist(*s,*Chp[i])
        if dist < close:
            close = dist
            arrv = i+1
    Arrv.append(arrv)
for ar in Arrv:
    print(ar)

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] * m
for i in range(n):
    a, b = ab[i][0], ab[i][1]
    dist = [0] * m
    for j in range(m):
        dist[j] = abs(a - cd[j][0]) + abs(b - cd[j][1])
    dm = min(dist)
    for j in range(m):
        if dist[j] == dm:
            print(j+1)
            break

Submission status: Accepted

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

tmp = []
for i in range(len(student)):
    for j in range(len(check)):
        x = abs(student[i][0] - check[j][0])
        y = abs(student[i][1] - check[j][1])
        tmp.append(x+y)
    print(tmp.index(min(tmp))+1)
    tmp = []

Submission status: Accepted

Solution code:
N,M=map(int,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)]

for a,b in ab:
  ans=list()
  for c,d in cd:
    ans.append(abs(a-c)+abs(b-d))
  print(ans.index(min(ans))+1)

Submission status: Accepted

Solution code:
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    n, m = i_map()
    n_list = i_row_list(n)
    m_list = i_row_list(m)

    for num in n_list:
        min_dist = INF
        min_point = 0
        for i, check in enumerate(m_list):
            dist = abs(num[0]-check[0]) + abs(num[1]-check[1])
            if min_dist > dist:
                min_dist = dist
                min_point = i + 1
        print(min_point)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    N, M = map(int, readline().split())

    students = []

    for _ in range(N):
        a, b = map(int, readline().split())
        students.append((a, b))

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

    for i in range(N):
        dist_min = INF
        idx = -1
        x1, y1 = students[i]
        for j in range(M):
            x2, y2 = cp[j]
            dist_cur = abs(x2 - x1) + abs(y2 - y1)
            if dist_cur < dist_min:
                dist_min = dist_cur
                idx = j + 1
        print(idx)


if __name__ == '__main__':
    main()

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)]
for i in range(n):
  Min=4*(10**8)+1
  for j in range(m):
    d = abs(ab[i][0]-cd[j][0]) + abs(ab[i][1]-cd[j][1])
    #print(d,ab[i][0],cd[j][0])
    if Min > d:
      Min = d
      ans = j+1
  print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(4100000)
import math
import itertools
INF = float('inf')
from heapq import heapify, heappop, heappush
import collections
import bisect

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 i in range(n):
        dist = []
        for j in range(m):
            dist.append(abs(AB[i][0]-CD[j][0]) + abs(AB[i][1] - CD[j][1]))
        dist_min = min(dist)
        for k in range(len(dist)):
            if dist[k] == dist_min:
                print(k+1)
                break


if __name__ == '__main__':
    main()

Submission status: Accepted

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

# 学生N人の現在地(a,b)
A_B = [list(map(int, input().split())) for _ in range(N)]
# チェックポイントM個の場所(c,d)
C_D = [list(map(int, input().split())) for _ in range(M)]


for a, b in A_B:
    temp_distance = 10**10
    temp_checkpoint = -1
    checkpoint_count = 1
    for c, d in C_D:
        manhattan_distance = abs(a-c) + abs(b-d)
        if temp_distance > manhattan_distance:
            temp_distance = manhattan_distance
            temp_checkpoint = checkpoint_count
        checkpoint_count += 1
    print(temp_checkpoint)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
coordinate = [list(map(int,input().split())) for c in range(n)]
point = [list(map(int,input().split())) for c in range(m)]
for c in coordinate:
  num = 10**9
  ans = []
  for index,p in enumerate(point):
    tmp = abs(c[0]-p[0])+abs(c[1]-p[1])
    ans.append(tmp)
  print(ans.index(min(ans))+1)

Submission status: Accepted

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

s = [tuple(map(int, input().split())) for _ in range(n)]
c = [tuple(map(int, input().split())) for _ in range(m)]

for a, b in s:
    d = float('inf')
    for i in range(m):
        x, y = c[i]
        if abs(a - x) + abs(b - y) < d:
            d = abs(a - x) + abs(b - y)
            ans = i + 1
    print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
a = []
c = []
for i in range(N):
  x, y = map(int, input().split())
  a.append([x, y])
for i in range(M):
  x, y = map(int, input().split())
  c.append([x, y])

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

ans = []



for i in range(n):
    judge = 10 ** 9
    num = 0
    for j in range(m):
        if judge > abs(a[i]-c[j])+abs(b[i]-d[j]):
            judge = abs(a[i]-c[j])+abs(b[i]-d[j])
            num = j+1
    ans.append(num)
#print(ans)
for i in ans:
    print(i)

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:
    check_point_dist = 10 ** 8 * 4 + 1
    check_point = 0
    count = 0
    for c, d in cd:
        count += 1
        if check_point_dist > abs(a - c) + abs(b - d):
            check_point = count
            check_point_dist = abs(a - c) + abs(b - d)
    else:
        print(check_point)

Submission status: Accepted

Solution code:
def distance(coordinate1, coordinate2):
    x1 = coordinate1[0]
    y1 = coordinate1[1]
    x2 = coordinate2[0]
    y2 = coordinate2[1]
    return abs(x1 - x2) + abs(y1 - y2)


def main():
    n, m = map(int, input().split())
    ab_lst = [list(map(int, input().split())) for _ in range(n)]
    cd_lst = [list(map(int, input().split())) for _ in range(m)]
    point_lst = []

    for i in range(n):

        distance_lst = []
        for j in range(m):

            coordinate1 = ab_lst[i]
            coordinate2 = cd_lst[j]
            distance_lst.append(distance(coordinate1, coordinate2))

        minimum = min(distance_lst)
        for k in range(m):
            if distance_lst[k] == minimum:
                point_lst.append(k + 1)
                break

    for i in range(n):
        print(point_lst[i])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
place = [list(map(int,input().split())) for _ in range(N)]
check = [list(map(int,input().split())) for _ in range(M)]
for x,y in place:
    tmp = 10**9
    for i in range(M):
        dis = abs(x-check[i][0]) + abs(y-check[i][1])
        if tmp > dis:
            tmp = dis
            ans = i+1
    print(ans)

Submission status: Accepted

Solution code:
N,M=list(map(int,input().split()))
S=[[0,0]]*N
for i in range(N):
  S[i]=list(map(int,input().split()))
C=[[0,0]]*M
for j in range(M):
  C[j]=list(map(int,input().split()))

INF=float('inf')
ans=[[0,INF]]*N
for i in range(N):
  for j in range(M):
    x=abs(S[i][0]-C[j][0])
    y=abs(S[i][1]-C[j][1])
    if x+y<ans[i][1]:
      ans[i]=[j+1,x+y]
for i in range(N):
  print(ans[i][0])

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 j in range(m)]

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

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

Submission status: Accepted

Solution code:
#
# abc057 b
#

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """2 2
2 0
0 0
-1 0
1 0"""
        output = """2
1"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """3 4
10 10
-10 -10
3 3
1 2
2 3
3 5
3 5"""
        output = """3
1
2"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """5 5
-100000000 -100000000
-100000000 100000000
100000000 -100000000
100000000 100000000
0 0
0 0
100000000 100000000
100000000 -100000000
-100000000 100000000
-100000000 -100000000"""
        output = """5
4
3
2
1"""
        self.assertIO(input, output)


def resolve():
    N, M = map(int, input().split())
    S = [list(map(int, input().split())) for _ in range(N)]
    C = [list(map(int, input().split())) for _ in range(M)]

    ans = []
    for s in S:
        D = float("inf")
        t = 0
        for i in range(M):
            d = abs(s[0]-C[i][0]) + abs(s[1]-C[i][1])
            if d < D:
                D = d
                t = i
        ans.append(t+1)

    for a in ans:
        print(a)


if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
ab = []
cd = []
for i in range(N):
  tmp = list(map(int, input().split()))
  ab.append(tmp)
for j in range(M):
  tmp = list(map(int, input().split()))
  cd.append(tmp)
for i in range(N):
  tmp = 10**10
  tmp2 = 0
  for j in range(M):
    if tmp > abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1]):
      tmp = abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
      tmp2 = j
  print(tmp2+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 a,b in AB:
    tmp_point = -1
    tmp_root = 100000000000
    for i,cd in enumerate(CD):
        c,d = cd
        if abs(a-c)+abs(b-d) < tmp_root:
            tmp_root = abs(a-c)+abs(b-d)
            tmp_point = i+1
    print(tmp_point)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
ab,cd=[list(map(int,input().split())) for _ in range(n)],[list(map(int,input().split())) for _ in range(m)]
for i in ab:
  r=[]
  for j in cd: r.append(abs(i[0]-j[0])+abs(i[1]-j[1]))
  print(r.index(min(r))+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)]
r=[]
for i in ab:
  x1,y1=i[0],i[1]
  temp=[]
  for j in cd:
    x2,y2=j[0],j[1]
    temp.append(abs(x1-x2)+abs(y1-y2))
  r.append(temp.index(min(temp))+1)
print(*r,sep='\n')

Submission status: Accepted

Solution code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n,m=nii()
ab=[lnii() for i in range(n)]
cd=[lnii() for i in range(m)]

ans=[]
for a,b in ab:
  min_dist=10**10
  for i in range(m):
    c,d=cd[i]
    if abs(a-c)+abs(b-d)<min_dist:
      t_ans=i
      min_dist=abs(a-c)+abs(b-d)
  ans.append(t_ans+1)

for i in ans:
  print(i)

Submission status: Accepted

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

cp = [0]*M
for i in range(M):
    cp[i] = list(map(int,input().split()))

# print(stu,cp)
stumo = [0]*N
for i in range(N):
    min_move = 10000000000000000000000000
    for j in range(M):
        min_his = min_move 
        mhd = abs(stu[i][0]-cp[j][0]) + abs(stu[i][1]-cp[j][1])
        min_move = min(min_move,mhd)
        if(min_move != min_his):
            stumo[i] = j+1
# print(stumo)
for i in range(N):
    print(stumo[i])