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:
#a = int(input())
#b,c = map(int,input().split())
#s = input()
#list_s = list(input())
#list_int = list(map(int,input().split()))

#list = [0 for i in range(n)]
#dp = [[0 for i in range(A)] for j in range(B)]

#list_int 並べて出力 print (' '.join(map(str,ans_li)))
#list_str 並べて出力 print (' '.join(list))

# 2進数 format(10, 'b') # '1010'

# aa=[int(input()) for i in range(n)]

#for i,name in enumerate(list)

''' 二次元配列を一列ずつ
for i in ans:
	print(*i)
'''
''' heapq
queue = []
heapq.heapify(queue) #heapqの作成
heapq.heappush(queue,num) #numのpush(値の追加)
pop = heapq.heappop(queue) #numのpop(最小値の出力)
pop = heapq.heappushpop(queue,num) #push -> pop

'''

from collections import defaultdict
import sys,heapq,bisect,math,itertools,string
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7

N,M = map(int,input().split())
ab_list = []
ans = [[INF,0]]*N

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

for i in range(M):
	c,d = map(int,input().split())
	for n,[a,b] in enumerate(ab_list):
		dist = abs(a-c)+abs(b-d)
		if ans[n][0] > dist:
			ans[n] = [dist,i]

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

Submission status: Accepted

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

ans = []
for s in ss:
    buf = float('inf')
    c_n = -1
    for idx in range(len(ps)):
        dist = abs(s[0] - ps[idx][0]) + abs(s[1] - ps[idx][1])
        if dist < buf:
            buf = dist
            c_n = idx
    ans += [c_n+1]

for x in ans:
    print(x)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
student = []
for i in range(N):
    x_y = list(map(int, input().split()))
    student.append(x_y)
    
check = []
for i in range(M):
    x_y = list(map(int, input().split()))
    check.append(x_y)
    
for i in student:
    cnt = []
    for j in check:
        dis = abs(i[0] - j[0]) + abs(i[1] - j[1])
        cnt.append(dis)
    print(cnt.index(min(cnt)) + 1)

Submission status: Accepted

Solution code:
n, m = [int(i) for i in input().split()]
a = []
b = []
c = []
d = []
for k in range(n):
    tmp = [int(i) for i in input().split()]
    a.append(tmp[0])
    b.append(tmp[1])
for k in range(m):
    tmp = [int(i) for i in input().split()]
    c.append(tmp[0])
    d.append(tmp[1])

for i in range(n):
    point = 1
    min_dis = abs(a[i] - c[0]) + abs(b[i] - d[0])
    for j in range(1, m):
        dis = abs(a[i] - c[j]) + abs(b[i] - d[j])
        if min_dis > dis:
            point = j + 1
            min_dis = dis
    print(point)

Submission status: Accepted

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

N_ab = []
M_cd = []

for i in range(n):
  a, b = map(int, input().split())
  N_ab.append([a, b])
  
for i in range(m):
  c, d = map(int, input().split())
  M_cd.append([c, d])
  
for i in range(n):
  Mi = abs(N_ab[i][0]-M_cd[0][0]) + abs(N_ab[i][1]-M_cd[0][1])
  #print(Mi)
  num = 0
  for j in range(1, m):
    tmp = abs(N_ab[i][0]-M_cd[j][0]) + abs(N_ab[i][1]-M_cd[j][1])
    #print(tmp)
    if tmp<Mi:
      Mi=tmp
      num=j
  print(num+1)

Submission status: Accepted

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

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

# print("ab:", ab)
# print("cd:", cd)

for i, (a, b) in enumerate(ab):
    # print(i, " ", a, " ", b)
    min_dis = sys.maxsize
    min_idx = -1
    # print(min_idx, " ", min_dis)
    for j, (c, d)  in enumerate(cd):
        distance = abs(a-c) + abs(b-d)
        # print(j, " ", distance)
        if distance < min_dis:
            min_dis = distance
            min_idx = j
    print(min_idx+1)

Submission status: Accepted

Solution code:
N, M = list(map(int, input().split()))
A, B = [0 for i in range(N)], [0 for i in range(N)]
for i in range(N):
    A[i], B[i] =  list(map(int, input().split()))
C, D =  [0 for i in range(M)], [0 for i in range(M)]
for i in range(M):
    C[i], D[i] =  list(map(int, input().split()))

# 距離求める
def distance(a, b, c, d):
    return abs(a - c) + abs(b - d)

