Problem:


Score : 200 points

Problem Statement

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

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

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

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

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

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

Which checkpoint will each student go to?

Constraints

1 \leq N,M \leq 50

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

All input values are integers.

Input

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

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

Output

Print N lines.

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

Sample Input 1

2 2
2 0
0 0
-1 0
1 0

Sample Output 1

2
1

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

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

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

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

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

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

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

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

Sample Input 2

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

Sample Output 2

3
1
2

There can be multiple checkpoints at the same coordinates.

Sample Input 3

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

Sample Output 3

5
4
3
2
1



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


Sample output:
2
1

Submission status: Accepted

Solution code:
import numpy as np
N,M = map(int, input().split())

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

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

for i in p:
  print(np.argmin([distance(i,j)for j in c])+1)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
x = [list(map(int,input().split()))for i in range(n)]
y = [list(map(int,input().split()))for i in range(m)]
ans = []
for a,b in x:
    dif = 10**9
    index = -1
    for i in range(m):
        c,d = y[i]
        if dif>abs(a-c)+abs(b-d):
            dif=abs(a-c)+abs(b-d)
            index = i+1
    ans.append(index)
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(300000)

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


N, M = MI()
AB = [tuple(MI()) for _ in range(N)]
CD = [tuple(MI()) for _ in range(M)]
for a, b in AB:
    min_dist = INF
    ans = 0
    for i, (c, d) in enumerate(CD):
        dist = abs(a - c) + abs(b - d)
        if dist < min_dist:
            min_dist = dist
            ans = i + 1
    print(ans)

Submission status: Accepted

Solution code:
import math
n,m = map(int,input().split())
a = []
c = []
for i in range(n):
    a.append(input().split())
for i in range(m):
    c.append(input().split())
for i in range(n):
    d = float('inf')
    for j in range(m):
        b = abs(int(a[i][0]) - int(c[j][0])) + abs(int(a[i][1]) - int(c[j][1]))
        if d > b:
            d = b
            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)]

kouho = [[] for _ in range(N)]

n = 0
for i, j in ab:
    for k, l in cd:
        kouho[n].append(abs(i-k) + abs(j-l))
    n += 1

for i in range(N):
    Nmin = min(kouho[i])
    for j, k in enumerate(kouho[i]):
        if k == Nmin:
            print(j+1)
            break

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n, m = na()
ab = nan(n)
cd = nan(m)

ans = [-1] * n
for i in range(n):
    a, b = ab[i]
    min_val = inf
    for j in range(m):
        c, d = cd[j]
        dist = abs(a - c) + abs(b - d)
        if min_val > dist:
            min_val = dist
            ans[i] = j + 1

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

Submission status: Accepted

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

def checkdist(student,checkpoint):
    a, b = student
    c, d = checkpoint
    
    distance = abs(a-c) + abs(b-d)
    return distance

result = {}

for i in range(len(students)):
    result[i] = 0
    
for i, student in enumerate(students):
    lowest_dist = checkdist(student, checkpoints[0])
    for j, checkpoint in enumerate(checkpoints):
        distance = checkdist(student,checkpoint)
        if distance < lowest_dist:
            result[i] = j
            lowest_dist = distance

for i in range(len(students)):
    print(result[i] + 1)

Submission status: Accepted

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

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

for i in range(n):
    templ=[]
    a=corl[i][0]
    b=corl[i][1]
    for j in range(m):
        c=chkl[j][0]
        d=chkl[j][1]
        templ.append([j,abs(a-c)+abs(b-d)])
    templ.sort(key=lambda x:(x[1],x[0]))
    print(templ[0][0]+1)

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):
    d=100000000000000000
    for j in range(m):
        now=abs(A[i]-C[j])+abs(B[i]-D[j])
        if now<d:
            d=now
    for j in range(m):
        now=abs(A[i]-C[j])+abs(B[i]-D[j])
        if now==d:
            print(j+1)
            break

Submission status: Accepted

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

for i in range(N):
    ans = float('Inf')
    for j in range(M):
        dist = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
        if dist < ans:
            ans = dist
            output = j
    print(output + 1)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a_list = []
b_list = []
for i in range(n):
	a, b = map(int, input().split())
	a_list.append(a)
	b_list.append(b)
