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())
students = []
for _ in range(N):
    l = list(map(int,input().split()))
    students.append(l)

check_points = []

for _ in range(M):
    l = list(map(int,input().split()))
    check_points.append(l)

minimum_points = 0

for person in students:
    minimum = 10**10
    for i in range(len(check_points)):
        d=abs(person[0]-check_points[i][0])+abs(person[1]-check_points[i][1])
        if minimum > d:
            minimum = d
            minimum_points = i
    print(minimum_points+1)

Submission status: Accepted

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

a_arr = []
b_arr = []
for _ in range(N):
    a, b = map(int, input().split())
    a_arr.append(a)
    b_arr.append(b)
    
c_arr = []
d_arr = []
for _ in range(M):
    c, d = map(int, input().split())
    c_arr.append(c)
    d_arr.append(d)

for n in range(N):
    ans = 0
    min_dis = 4 * 10**8 + 1
    for m in range(M):
        dis = abs(a_arr[n] - c_arr[m]) + abs(b_arr[n] - d_arr[m])
        if dis < min_dis:
            min_dis = dis
            ans = m + 1
    print(ans)

Submission status: Accepted

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

ans = []
for i in range(N):
    tmp = 10**9
    idx = 0
    for j in range(M):
        dist = abs(ab[i][0]-cd[j][0]) + abs(ab[i][1]-cd[j][1])
        if dist < tmp:
            tmp = dist
            idx = j
    ans.append(idx+1)

for a in ans:
    print(a)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# Luis Yoichi Morales January 2019

from sys import stdin
import sys

def manhattan_dist(a, c):
    return  abs(a[0]-c[0]) + abs(a[1]-c[1])



N,M = map( int, raw_input().split() )
#print N, M


a=[]
c=[]
for i in range (N):
    a.append( map(int, stdin.readline().split()) )

for i in range (M):
    c.append( map(int, stdin.readline().split()) )

prev_dist=sys.maxint
index=[]
for i in range (N):
    for j in range (M):
        if prev_dist > manhattan_dist( a[i], c[j] ):
            index = (manhattan_dist( a[i], c[j] ), j+1 )
            prev_dist = manhattan_dist( a[i], c[j] )
    print index[1] 
    prev_dist=sys.maxint

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
posi = [tuple(map(int, input().split())) for _ in range(n)]
goal = [None]+[tuple(map(int, input().split())) for _ in range(m)]
for i in range(n):
    table = [0, float("inf")]
    for j in range(1, m+1):
        d = abs(posi[i][0]-goal[j][0])+abs(posi[i][1]-goal[j][1])
        if d < table[1]:
            table = [j, d]
    print(table[0])

Submission status: Accepted

Solution code:
n,m = (int(i) for i in input().split())
#print(n,m)
#for i in range(n):
mylist1=[[] for i in range(n)]
for i in range(n):
    mylist1[i]=[int(i) for i in input().split()]

mylist2=[[] for i in range(m)]
for i in range(m):
    mylist2[i]=[int(i) for i in input().split()]  

for i in range(n):
    dist= float("inf")
    ans=0
    for j in range(m):
        tmp=abs(mylist1[i][0]-mylist2[j][0])+abs(mylist1[i][1]-mylist2[j][1])
#        print(tmp)
        if tmp < dist:
            ans=j
            dist=tmp
    print(ans+1)

Submission status: Accepted

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

for a, b in AB:
    dist = [abs(a - c) + abs(b - d) for c, d in CD]
    print(dist.index(min(dist)) + 1)

Submission status: Accepted

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

for a, b in AB:
    place = [abs(a - c) + abs(b - d) for c, d in CD]
    print(place.index(min(place)) + 1)

Submission status: Accepted

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

place = [0] * len(AB)
for i, ab in enumerate(AB):
    dist = 10 ** 9
    for j, cd in enumerate(CD):
        tmp = abs(ab[0] - cd[0]) + abs(ab[1] - cd[1])
        if tmp < dist:
            dist = tmp
            place[i] = j + 1
            
for i in place:
    print(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])
for i in range(M):
	c,d = map(int, input().split())
	B.append([c,d])
#print(A,B)

for i in range(N):
	z = A[i]
	ans = []
	for j in range(M):
		ch = B[j]
		d = abs(z[0]-ch[0]) + abs(z[1]-ch[1])
		ans.append([j,d])
	#print(ans)
	ans.sort(key=lambda x:x[1])
	#print(ans)
	print(ans[0][0]+1)