# i番目の人が行く場所調べる
def judge(i):
    tmp = -1
    re = -1
    for j in range(M):
        dis = distance(A[i], B[i], C[j], D[j])
        if tmp == -1 or tmp > dis:
            tmp = dis
            re = j
#    print(re, ' ', tmp)
    return re+1

for i in range(N):
    print(judge(i))

Submission status: Accepted

Solution code:
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 i in range(m):
    c, d = map(int, input().split())
    C.append(c)
    D.append(d)

for i in range(n):
    a = A[i]
    b = B[i]
    min_dist = 10 ** 9
    min_num = -1
    for j in range(m):
        c = C[j]
        d = D[j]
        dist = abs(a-c)+abs(b-d)
        if min_dist > dist:
            min_dist = dist
            min_num = j+1
    print(min_num)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = []
for i in range(N):
  a, b = map(int, input().split())
  A.append([a, b])
B = []
for i in range(M):
  c, d = map(int, input().split())
  B.append([c, d])
M = [[[abs(b[0] - a[0]) + abs(b[1] - a[1]), i] for i, b in enumerate(B)] for a in A]
for m in M:
  print(sorted(m, key=lambda x:x[0])[0][1] + 1)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
a, b, c, d = [], [], [], []
for i in range(N):
    ai, bi = map(int, input().split())
    a.append(ai)
    b.append(bi)
for i in range(M):
    ci, di = map(int, input().split())
    c.append(ci)
    d.append(di)

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


for i in range(N):
    min_dist = float('inf')
    min_checkpoint = -1
    for j in range(M):
        dist = distance(a[i], c[j], b[i], d[j])
        if dist < min_dist:
            min_dist = dist
            min_checkpoint = j + 1
    print(min_checkpoint)

Submission status: Accepted

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

for i in range(N):
	L = []
	for j in range(M):
		L.append(abs(AB[i][0] - CD[j][0]) + abs(AB[i][1] - CD[j][1]))
	print(L.index(min(L)) + 1)

Submission status: Accepted

Solution code:
n, m = list(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 i in range(n):
  t = float("INF")
  for j in range(m):
    if abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])<t:
      t = abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
      ans = j+1
  print(ans)

Submission status: Accepted

Solution code:
import math
def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()
    
    array_result.append(data.split(" "))

    flg = 1

    try:

        while flg:

            data = input()

            if(data != ""):
                
                array_result.append(data.split(" "))

            else:

                flg = 0
    finally:

        return array_result

arr_data = getinputdata()

n = int(arr_data[0][0])
m = int(arr_data[0][1])

arr_chk = []
for j in range(1 + n, 1 + n + m):
    
    arr_temp = []
    arr_temp.append(int(arr_data[j][0]))
    arr_temp.append(int(arr_data[j][1]))
    arr_chk.append(arr_temp)
    
#学生数ループ処理    
for i in range(1, 1 + n):
    
    x1 = int(arr_data[i][0])
    y1 = int(arr_data[i][1])
    
    l = abs(x1-arr_chk[0][0]) + abs(y1-arr_chk[0][1])
    
    seq=0
    
    #チェックポイント数分ループ
    for j in range(1,len(arr_chk)):
     
        ltemp = abs(x1-arr_chk[j][0]) + abs(y1-arr_chk[j][1])
        
        if l>ltemp:
            
            seq=j
            l=ltemp
            
    print(seq+1)

Submission status: Accepted

Solution code:
# input
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):
    c = 0
    for j in range(M):
        if abs(S[i][0] - C[j][0]) + abs(S[i][1] - C[j][1]) < abs(S[i][0] - C[c][0]) + abs(S[i][1] - C[c][1]):
            c = j
    print(c + 1)

Submission status: Accepted

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

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 a in A:
    dis = 10**100
    ans = None
    for i in range(len(C)):
        c = C[i]
        if abs(a[0]-c[0])+abs(a[1]-c[1]) < dis:
            dis = abs(a[0]-c[0])+abs(a[1]-c[1])
            ans = i + 1
    print(ans)

Submission status: Accepted

Solution code:
n, m = list(map(int, input().split()))
student_positions = []
checkpoints = []

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

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

for i in range(n):
  max = 0
  for j in range(1, m):
    if abs(student_positions[i][0] - checkpoints[j][0]) + abs(student_positions[i][1] - checkpoints[j][1]) < abs(student_positions[i][0] - checkpoints[max][0]) + abs(student_positions[i][1] - checkpoints[max][1]):
      max = j

  print(max + 1)

Submission status: Accepted