c_list = []
d_list = []
for i in range(m):
	c, d = map(int, input().split())
	c_list.append(c)
	d_list.append(d)
for i, x1 in enumerate(a_list):
	y1 = b_list[i]
	v_list = []
	for j, x2 in enumerate(c_list):
		y2 = d_list[j]
		v_list.append(abs(x1 - x2) + abs(y1 - y2))
	print(v_list.index(min(v_list)) + 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)]
#print(a,c)

for i in range(n):
    k=0
    ans=1
    num=10**9
    for j in range(m):
        k=abs(a[i][0]-c[j][0])+abs(a[i][1]-c[j][1])
        #print(abs(a[i][0]-c[j][0]),abs(a[i][1]-c[j][1]),k)
    
        if num>k:
            num=k
            ans=j+1
            #print(ans,num)
    else:
        print(ans)
        

#print(ans,num)

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

e=[0]*N
for k in range(N):
  dist=float("inf")
  pos=0
  for l in range(M):
    tmp = abs(c[l]-a[k])+abs(d[l]-b[k])
    if dist>tmp:
      dist=tmp
      pos=l
  e[k]=pos+1
  
for ans in e:
  print(ans)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
a,b = list(),list()
res = list()
for i in range(N):
  t = input().split()
  a.append(int(t[0]))
  b.append(int(t[1]))
  res.append([0,0])
for n in range(M):
  c,d = map(int,input().split())
  for i in range(N):
    if n == 0:
      res[i][0] = abs(a[i]-c) + abs(b[i]-d) 
    elif res[i][0] > abs(a[i]-c) + abs(b[i]-d):
      res[i][0] = abs(a[i]-c) + abs(b[i]-d)
      res[i][1] = n
for m in range(N):
  print(res[m][1] + 1)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
l_n =list(list(map(int,input().split())) for i in range(n))
l_m =list(list(map(int,input().split())) for i in range(m))
for i in range(n):
  q = 10**9
  for t in range(m):
    a,b = l_n[i]
    c,d = l_m[t]
    v= abs(a-c)+abs(b-d)
    if v<q:
      q = v
      z = t
  print(z+1)

Submission status: Accepted

Solution code:
n, m = [int(i) for i in input().split()]
student_pos_list = [[int(j) for j in input().split()] for i in range(n)]
checkpoint_list = [[int(j) for j in input().split()] for i in range(m)]

for student_pos in student_pos_list:
    min_d = 20**8+1
    min_pt_index = m+1
    for i, checkpt in enumerate(checkpoint_list):
        d = abs(student_pos[0] - checkpt[0]) + abs(student_pos[1] - checkpt[1])
        if d < min_d:
            min_d = d
            min_pt_index = i+1

    print(min_pt_index)

Submission status: Accepted

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

ans = []
for i in range(N):
    for j in range(M):
        tmp = abs(a[i]-c[j])+abs(b[i]-d[j])
        ans.append(tmp)
    print(ans.index(min(ans))+1)
    ans = []

Submission status: Accepted

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

for s in student:
    dist = float('inf')
    ans = 0
    for i, c in enumerate(check):
        tmp = abs(s[0]-c[0]) + abs(s[1]-c[1])
        if tmp<dist:
            ans = i+1
            dist = tmp
    print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N, M = [int(i) for i in input().split()]

a = np.ones(N)
b = np.ones(N)

c = np.ones(M)
d = np.ones(M)

for i in range(N):
    a[i],b[i] = [int(i) for i in input().split()]
    
for i in range(M):
    c[i],d[i] = [int(i) for i in input().split()]
    
    
for i in range(N):
    ans = 1
    min_sofar = abs(a[i]-c[0]) + abs(b[i] - d[0])
    for j in range(M):
        candid = abs(a[i]-c[j]) + abs(b[i] - d[j])
        if min_sofar > candid:
            ans = j+1
            min_sofar = candid
        
    print(int(ans))

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_ = 10**10
    index = 0
    for j in range(M):
        if abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1]) < min_:
            index = j+1
            min_ = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][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)]