Submission status: Accepted

Solution code:
# coding:utf-8

import sys
# from collections import Counter, defaultdict

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

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


n, m = LI()
ab = [LI() for _ in range(n)]
cd = [LI() for _ in range(m)]

for a, b in ab:
    ans = -1
    dist = INF
    for i in range(m):
        c, d = cd[i]
        tmp = abs(c - a) + abs(d - b)
        if tmp < dist:
            dist = tmp
            ans = i + 1
    print(ans)

Submission status: Accepted

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

ST = [[int(x) for x in input().split()] for y in range(n)]
CH = [[int(x) for x in input().split()] for y in range(m)]

for a, b in ST:
    manhat = [abs(a - c) + abs(b - d) for c, d in CH]
    print(manhat.index(min(manhat)) + 1)

Submission status: Accepted

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

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

for i in range(n):
    li_distance=[abs(lj[j][0]-li[i][0])+abs(lj[j][1]-li[i][1]) for j in range(m)]
    print(li_distance.index(min(li_distance))+1)

Submission status: Accepted

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

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

for i in range(n):
    li_distance=[abs(lj[j][0]-li[i][0])+abs(lj[j][1]-li[i][1]) for j in range(m)]
    print(li_distance.index(min(li_distance))+1)

Submission status: Accepted

Solution code:
N, M = map(int,input().split())
students = []
checkpoints = []
for i in range(N):
    x,y = map(int,input().split())
    students.append([x,y])
for i in range(M):
    x,y = map(int,input().split())
    checkpoints.append([x,y])
ans = []
for i in range(N):
    ans_tmp = [1000000000,-1]
    for q in range(M):
        dist = abs(students[i][0]-checkpoints[q][0]) + abs(students[i][1]-checkpoints[q][1])
        if dist < ans_tmp[0]:
            ans_tmp[0] = dist
            ans_tmp[1] = q
    ans.append(ans_tmp[1]+1)
for k in ans:
    print(k)

Submission status: Accepted

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

def calc(a, b, CD):
    mini, mind = -1, 10**10
    for i, cd in enumerate(CD):
        c, d = cd
        d = abs(c - a) + abs(d - b)
        if d < mind:
            mini, mind = i, d
    return mini + 1

for a, b in AB:
    print(calc(a, b, CD))

Submission status: Accepted

Solution code:
n, m = [int(x) for x in input().split()]
a = [[int(x) for x in input().split()] for y in range(n)]
b = [[int(x) for x in input().split()] for y in range(m)]

for ai in a:
    n = [abs(ai[0] - bi[0]) + abs(ai[1] - bi[1]) for bi in b]
    print(n.index(min(n)) + 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)]

ans = [0 for i in range(n)]
for i in range(n):
    distance = 1e16
    tmp_ans = 1
    for j in range(m):
        tmp_dis = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
        if distance > tmp_dis:
            distance = tmp_dis
            tmp_ans = j + 1
    print(tmp_ans)

Submission status: Accepted

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

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

for i in range(n):
    min = 200000001
    p = 1
    for j in range(m):
        z = abs(a[i] - c[j]) + abs(b[i] - d[j])
        if z < min:
            min = z
            p = j + 1

    print(p)

Submission status: Accepted

Solution code:
# 057 B
N, M = [int(x) for x in input().split()]
#print(N,M)#
st = []
for i in range(N):
    st.append([int(x) for x in input().split()])
cp = []
for i in range(M):
    cp.append([int(x) for x in input().split()])
#    st[i][0], st[i][1] =  [int(x) for x in input().split()]
#print(st)#
#print(cp)#
for i in range(N):
    mindist = 10**9
    for j in range(M):
        d = abs(cp[j][0]-st[i][0]) + abs(cp[j][1]-st[i][1])
        if d<mindist: 
            mindist = d
            nth = j
    print(nth+1)

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
p=[list(map(int,input().split()))for i in range(a)]
q=[list(map(int,input().split()))for i in range(b)]
for i in range(a):
    r=[]
    for j in range(b):
        r.append([abs(p[i][0]-q[j][0])+abs(p[i][1]-q[j][1]),j+1])
    else:
        r.sort()
        print(r[0][1])

Submission status: Accepted

Solution code:
n,m = (int(i) for i in input().split())
x =[]
checkpoint =[]
for i in range(n):
  tmp =list(int(i) for i in input().split())
  x.append(tmp)