Solution code:
"""
https://abc057.contest.atcoder.jp/tasks/abc057_b
"""
[n,m]=[int(i) for i in input().split()]
ab=[]
cd=[]
k=[]
box=[]
l=0
for i in range(n):
    ab.append([int(j) for j in input().split()])
for i in range(m):
    cd.append([int(j) for j in input().split()])

for i in range(n):
    for j in range(m):
        k.append(abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1]))
    #kには全てのjについてのマンハッタン距離が入る
    box.append(k)
    k=[]


for i in range(n):
    for j in box[i]:
        if j == min(box[i]):
            l=l+1
            print(l)
            break
        l=l+1
    l=0

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

Submission status: Accepted

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

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

# 学生の数ループ
for i in range(N):
    # 最小値の初期値は無限大
    min_point = float("inf")
    ans = 0
    # チェックポイントの数ループ
    for j in range(M):
        # マンハッタン距離の計算
        x = abs(N_list[i][0] - M_list[j][0])
        y = abs(N_list[i][1] - M_list[j][1])
        tmp = x + y
        # 最短距離なら、最短距離を更新してチェックポイントの番号を出力
        if tmp < min_point:
            min_point = tmp
            ans = j + 1
    print(ans)

Submission status: Accepted

Solution code:
x=input().split()
n=int(x[0])
m=int(x[1])
stu=[[]*i for i in range(n)]
che=[[]*i for i in range(m)]
for i in range(n):
    x=input().split()
    x[0]=int(x[0])
    x[1]=int(x[1])
    stu[i]=x
for i in range(m):
    x=input().split()
    x[0]=int(x[0])
    x[1]=int(x[1])
    che[i]=x

for i in stu:
    di=[]
    mini=9999999999
    for j in che:
        x=abs(i[0]-j[0])+abs(i[1]-j[1])
        di.append(x)
        mini=min(mini,x)
    print(di.index(mini)+1)

Submission status: Accepted

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

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

for n in n_list:
    distance = 10 ** 16
    ans = 0
    for i in range(len(m_list)):
        this_distance = cal_distance(n[0], m_list[i][0], n[1], m_list[i][1])
        if distance > this_distance:
            distance = this_distance
            ans = (i + 1)

    print(ans)

Submission status: Accepted

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

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

for n in n_list:
    distance = 10 ** 16
    index = 0
    ans = 0
    for m in m_list:
        index += 1
        if distance > cal_distance(n[0], m[0], n[1], m[1]):
            distance = cal_distance(n[0], m[0], n[1], m[1])
            ans = index

    print(ans)

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 ab_i in ab:
    min_j = -1
    min_manh = float('inf')
    for j, cd_j in enumerate(cd):
        if min_manh > abs(ab_i[0]-cd_j[0])+abs(ab_i[1]-cd_j[1]):
            min_manh = abs(ab_i[0]-cd_j[0])+abs(ab_i[1]-cd_j[1])
            min_j = j+1
    print(min_j)

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 ab_i in ab:
    min_j = -1
    min_manh = float('inf')
    for j, cd_j in enumerate(cd):
        if min_manh > abs(ab_i[0]-cd_j[0])+abs(ab_i[1]-cd_j[1]):
            min_manh = abs(ab_i[0]-cd_j[0])+abs(ab_i[1]-cd_j[1])
            min_j = j+1
    print(min_j)

Submission status: Accepted

Solution code:
N,M=map(int,raw_input().split())
xs=[]
cs=[]
for i in xrange(N):
  x=map(int,raw_input().split())
  xs.append(x)
for i in xrange(M):
  c=map(int,raw_input().split())
  cs.append(c)
for x in xs:
  cp = -1
  cd = 1e9
  for j,c in enumerate(cs):
    md = abs(c[0]-x[0]) + abs(c[1]-x[1])
    if md < cd:
      cd = md
      cp = j
  print 1+cp

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=[[int(i) for i in input().split()] for j in range(n)]
c=[[int(i) for i in input().split()] for j in range(m)]
for x1,y1 in a:
  d=10**9
  n=1
  s=0
  for x2,y2 in c:
    if abs(x1-x2)+abs(y1-y2)<d:
      s=n
      d=abs(x1-x2)+abs(y1-y2)
    n+=1
  print(s)

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,j in a:
    dis=10**9
    point=0
    for k in range(m):
        if abs(i-b[k][0])+abs(j-b[k][1])<dis:
            dis=abs(i-b[k][0])+abs(j-b[k][1])
            point=k
    print(point+1)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