ans=[]
for i in range(n):
    MIN=10**10
    index=0
    for g in range(m):
        if MIN>abs(ab[i][0]-cd[g][0])+abs(ab[i][1]-cd[g][1]):
            MIN=abs(ab[i][0]-cd[g][0])+abs(ab[i][1]-cd[g][1])
            index=g+1
    ans.append(index)

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

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):
    #brute force over all checkpoints
    dist=float('inf')
    for j in range(m):
        dist=min(dist,abs(a[i]-c[j])+abs(b[i]-d[j]))
    for j in range(m):
        if dist==abs(a[i]-c[j])+abs(b[i]-d[j]):
            print(1+j)
            break

Submission status: Accepted

Solution code:
import math
N, M = map(int,input().split())
st = dict()
cp = dict()
for i in range(N):
    st[i+1] = list(map(int,input().split()))

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

for k in st.keys():
    a, b = st[k]
    ans = dict()
    for l in cp.keys():
        c, d = cp[l]
        pi = abs(a-c) + abs(b-d)
        ans[l] = pi
    st[k] = min(ans,key=ans.get)
        

for m in st.keys():
    print(st[m])

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
Ls = []
Lp = []
for i in range(N):
    a,b = map(int,input().split())
    Ls.append([a,b])
for m in range(M):
    c,d = map(int,input().split())
    Lp.append([c,d])
for i in range(N):
    dis = []
    for m in range(M):
        dis.append(abs(Ls[i][0]-Lp[m][0])+abs(Ls[i][1]-Lp[m][1]))
    print(dis.index(min(dis))+1)

Submission status: Accepted

Solution code:
from collections import defaultdict

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

aa = []
bb = []
cc = []
dd = []
answer = []

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

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

for i in range(n):
    ans = float('inf')
    for j in range(m):
        distance = abs(aa[i]-cc[j]) + abs(bb[i]-dd[j])
        if ans > distance:
            ans = min(distance, ans)
            num = j+1
    answer.append(num)

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

Submission status: Accepted

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

for i in a:
    mn = 10 ** 9
    record = 0
    for j, v in enumerate(c):
        temp = abs(i[0] - v[0]) + abs(i[1] - v[1])
        if temp < mn:
            mn = temp
            record = j + 1
    print(record)

Submission status: Accepted

Solution code:
N,M = map(int,input().split(" "))
students = [tuple(map(int,input().split(" "))) for _ in range(N)]
checkpoints = [tuple(map(int,input().split(" "))) for _ in range(M)]
Ans = [(0,4*(10**8))]*N

# print(students)
# print(checkpoints)

i = 0
for n in students:
    j=0
    for m in checkpoints:
        j+=1
        dist = abs(n[0]-m[0])+abs(n[1]-m[1])
        if dist<Ans[i][1]:
            Ans[i] = (j,dist)
    i+=1
    
# print(Ans)

for ans in Ans:
    print(ans[0])

Submission status: Accepted

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

st = []
for n in range(N):
  st.append(list(map(int, input().split())))

cs = []
for m in range(M):
  cs.append(list(map(int, input().split())))
  
for n in range(N):
  min_d = 100000000000000
  min_i = -1
  for m in range(M):
    d = abs(st[n][0]-cs[m][0]) + abs(st[n][1]-cs[m][1])
    if d < min_d:
      min_d = d
      min_i = m
  print(min_i+1)

Submission status: Accepted

Solution code:
#ABC057.B
N,M = map(int,input().split())
L1 = []
L2 = []

for i in range(N):
    a,b = map(int,input().split())
    L1.append([a,b])
for m in range(M):
    c,d = map(int,input().split())
    L2.append([c,d])

for j in range(N):
    L3 = []
    for l in range(M):
        L3.append(abs(L1[j][0]-L2[l][0]) + abs(L1[j][1]-L2[l][1]))
    print(L3.index(min(L3))+1)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
slist = []
plist = []

for i in range(N):
  a, b = map(int, input().split())
  slist.append([a,b])  
  
for i in range(M):
  c, d = map(int, input().split())
  plist.append([c,d])

for i in range(N):
  list = []
  for j in range(M):
    list.append(abs(slist[i][0] - plist[j][0]) + abs(slist[i][1] - plist[j][1]))
  print(list.index(min(list)) + 1)

Submission status: Accepted

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

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