for j in range(m):
  tmp = list(int(i) for i in input().split())
  checkpoint.append(tmp)

for i in range(n):
  destrange = []
  for j in range(m):
    #各学生とチェックポイントとの距離をだす
    rang = abs(x[i][0]-checkpoint[j][0])+abs(x[i][1]-checkpoint[j][1])
    destrange.append(rang)
  print(destrange.index(min(destrange))+1)

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

point = [0] * N

for i in range(N):
    tmp = 300000000
    for j in range(M):
        l = abs(c[j] - a[i]) + abs(d[j] - b[i])
        if tmp > l:
            point[i] = j + 1
            tmp = l
    print(point[i])

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
A,B,C,D = [],[],[],[]
for i in range(N):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
for i in range(M):
    c,d = map(int,input().split())
    C.append(c)
    D.append(d)

Ans = []
for i in range(N):
    d = 10**9
    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])
            ans = j
    Ans.append(ans)

# 0-indexedなので出力時に+1
for ans in Ans:
    print(ans+1)

Submission status: Accepted

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

for i in range(n):
    distance = 10**9
    ans = 0
    for j in range(m):
        temp_dictance = abs(students[i][0]-check_point[j][0]) + abs(students[i][1]-check_point[j][1])
        if temp_dictance < distance:
            distance = temp_dictance
            ans = j+1
    print(ans)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
persons = []
chechpoints = []
for i in range(N):
    a = list(map(int,input().split()))
    persons.append(a)
for j in range(M):
    a = list(map(int,input().split()))
    chechpoints.append(a)

for i in range(N):
    x = persons[i][0]
    y = persons[i][1]
    distance = []
    for j in range(M):
        distance_j = abs(x-chechpoints[j][0])+abs(y-chechpoints[j][1])
        distance.append(distance_j)
    print(distance.index(min(distance))+1)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N,M = map(int,input().split())
persons = []
chechpoints = []
for i in range(N):
    a = list(map(int,input().split()))
    persons.append(a)
for j in range(M):
    a = list(map(int,input().split()))
    chechpoints.append(a)

for i in range(N):
    x = persons[i][0]
    y = persons[i][1]
    distance = []
    for j in range(M):
        distance_j = abs(x-chechpoints[j][0])+abs(y-chechpoints[j][1])
        distance.append(distance_j)
    print(distance.index(min(distance))+1)

Submission status: Accepted

Solution code:
while(True):
    try:
        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)]
    except EOFError:
        exit()
    for a, b in ab:
        dist = [abs(a - c) + abs(b - d) for c, d in cd]
        print(dist.index(min(dist)) + 1)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=[[int(j) for j in input().split()] for i in range(n)]
c=[[int(j) for j in input().split()] for i in range(m)]
for i in range(n):
    d=10e8
    b=0
    for j in range(m):
        if abs(a[i][0]-c[j][0])+abs(a[i][1]-c[j][1])<d:
            d=abs(a[i][0]-c[j][0])+abs(a[i][1]-c[j][1])
            b=j+1
    print(b)

Submission status: Accepted

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

for i in range(n):
    mi=1000000000
    for j in range(m):
        if abs(c[j]-a[i])+abs(d[j]-b[i])<mi:
            mi=abs(c[j]-a[i])+abs(d[j]-b[i])
            an=j+1
    ans.append(an)
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):
        ans=0
        tmp=300000000
        for j in range(M):
                l=abs(a[i]-c[j])+abs(b[i]-d[j])
                if tmp>l:
                        ans=j+1
                        tmp=l
        print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = []
B = []
C = []
D = []
for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
for j in range(M):
    c, d = map(int, input().split())
    C.append(c)
    D.append(d)
for i in range(N):
    mdis_j = 1
    mdis = 10**9
    for j in range(M):
        tmp = abs(A[i]-C[j])+abs(B[i]-D[j])
        if mdis > tmp:
            mdis_j = j+1
            mdis = tmp
    print(mdis_j)

Submission status: Accepted

Solution code:
int_n, int_m = map(int, input().split())

li_n = list()
li_m = list()

for i in range(int_n):
    li_n.append(list(map(int, input().split())))

for i in range(int_m):
    li_m.append(list(map(int, input().split())))