s=[list(map(int,input().split()))for _ in[0]*N]
c=[list(map(int,input().split()))for _ in[0]*M]
for x,y in s:
    d={k+1:abs(x-t[0])+abs(y-t[1])for k,t in enumerate(c)}
    print(min(d,key=d.get))

Submission status: Accepted

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

ans = []
for sx,sy in st:
    minci = 1
    mind = float('inf')
    for i,(cx,cy) in enumerate(ch):
        d = abs(sx-cx) + abs(sy-cy)
        if d < mind:
            mind = d
            minci = i+1
    ans.append(str(minci))
print(*ans, sep='\n')

Submission status: Accepted

Solution code:
N,M = (int(i) for i in input().split())
a=[]
b=[]
c=[]
d=[]

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

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


closest = N*[0]

for i in range(N):
    minimum = abs(a[i]-c[0])+abs(b[i]-d[0])
    number = 1
    for j in range(1,M):
        distance = abs(a[i]-c[j])+abs(b[i]-d[j])
        if distance < minimum:
            minimum = distance
            number = j+1
    closest[i] = number

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
cd = [list(map(int, input().split())) for _ in range(m)]
for g in ab:
    dis = 10**9
    point = 0
    for c in range(m):
        d = abs(g[0]-cd[c][0]) + abs(g[1]-cd[c][1])
        if(dis > d):
            dis = d
            point = c + 1
    print(point)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
A,B,C,D,Ans = [],[],[],[],[]
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)
for i in range(N):
    d,t = 10**10,-1
    for j in range(M):
        if d > abs(A[i]-C[j])+abs(B[i]-D[j]):
            d = abs(A[i]-C[j])+abs(B[i]-D[j])
            t = j
    Ans.append(t)
for i in range(N):
    print(Ans[i]+1)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
rec1, rec2 = [], []
for i in range(n):
    a, b = map(int, input().split())
    rec1.append((a, b))

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

rec = []
for i in range(n):
    a, b = rec1[i]
    num = float("inf")
    for j in range(m):
        c, d = rec2[j]
        if abs(a - c) + abs(b - d) < num:
            index = j
            num = abs(a - c) + abs(b - d)
    rec.append(index)


for i in range(n):
    print(rec[i] + 1)

Submission status: Accepted

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

INF = 10**9
d = lambda x, y: abs(x[0]-y[0]) + abs(x[1]-y[1])

for s in st:
    ans = 0
    dist = INF
    for i, c in enumerate(ch):
        dist_ = d(s, c)
        if dist_ < dist:
            dist = dist_
            ans = i
    print(ans+1)

Submission status: Accepted

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

for a,b in mapN:
    ans = 0
    intInf = float('inf')
    i = 1
    for c,d in mapM:
        work = abs(a - c) + abs(b - d)
        if work < intInf:
            intInf = work
            ans = i
        i += 1
    print(ans)

Submission status: Accepted

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

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

check = []
for i in range(m):
    check.append(tuple(map(int, input().split())))

for i in student:
    min_idx = 0
    min_k = abs(i[0]-check[0][0]) + abs(i[1]-check[0][1])
    for j in range(1, len(check)):
        k = abs(i[0]-check[j][0]) + abs(i[1]-check[j][1])
        if k < min_k:
            min_k = k
            min_idx = j

    print(min_idx+1)

Submission status: Accepted

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

for s in S:
    d = 10**9
    t = 0
    for c in range(M):
        if d > abs(s[0]-C[c][0])+abs(s[1]-C[c][1]):
            d = abs(s[0]-C[c][0])+abs(s[1]-C[c][1])
            t = c
    print(t+1)

Submission status: Accepted

Solution code:
N, M = map(int, input().split(' '))
st = {i: list(map(int, input().split(' '))) for i in range(N)}
chk = {i: list(map(int, input().split(' '))) for i in range(M)}
num_chk = [0] * N
for s_k, s_v in st.items():
    prev = float('inf')
    for c_k, c_v in chk.items():
        dist = abs(c_v[0] - s_v[0]) + abs(c_v[1] - s_v[1])
        if dist < prev:
            prev = dist
            num_chk[s_k] = c_k + 1
for i in num_chk:
    print(i)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
n_p = list()
m_p = list()
ans = 1


for i in range(n):
    n_p.append(list(map(int,input().split()))    )
for j in range(m):
    m_p.append(list(map(int,input().split())))
    