li = [[0] * m for _ in range(n)]

for i in range(n):
    for j in range(m):
        li[i][j] = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])

for i in range(n):
    print(li[i].index(min(li[i]))+1)

Submission status: Accepted

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

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

for i in range(N):
    ans = 0
    a = a_b[i][0]
    b = a_b[i][1]

    for j in range(M):
        c_ans = c_d[ans][0]
        d_ans = c_d[ans][1]
        c = c_d[j][0]
        d = c_d[j][1]
        
        if abs(a-c) + abs(b-d) < abs(a-c_ans) + abs(b-d_ans):
             ans = j
    print(ans+1)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n, m = map(int,input().split())
ab = []
for i in range(n):
    ab.append([int(i) for i in input().split()])
cd = []
for i in range(m):
    cd.append([int(i) for i in input().split()])

for i in range(n):
    inf = pow(10, 15)
    for j in range(m):
        if abs(cd[j][0] - ab[i][0]) + abs(cd[j][1] - ab[i][1]) < inf:
            inf = abs(cd[j][0] - ab[i][0]) + abs(cd[j][1] - ab[i][1])
            ans = j + 1
    print(ans)

Submission status: Accepted

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

for x, y in student:
    d = 10 ** 18
    ans = -1
    for i, (a, b) in enumerate(check):
        if d > abs(x - a) + abs(y - b):
            d = abs(x - a) + abs(y - b)
            ans = i+1
    print(ans)

Submission status: Accepted

Solution code:
n,m = [int(x) for x in input().split()]
ab = []
cd = []
for _ in range(n):
    tmp = [int(x) for x in input().split()]
    ab.append(tmp)
for _ in range(m):
    tmp = [int(x) for x in input().split()]
    cd.append(tmp)

for i in range(n):
    ans = 0
    man = 10**9
    for j in range(m):
        tmp = abs(ab[i][0]-cd[j][0]) + abs(ab[i][1]-cd[j][1])
        if man > tmp:
            man = tmp
            ans = j + 1

    print(ans)

Submission status: Accepted

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


for i in range(n):
    ans = 0
    man = 10 ** 9

    for j in range(m):
        tmp = abs(T1[i][0] - T2[j][0]) + abs(T1[i][1] - T2[j][1])
        if man > tmp:
            man = tmp
            ans = j + 1

    print(ans)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
s = [list(map(int,input().split())) for i in range(n)]
p = [[0,10**18] for i in range(n)]
for j in range(m):
  c,d=map(int,input().split())
  for k in range(n):
    if p[k][1]>(abs(c-s[k][0])+abs(d-s[k][1])):
      p[k][0]=j+1
      p[k][1]=(abs(c-s[k][0])+abs(d-s[k][1]))
for i in range(n):
  print(p[i][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 a, b in ab:
    ans = -1
    m = 10**9
    i = 1
    for c, d in cd:
        t = abs(c-a)+abs(d-b)
        if t < m:
            m = t
            ans = i
        i += 1
    print(ans)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
S=[]
T=[]
for i in range(N):
  S.append(list(map(int,input().split())))
for i in range(M):
  T.append(list(map(int,input().split())))
for i in range(N):
  min=abs(S[i][0]-T[0][0])+abs(S[i][1]-T[0][1])
  num=1
  for j in range(1,M):
    if abs(S[i][0]-T[j][0])+abs(S[i][1]-T[j][1])<min:
      min=abs(S[i][0]-T[j][0])+abs(S[i][1]-T[j][1])
      num=j+1
  print(num)

Submission status: Accepted

Solution code:
n,m=list(map(int,input().split()))
st=[]
for i in range(n):
    a,b=list(map(int,input().split()))
    st.append([a,b])
cp=[]
for j in range(m):
    c,d=list(map(int,input().split()))
    cp.append([c,d])
g=[]
for i in range(n):
    m_dt=abs(st[i][0]-cp[0][0])+abs(st[i][1]-cp[0][1])
    idx=1
    for j in range(1,m):
        dt=abs(st[i][0]-cp[j][0])+abs(st[i][1]-cp[j][1])
        if dt<m_dt:
            m_dt=dt
            idx=j+1
    print(idx)

Submission status: Accepted

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

N,M = list(map(int, input().rstrip().split()))
ab_list = [list(map(int, input().rstrip().split())) for i in range(N)]
cd_list = [list(map(int, input().rstrip().split())) for i in range(M)]
#-----

for a,b in ab_list:
    dist = (10**8)*2*2 + 1
    
    for i,[c,d] in enumerate(cd_list):
        temp_dist = abs(a-c) + abs(b-d)
        
        if dist > temp_dist:
            dist = temp_dist
            check = i

    print(check+1)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
ns = [list(map(int, input().split())) for _ in range(N)]
ms = [list(map(int, input().split())) for _ in range(M)]
for n in ns:
  dmin = 2002002002
  num = -1
  for i, m in enumerate(ms):
    d = abs(n[0]-m[0])+abs(n[1]-m[1])
    if d < dmin:
      dmin = d
      num = i
  print(num+1)

Submission status: Accepted

Solution code:
#abc064 b
n,m=map(int,input().split())
student=[]
checkpoint=[]
for i in range(n):
    x=list(map(int,input().split()))
    student.append(x)
for i in range(m):
    x=list(map(int,input().split()))
    checkpoint.append(x)

for p in student:
    distance=1001001001
    i=1
    ans=0
    for c in checkpoint:
        d=abs(p[0]-c[0])+abs(p[1]-c[1])
        if distance>d:
            distance=d
            ans=i
        i+=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)]