for n in li_n:
    l_dis = [abs(n[0] - m[0]) + abs(n[1] - m[1]) for m in li_m]

    minimum = min(l_dis)
    print(l_dis.index(minimum) + 1)

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:
    tmp = 10 ** 10
    for i, C in enumerate(check):
        cx, cy = C[0], C[1]
        man = abs(x-cx)+abs(y-cy)
        if tmp > man:
            tmp = man
            ans = i
    print(ans + 1)

Submission status: Accepted

Solution code:
def abc057_b():
    n, m = map(int, input().split())
    ab = [list(map(int, input().split())) for _ in range(n)]
    cd = [list(map(int, input().split())) for _ in range(m)]

    for i in range(n):
        tmp_index = 0
        d = 10 ** 9
        for j in range(m):
            tmp_d = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
            if tmp_d < d:
                tmp_index = j
                d = tmp_d
        print(tmp_index + 1)


abc057_b()

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
al=[]
bl=[]
ansl=[]
for i in range(n):
  al.append(input())
for i in range(m):
  bl.append(input())
for i in range(n):
  a1,a2=map(int,al[i].split())
  b1,b2=map(int,bl[0].split())
  mi=dis=abs(b1-a1)+abs(b2-a2)
  c=1
  for j in range(1,m):
    b1,b2=map(int,bl[j].split())
    dis=abs(b1-a1)+abs(b2-a2)
    if mi>dis:
      mi=dis
      c=j+1
  ansl.append(c)
for i in range(len(ansl)):
  print(ansl[i])

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
x1 = []
y1 = []
x2 = []
y2 = []
for i in range(a):
    x, y = map(int, input().split())
    x1.append(x)
    y1.append(y)


for j in range(b):
    x, y = map(int, input().split())
    x2.append(x)
    y2.append(y)
ans = -1
min=1000000000000
for i in range(a):
    for j in range(b):
        xx = x1[i] - x2[j]
        yy = y1[i] - y2[j]
        if(xx<0):
            xx= -xx
        if(yy<0):
            yy = -yy
        if(xx+yy<min):
            min=xx+yy
            ans=j+1
    print(ans)
    min = 100000000000
    ans=-1

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
ans=10**9
tmp_ans=10**9
prin=0
a=[]
b=[]
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())
    b.append([x,y])
for i in range(n):
    tmp_x=a[i][0]
    tmp_y=a[i][1]
    for j in range(m):
        ans=min((abs(tmp_x-b[j][0])+abs(tmp_y-b[j][1])),ans)
        if tmp_ans!=ans:
            prin=j+1
            tmp_ans=ans
    print(prin)
    ans=10**9
    tmp_ans=10**9

Submission status: Accepted

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

for a, b in ab:
    ans = 0
    temp_min = float("inf")
    for i, (c, d) in enumerate(cd):
        dist = abs(a - c) + abs(b - d)
        if dist < temp_min:
            ans = i + 1
            temp_min = dist
        
    print(ans)

Submission status: Accepted

Solution code:
T = input().rstrip().split(" ")
N = int(T[0])
M = int(T[1])
ss = []
for i in range(N):
    T = input().rstrip().split(" ")
    ss.append(T)
dd = []
for i in range(M):
    T = input().rstrip().split(" ")
    dd.append(T)
ans = []
for i in range(N):
    px = int(ss[i][0])
    py = int(ss[i][1])
    list = []
    for j in range(M):
        dx = int(dd[j][0])
        dy = int(dd[j][1])
        MD = abs(px - dx) + abs(py - dy)
        list.append(MD)
    ans.append(list.index(min(list))+1)
for i in range(len(ans)):
    print(ans[i])

Submission status: Accepted

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


def main():
    """Function."""
    n, m = map(int, input().split())

    n_map, m_map = [], []
    for _ in range(n):
        n_map.append(list(map(int, input().split())))
    for _ in range(m):
        m_map.append(list(map(int, input().split())))

    for st in n_map:
        min_index = 1
        min_val = abs(st[1] - m_map[0][1]) + abs(st[0] - m_map[0][0])
        counter = 1
        for pl in m_map:
            temp = abs(st[1] - pl[1]) + abs(st[0] - pl[0])
            if temp < min_val:
                min_val = temp
                min_index = counter
            counter += 1
        print(min_index)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

result = []
for s in S:
  a = s[0]
  b = s[1]
  for p in P:
    c = p[0]
    d = p[1]
    direct = abs(a-c)+abs(b-d)
    result.append(direct)
  point = min(result)
  print(result.index(point) + 1)
  result = []