for i in range(n):
    ans = 1
    d=abs(n_p[i][0]-m_p[0][0])+abs(n_p[i][1]-m_p[0][1])
    for j in range(m):
        if d != min(d,abs(n_p[i][0]-m_p[j][0])+abs(n_p[i][1]-m_p[j][1])):
            d = min(d,abs(n_p[i][0]-m_p[j][0])+abs(n_p[i][1]-m_p[j][1]))
            ans = j+1
    print(ans)

Submission status: Accepted

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

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

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

for x, y in ns:
    diff = abs(x - ms[0][0]) + abs(y - ms[0][1])
    ans = 1
    for i, e in enumerate(ms):
        d = abs(x - e[0]) + abs(y - e[1])
        if d < diff:
            ans = i + 1
            diff = d
    print(ans)

Submission status: Accepted

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

S=[]
C=[]

for i in range(N):
  a,b=map(int,input().split())
  S.append([a,b])
for i in range(M):
  a,b=map(int,input().split())
  C.append([a,b])
  
for a,b in S:
  min=M
  man=10**10
  for i in range(M):
    cnt=abs(a-C[i][0])+abs(b-C[i][1])
    if man>cnt:
      man=cnt
      min=i
  print(min+1)

Submission status: Accepted

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

def searchpoint(student, lst):
	min = 1000000000
	ans = -1
	for i in range(0, len(lst)):
		tmp = distance(student, lst[i])
		if tmp < min:
			min = tmp
			ans = i + 1
	return ans

N, M = map(int, raw_input().split())
student = []
for i in range(0, N):
	student.append(map(int, raw_input().split()))
checkpoint = []
for i in range(0, M):
	checkpoint.append(map(int, raw_input().split()))
for i in range(0, N):
	print searchpoint(student[i], checkpoint)

Submission status: Accepted

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

P,C = [],[]
for i in range(N):
    P.append(list(map(int,input().split())))
for j in range(M):
    C.append(list(map(int,input().split())))

for i in range(N):
    min_point = 0
    min_man = 0
    for j in range(M):
        man = abs(P[i][0]-C[j][0]) + abs(P[i][1]-C[j][1])
        if min_man > man or min_point==0:
            min_man = man
            min_point = j+1
    print(min_point)

Submission status: Accepted

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

ans = 50
distance = 'a'

for i in range(n):
    for j in range(m):
        e = abs(a[i]-c[j])+abs(b[i]-d[j])
        if distance == 'a':
            distance = e
            ans = j
        elif distance > e:
            distance = e
            ans = j
    print(ans+1)
    ans = 50
    distance = 'a'

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
student_list = []
checkpoint_list = []
for _ in range(N):
    student_list.append(list(map(int, input().split())))
    
for _ in range(M):
    checkpoint_list.append(list(map(int, input().split())))
    
for i in student_list:
    compare_dict = {}
    for k, l in enumerate(checkpoint_list):
        
        manhattan_d = abs(i[0]-l[0])+abs(i[1]-l[1])
        
        if manhattan_d not in compare_dict.keys():
            compare_dict[manhattan_d] = k+1
        else:
            pass
    
    print(compare_dict[sorted(compare_dict.keys())[0]])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def inpl(): return list(map(int, input().split()))
N, M = inpl()
s = []
c = []
for i in range(N):
    s.append(inpl())
for i in range(M):
    c.append(inpl())
for s_i in s:
    ans = 0
    d = 10000000000
    for (j, c_j) in enumerate(c):
        temp = abs(s_i[0]-c_j[0])+abs(s_i[1]-c_j[1])
        if temp<d:
            d = temp
            ans = j+1
            
    print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
ab = [[int(a) for a in input().split()] for _ in range(N)]
cd = [[int(a) for a in input().split()] for _ in range(M)]
for i in range(N):
    min_distance = float('inf')
    check_point = 0
    for j in range(M):
        manhattan_distance = abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
        if min_distance > manhattan_distance:
            min_distance = manhattan_distance
            check_point = j+1
    print(check_point)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    student_count, checkpoint_count = map(int, input().split())
    student_points = [list(map(int, input().split())) for i in range(1, student_count + 1)]
    check_points = [list(map(int, input().split())) for i in range(1, checkpoint_count + 1)]
 
    for student_point_x, student_point_y in student_points:
        point_number = 0
        shortest_distance = float('inf')
        manhattan_distance = 0
 
        for i in range(len(check_points)):
            diff_x = abs(student_point_x - check_points[i][0])
            diff_y = abs(student_point_y - check_points[i][1])
            manhattan_distance = diff_x + diff_y
 
            if manhattan_distance < shortest_distance:
                shortest_distance = manhattan_distance
                point_number = i + 1
 
        print(point_number)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a = [None] * n