def dist(AB, CD):
  return abs(AB[0]-CD[0]) + abs(AB[1]-CD[1])

for i in range(N):
  d = 10**18; ans = -1;
  for j in range(M):
    tmp = dist(AB[i], CD[j])
    if tmp < d:
      d = tmp; ans = j+1;
  print(ans)

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):
    a, b = map(int, input().split())
    C.append(a)
    D.append(b)

for i in range(n):
    t = 0
    T = []
    for j in range(m):
        t = abs(A[i] - C[j]) + abs(B[i] - D[j])
        T.append(t)
    print(T.index(min(T)) + 1)

Submission status: Accepted

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

ans=[]
ith_checkpt=0

INF=float('inf')
tmp=INF

for i in range(N):
    tmp=INF
    for j in range(M):
        m=abs(H[i][0]-C[j][0])+abs(H[i][1]-C[j][1])
        if m==tmp:
            pass
        if m<tmp:
            tmp=m
            ith_checkpt=j+1
    ans.append(ith_checkpt)
            
for a in ans:
    print(a)

Submission status: Accepted

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

D=[float('inf') for _ in range(N)]
ans=[0]*N
for i in range(M):
    c,d=map(int,input().split())
    for j in range(N):
        a,b=AB[j][0],AB[j][1]
        res=abs(c-a)+abs(d-b)
        if D[j]>res:
            D[j]=res
            ans[j]=i+1
for a in ans:
    print(a)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, a: "List[int]", b: "List[int]", c: "List[int]", d: "List[int]"):
    for i in range(N):
        min_dist = 10**9
        min_index = None
        for j in range(M):
            dist = abs(a[i]-c[j])+abs(b[i]-d[j])
            if dist < min_dist:
                min_dist = dist
                min_index = j
        
        print(min_index+1)


    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    a = [int()] * (N)  # type: "List[int]"
    b = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    c = [int()] * (M)  # type: "List[int]"
    d = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        c[i] = int(next(tokens))
        d[i] = int(next(tokens))
    solve(N, M, a, b, c, d)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# import bisect
# import copy
# import fractions
# import math
# import numpy as np
# from collections import Counter, deque
# from itertools import accumulate,permutations, combinations,combinations_with_replacement,product

def resolve():
    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 A:
        valmin=10**5
        cnt=0
        l=[]
        for j in B:
            l.append(abs(i[0]-j[0])+abs(i[1]-j[1]))
        print(l.index(min(l))+1)





resolve()

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 route(n):
    array=[]
    for i in range(M):
        k=abs(a[n]-c[i])+abs(b[n]-d[i])
        array.append(k)
    e=array.index(min(array))
    return e
for i in range(N):
    print(route(i)+1)