Submission status: Accepted

Solution code:
N, M = [ int(i) for i in input().split() ]
students = []
for i in range(N):
    students.append([int(i) for i in input().split()])
points = []
for i in range(M):
    points.append([int(i) for i in input().split()])
for x, y in students:
    shortest = 2000000000
    index = 0
    for j, (xx, yy) in enumerate(points):
        l = abs(x-xx) + abs(y-yy)
        if l < shortest:
            shortest = l
            index = j
    print(index+1)

Submission status: Accepted

Solution code:
def dist(p0, p1):
    return abs(p0[0] - p1[0]) + abs(p0[1] - p1[1])


def main():
    n, m = map(int, input().split())
    ss = [list(map(int, input().split())) for _ in range(n)]
    pp = [list(map(int, input().split())) for _ in range(m)]
    for i in range(n):
        d_min = dist(ss[i], pp[0])
        d_min_j = 0
        for j in range(1, m):
            d = dist(ss[i], pp[j])
            if d < d_min:
                d_min = d
                d_min_j = j
        print(d_min_j + 1)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

for i in range(n):
    _min = [10 ** 10, 0]
    for j in range(m):
        if abs(a[i][0] - c[j][0]) + abs(a[i][1] - c[j][1]) < _min[0]:
            _min[0] = abs(a[i][0] - c[j][0]) + abs(a[i][1] - c[j][1])
            _min[1] = j + 1
    print(_min[1])

Submission status: Accepted

Solution code:
N,M = [int(i) for i in input().split()]
student_location = []
for i in range(N) :
    student_location.append([int(i) for i in input().split()])

checkpoint_location = []
for i in range(M) :
    checkpoint_location.append([int(i) for i in input().split()])

for student_loc in student_location :
    min_distance = 9999999999
    min_distance_index = -1
    index = 0
    for checkpoint_loc in checkpoint_location :
        index += 1
        d = abs(student_loc[0] - checkpoint_loc[0]) + abs(student_loc[1] - checkpoint_loc[1])
        if (d < min_distance) :
            min_distance = d
            min_distance_index = index
    # print([d,index])
    print(min_distance_index)

Submission status: Accepted

Solution code:
N, M = [int(i) for i in 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)]

ls1 = []
for i in range(N):
    ls2 = []
    for j in range(M):
        ls2.append(abs(A[i][0] - C[j][0]) + abs(A[i][1] - C[j][1]))
    a = min(ls2)
    ls1.append(ls2.index(a))