for i in range(n):
    a[i] = tuple(map(int, input().split()))
b = [None] * m
for i in range(m):
    b[i] = tuple(map(int, input().split()))
for x, y in a:
    z = None
    k = None
    for i in range(m):
        c, d = b[i]
        d = abs(x - c) + abs(y - d)
        if z is None or d < z:
            z = d
            k = i
    print(k + 1)

Submission status: Accepted

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

def nearest(x, y, checkpoints):
    distances = list(map(lambda c: distance(x, y, c[0], c[1]), checkpoints))
    return 1 + distances.index(min(distances))


if __name__ == '__main__':
    n, m = map(int, input().split())
    students = [list(map(int, input().split())) for _ in range(n)]
    checkpoints = [list(map(int, input().split())) for _ in range(m)]
    for x, y in students:
        print(nearest(x, y, checkpoints))

Submission status: Accepted

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

# AtCoder Beginner Contest
# Problem B

if __name__ == '__main__':
    student_count, checkpoint_count = map(int, input().split())
    student_points = [list(map(int, input().split())) for i in range(1, student_count + 1)]
    check_points = [list(map(int, input().split())) for i in range(1, checkpoint_count + 1)]

    for student_point_x, student_point_y in student_points:
        point_number = 0
        shortest_distance = float('inf')
        manhattan_distance = 0

        for i in range(len(check_points)):
            diff_x = abs(student_point_x - check_points[i][0])
            diff_y = abs(student_point_y - check_points[i][1])
            manhattan_distance = diff_x + diff_y

            if manhattan_distance < shortest_distance:
                shortest_distance = manhattan_distance
                point_number = i + 1

        print(point_number)

Submission status: Accepted

Solution code:
n, m = map(int,input().split())
abl = [[int(i) for i in input().split()] for i in range(n)]
cdl = [[int(i) for i in input().split()] for i in range(m)]
ans = []
for i in range(n):
    tmp = abs(abl[i][0]-cdl[0][0])+abs(abl[i][1]-cdl[0][1])
    c_i = 1
    for j in range(1,m):
        if tmp > abs(abl[i][0]-cdl[j][0])+abs(abl[i][1]-cdl[j][1]):
            tmp = abs(abl[i][0]-cdl[j][0])+abs(abl[i][1]-cdl[j][1])
            c_i = j+1
    ans.append(c_i)
for i in range(n):
    print(ans[i])

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
ab = [list(map(int,input().split())) for x in [0]*n]
cd = [list(map(int,input().split())) for x in [0]*m]
for a,b in ab:
    l = [abs(a-c)+abs(b-d) for c,d in cd]
    print(l.index(min(l))+1)

Submission status: Accepted

Solution code:
n,m = (int(i) for i in input().split())
x = [[int(i) for i in input().split()] for i in range(n)]
y = [[int(i) for i in input().split()] for i in range(m)]
for i in x:
	num,answer = abs(i[0]-y[0][0])+abs(i[1]-y[0][1]),1
	for j in range(m):
		if num > abs(i[0]-y[j][0])+abs(i[1]-y[j][1]):
			answer = j+1
			num = abs(i[0]-y[j][0])+abs(i[1]-y[j][1])
	print(answer)

Submission status: Accepted

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

stu_list = []
cp_list = []

for i in range(N):
    stu_list.append(list(map(int, input().split())))

for j in range(M):
    cp_list.append(list(map(int, input().split())))

for i in range(len(stu_list)):
    min_cp = 0
    min_d = 10**9
    for j in range(len(cp_list)):
        d = abs(stu_list[i][0] - cp_list[j][0]) + abs(stu_list[i][1] - cp_list[j][1])

        if min_d > d:
            min_cp = j + 1
            min_d = d

    print(min_cp)

Submission status: Accepted

Solution code:
import pprint
import itertools

N, M = [int(s) for s in input().split()]

AB = []
for i in range(N):
    AB.append(tuple([int(s) for s in input().split()]))

CD = []
for j in range(M):
    CD.append(tuple([int(s) for s in input().split()]))

for i in range(N):
    mi = 0
    di = abs(CD[0][0] - AB[i][0]) + abs(CD[0][1] - AB[i][1])
    for j in range(1, M):
        md = abs(CD[j][0] - AB[i][0]) + abs(CD[j][1] - AB[i][1])
        if md < di:
            mi, di = j, md
    print(mi + 1)