Submission status: Accepted

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

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):
    dis=[-1]*3
    for j in range(m):
        dis[1]=abs(a[i]-c[j])+abs(b[i]-d[j])
        if (dis[0]<0):
            ans[i]=j+1
            dis[2]=dis[1]
        else:
            if (dis[2]>dis[1]):
                ans[i]=j+1
                dis[2]=dis[1]
        dis[0]=dis[1]
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 i in range(n)]
cd = [list(map(int, input().split())) for i in range(m)]

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

Submission status: Accepted

Solution code:
# import sys
# import math
# import decimal
# import queue
# import bisect
# import heapq
# import time
# import itertools
# import collections # queue
# from fractions import Fraction

mod = int(1e9+7)
INF = 1<<29
lINF = 1<<35

def main():
    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())
    cd = [0] * m
    for i in range(m):
        cd[i] = list(map(int,input().split()))
    for i in range(n):
        ans = m+1
        l = INF
        for j in range(m):
            if abs(a[i]-cd[j][0])+abs(b[i]-cd[j][1])<l:
                ans = j+1
                l = abs(a[i]-cd[j][0])+abs(b[i]-cd[j][1])
            elif abs(a[i]-cd[j][0])+abs(b[i]-cd[j][1])==l:
                ans = min(ans,j+1)
        print(ans)
    return

if __name__=='__main__':
    main()

Submission status: Accepted

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,M=MI()
    a=[0]*N
    b=[0]*N
    c=[0]*M
    d=[0]*M
    
    for i in range(N):
        aa,bb=MI()
        a[i]=aa
        b[i]=bb
        
    for i in range(M):
        cc,dd=MI()
        c[i]=cc
        d[i]=dd
        
    def calc(x1,y1,x2,y2):
        return abs(x2-x1)+abs(y2-y1)
    
    def s_calc(x,y):
        temp=10**10
        pos=-1
        for i in range(M):
            l=calc(x,y,c[i],d[i])
            if temp>l:
                temp=l
                pos=i+1
                
        return pos
    
    for i in range(N):
        print(s_calc(a[i],b[i]))
            

main()

Submission status: Accepted

Solution code:
n,m = [int(i) for i in input().split()]
ab = []
for i in range(n):
	array = list(map(int,input().split()))
	ab.append(array)
cd = []
for i in range(m):
	arra = list(map(int,input().split()))
	cd.append(arra)
chk = []
for i in range(n):
	for j in range(m):
		chk.append(abs(ab[i][0]-cd[j][0]) + abs(ab[i][1]-cd[j][1]))
for i in range(n):
	ans = chk[:m]
	#print(ans)
	print(ans.index(min(ans))+1)
	chk = chk[m:]

Submission status: Accepted

Solution code:
#057_B
n,m=map(int,input().split())
ab=[tuple(map(int,input().split())) for _ in range(n)]
cd=[tuple(map(int,input().split())) for _ in range(m)]
for i in range(n):
    a,b=ab[i]
    ans=10**9
    ans_index=-1
    for j in range(m):
        c,d=cd[j]
        if ans>abs(c-a)+abs(d-b):
            ans=abs(c-a)+abs(d-b)
            ans_index=j+1
    print(ans_index)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
stu = []
check = []
for i in range(n):
    stu.append(list(map(int, input().split())))
for i in range(m):
    check.append(list(map(int, input().split())))
for i in stu:
    min_dis = 4 * 10 ** 8 + 1
    for j, k in enumerate(check):
        dis = abs(i[0] - k[0]) + abs(i[1] - k[1])
        if dis < min_dis:
            ans = j + 1
            min_dis = dis
    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 ab in AB:
  ind = 1
  ans = 1
  dist = float('inf')
  for cd in CD:
    temp_dist = abs(ab[0]-cd[0])+abs(ab[1]-cd[1])
    if temp_dist<dist:
      ans = ind
      dist = temp_dist
    ind += 1
  print(ans)

Submission status: Accepted

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

for i in range(N):
  ans = 10**10
  ansIndex = -1
  for j in range(M):
    tmp = abs(X[i][0]-Y[j][0])+abs(X[i][1]-Y[j][1])
    if tmp < ans:
      ans = tmp
      ansIndex = j
  print(ansIndex+1)

Submission status: Accepted

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

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

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