for i in ls1:
    print(i+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:
  dis=[abs(a-c)+abs(b-d) for c,d in CD]
  print(dis.index(min(dis))+1)

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 x in range(n):
    e = []
    for y in range(m):
        e.append(abs(ab[x][0]-cd[y][0]) + abs(ab[x][1]-cd[y][1]))

    print(e.index(min(e))+1)

Submission status: Accepted

Solution code:
N, M = map(int, raw_input().split())
a = []
b = []
for i in range(N):
    _a, _b = map(int, raw_input().split())
    a.append(_a)
    b.append(_b)
c = []
d = []
for i in range(M):
    _c, _d = map(int, raw_input().split())
    c.append(_c)
    d.append(_d)

dist = [[float("inf")] * M for i in range(N)]
for i in range(N):
    for j in range(M):
        dist[i][j] = abs(a[i] - c[j]) + abs(b[i] - d[j])
for i in range(N):
    print dist[i].index(min(dist[i])) + 1

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
ab = []
for i in range(n):#h:高さ
    ab.append([int(m) for m in input().split()])
cd = []
for i in range(m):#h:高さ
    cd.append([int(m) for m in input().split()])
dis = [float("inf")]*n
dn = [-1]*n
for i in range(n):
    for j in range(m):
        t = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
        if t < dis[i]:
            dis[i] = t
            dn[i] = j
    print(dn[i] + 1)

Submission status: Accepted

Solution code:
N, M = [int(_) for _ in input().split()]
AB = [[int(_) for _ in input().split()] for _ in range(N)]
C = [[int(_) for _ in input().split()] + [_+1] for _ in range(M)]
for a, b in AB:
    ans = []
    for c in C:
        ans += [[(abs(c[0]-a)+abs(c[1]-b))*100+c[2], c[2]]]
    print(sorted(ans)[0][1])

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
s_p=[list(map(int,input().split()))for i in range(n)]
c_p=[list(map(int,input().split()))for i in range(m)]
for s in s_p:
    d=abs(c_p[0][0]-s[0])+abs(c_p[0][1]-s[1])
    a=1
    for i in range(1,m):
        if d>abs(c_p[i][0]-s[0])+abs(c_p[i][1]-s[1]):
            a=i+1
            d=abs(c_p[i][0]-s[0])+abs(c_p[i][1]-s[1])
    print(a)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
A = []
B = []
C = []
D = []
for i in range(N):
    x,y = map(int,input().split())
    A.append(x)
    B.append(y)
for i in range(M):
    x,y = map(int,input().split())
    C.append(x)
    D.append(y)
k = 0
for i in range(N):
    g = 100000000000
    for j in range(M):
        t = abs(A[i]-C[j])+abs(B[i]-D[j])
        
        if t < g:
            k = j+1
            g = t
    print(k)

Submission status: Accepted

Solution code:
# https://beta.atcoder.jp/contests/abc057/tasks/abc057_b
class Point(object):
    def __init__(self, x, y):
        self.x = int(x)
        self.y = int(y)

    @staticmethod
    def manhattan(p1, p2):
        return abs(p1.x - p2.x) + abs(p1.y - p2.y)

def solve():
    # Max(n, m) = (50, 50) => 50 * 2
    n, m = map(int, input().split())
    students = []
    for _ in range(n):
        students.append(Point(*input().split()))

    checkpoints = []
    for _ in range(m):
        checkpoints.append(Point(*input().split()))

    for student in students:
        min_dist = 4 * (10 ** 8)
        min_index = 1
        for index, cp in enumerate(checkpoints):
            manhattan = Point.manhattan(student, cp)
            if min_dist > manhattan:
                min_dist = manhattan
                min_index = index + 1
        print(min_index)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
a=list(map(int,input().split()))
N=a[0]
M=a[1]
posx=[]
posy=[]
for i in range(N):
    x1,y1=[int(i) for i in input().split()]
    posx.append(x1)
    posy.append(y1)
students=[10**9]*N
aim=[0,]*N
for i in range(M):
    pointx,pointy=[int(i) for i in input().split()]
    for j in range(N):
        if students[j] > abs(pointx-posx[j]) + abs(pointy-posy[j]):
            students[j] = abs(pointx-posx[j]) + abs(pointy-posy[j])
            aim[j]=i+1
for i in range(N):
    print(str(aim[i]))

Submission status: Accepted

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

for a,b in students:
    m_dis = [abs(a-c) + abs(b-d) for c,d in c_points]
    print(m_dis.index(min(m_dis)) + 1)

Submission status: Accepted

Solution code:
# coding: utf-8
def manhattan(x1, y1, x2, y2):
    return abs(x1-x2) + abs(y1-y2)

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

for s in students:
    val = 400000001
    ans = 0
    a, b = map(int, s.split())
    for j, c in enumerate(c_points):
        c, d = map(int, c.split())
        m_dis = manhattan(a,b,c,d)
        if m_dis < val:
            val = m_dis
            ans = j+1
    print(ans)

Submission status: Accepted

Solution code:
def man(a,b):
    return abs(a[0]-b[0])+abs(a[1]-b[1])
n,m=map(int,input().split())
ab=[]
for i in range(n):
    ab.append(list(map(int,input().split())))
cd=[]
for j in range(m):
    cd.append(list(map(int,input().split())))
for i in range(n):
    ans=0
    dis=man(ab[i],cd[0])
    for j in range(m):
        if dis >man(ab[i],cd[j]):
            ans = j
            dis = man(ab[i],cd[j])
    print(ans+1)

Submission status: Accepted

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

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

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

ans = []

for i, p in enumerate(st):
	l = 500000000
	ans.append(0)
	
	for j, d in enumerate(ch):
		if abs(p[0] - d[0]) + abs(p[1] - d[1]) < l:
			ans[i] = j + 1
			l = abs(p[0] - d[0]) + abs(p[1] - d[1])
		
		
for a in ans:
	print(a)

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 s in students:
    min_distance = 4 * 10**8 + 1
    for i, c in enumerate(checkpoints):
        distance = abs(s[0] - c[0]) + abs(s[1] - c[1]) 
        if min_distance > distance:
            min_distance = distance
            point = i+1
    print(point)