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

def manhattan(x,y):
    return np.abs(x[0]-y[0]) + np.abs(x[1]-y[1])

N,M = map(int,raw_input().split())
students = np.zeros((N,2))
checkpoints = np.zeros((M,2))
for i in range(N):
    students[i][0],students[i][1] = map(int,raw_input().split())
#print a
for j in range(M):
    checkpoints[j][0],checkpoints[j][1] = map(int,raw_input().split())

index = np.zeros(N)
for i in range(N):
    min = 200000000
    for j in range(M):
        d = manhattan(students[i],checkpoints[j])
        if min > d:
            min = d
            index[i] = j
    print (index[i]+1).astype(np.int32)

Submission status: Accepted

Solution code:
import os
import sys


def manhatten(tupleA,tupleB):
	return abs(tupleA[0]-tupleB[0]) + abs(tupleA[1]-tupleB[1])

header = input().split()
N,M = int(header[0]),int(header[1])
students = []
checkpoints = []

for i in range(N):
	student = input().split()
	student = [int(x) for x in student]
	students.append(tuple(student))

for i in range(M):
	checkpoint =input().split()
	checkpoint = [int(x) for x in checkpoint]
	checkpoints.append(tuple(checkpoint))

for student in students:
	distance = []
	for checkpoint in checkpoints:
		d = manhatten(student,checkpoint)
		distance.append(d)
	print(distance.index(min(distance))+ 1)

Submission status: Accepted

Solution code:
import math

def main():
    N, M = tuple(map(int, input().split(' ')))
    man_list = []
    point_list = []
    for i in range(N):
        man_list.append(tuple(map(int, input().split(' '))))
    for i in range(M):
        point_list.append(tuple(map(int, input().split(' '))))

    result = []
    for i, man in enumerate(man_list):
        a, b = man
        min_ = float('inf')
        for j, point in enumerate(point_list):
            c, d = point
            v = abs(a-c)+ abs(b-d)
            if len(result) < i+1:
                min_ = v
                result.append(j+1)
                continue
            if v < min_:
                result[i] = j+1
                min_ = v


    for r in result:
        print('{}'.format(r))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    #infile = open("compprog.txt", mode="r")
    n, m = [int(x) for x in input().split()]
    students = []
    cpoints = []
    for _ in range(n):
        students.append([int(x) for x in input().split()])
    for _ in range(m):
        cpoints.append([int(x) for x in input().split()])
    for student in students:
        res = 1
        closest_dis = man_dis(student[0], cpoints[0][0], student[1], cpoints[0][1])
        for c_idx in range(1, m):
            this_dis = man_dis(student[0], cpoints[c_idx][0], student[1], cpoints[c_idx][1])
            if this_dis < closest_dis:
                closest_dis = this_dis
                res = c_idx + 1
        print(res)
    #infile.close()


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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def dis(c1, c2):
    return abs(c1[0]-c2[0]) + abs(c1[1]-c2[1])

if __name__ == "__main__":
    nums = [int(num) for num in input().split()]
    N = nums[0]
    M = nums[1]
    students = []
    cps = []
    for i in range(N):
        coord = [int(num) for num in input().split()]
        students.append((coord[0], coord[1]))
    for i in range(M):
        coord = [int(num) for num in input().split()]
        cps.append((coord[0], coord[1]))

    cps2 = []
    for s in students:
        idx = -1
        d = 0
        for i, c in enumerate(cps):
            dd = dis(s, c)
            if idx == -1 or d > dd:
                idx = i
                d = dd
        cps2.append(idx+1)

    for c in cps2:
        print(c)

Submission status: Accepted

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

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

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

for i in range(N):
    ans = min(range(M), key=lambda j: abs(a[i] - c[j]) + abs(b[i] - d[j]))
    print(ans + 1)

Submission status: Accepted

Solution code:
from functools import reduce
import sys

n, m = [int(i) for i in input().split(" ")]
student = []
checkpoint = []
for i in range(n):
    student.append([int(i) for i in input().split(" ")])
for i in range(m):
    checkpoint.append([int(i) for i in input().split(" ")])
    
def calc_dist(loc1, loc2):
    return abs(loc1[0]-loc2[0])+abs(loc1[1]-loc2[1])

dist_list = list(map(lambda s: [calc_dist(s, c) for c in checkpoint], student))
near_checkpoint = list(map(lambda d: d.index(min(d)), dist_list))
for x in near_checkpoint:
    print(x+1)

Submission status: Accepted

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

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

student = []
checkpoint = []

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

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

for i in range(0, n):
    dist = 100000000000
    ans_num = 0
    for j in range(0, m):
        if distance(student[i], checkpoint[j]) < dist:
            dist = distance(student[i], checkpoint[j])
            ans_num = j + 1
    print(ans_num)

Submission status: Accepted

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

for x1, y1 in P:
    dist = 10 ** 9
    ans = -1
    for i, (x2, y2) in enumerate(Q):
        if abs(x1 - x2) + abs(y1 - y2) < dist:
            dist = abs(x1 - x2) + abs(y1 - y2)
            ans = i + 1
    print ans

Submission status: Accepted

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

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

student=[]
check=[]
for i in range(0,M):
    a,b=[int(x) for x in input().split()]
    student.append((a,b))

for j in range(0,N):
    c,d=[int(x) for x in input().split()]
    check.append((c,d))


for i in range(0,M):
    dist=distance(student[i],check[N-1])
    num=N-1
    for j in range(0,N):
        k=N-j-1
        if dist>=distance(student[i],check[k]):
            dist=distance(student[i],check[k])
            num=k
    print(num+1)

Submission status: Accepted

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

ans = [0] * n
for i, student in enumerate(students):
    for j, point in enumerate(points):
        distance = abs(student[0] - point[0]) + abs(student[1] - point[1])
        if j == 0:
            mini = distance
        elif distance < mini:
            mini = distance
            ans[i] = j

for num in ans:
    print(num + 1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
std=[]
tgt=[]
for _ in range(n):
    std.append(list(map(int,input().split())))
for _ in range(m):
    tgt.append(list(map(int,input().split())))
for i in range(n):
    lt=100000000000000000
    li=0
    for j in range(m):
        if abs(std[i][0]-tgt[j][0])+abs(std[i][1]-tgt[j][1])<lt:
            lt=abs(std[i][0]-tgt[j][0])+abs(std[i][1]-tgt[j][1])
            li=j
    print(li+1)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N, M = map(int, input().split())
students = []
checkpoints = []
for i in range(N):
    students.append(list(map(int, input().split())))
#print(students)
for i in range(M):
    checkpoints.append(list(map(int, input().split())))
#print(checkpoints)
for i in range(N):
    mincp = -1
    mindist = -1
    for j in range(M):
        dist = abs(students[i][0]-checkpoints[j][0]) + abs(students[i][1]-checkpoints[j][1])
        if mincp == -1:
            mincp = j
            mindist = dist
        else:
            if dist < mindist:
                mindist = dist
                mincp = j
    print("%d" % (mincp+1))

Submission status: Accepted

Solution code:
#ABC057B

n,m=map(int,raw_input().split())
ab=[]
for i in xrange(n):
 a,b=map(int,raw_input().split())
 ab.append([a,b])
cd=[]
for i in xrange(m):
 c,d=map(int,raw_input().split())
 cd.append([c,d])

for i in xrange(n):
 res=-1
 lm=10**9
 for j in xrange(m):
  l=abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
  if l<lm:
   lm=l
   res=j
 print res+1

Submission status: Accepted

Solution code:
import math

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

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

# check point input
check = []
for j in range(m):
    c, d = map(int, input().split())
    check.append([c, d])

# calc
for s in student:
    distance = 10e9
    near = 0
    for index, k in enumerate(check):
        v = math.fabs(s[0] - k[0]) + math.fabs(s[1] - k[1])
        if v < distance:
            distance = v
            near = index + 1
    print(near)

Submission status: Accepted

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

ab = [map(int, raw_input().split()) for _ in xrange(N)]
cd = [map(int, raw_input().split()) for _ in xrange(M)]

for i in xrange(N):
    for j in xrange(M):

        d = abs(ab[i][0]-cd[j][0]) + abs(ab[i][1]-cd[j][1])

        if j == 0:
            t = d
            ans = 1

        elif t > d:
            t = d
            ans = j+1

    print ans

Submission status: Accepted

Solution code:
import math

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

ab = [map(int, raw_input().split()) for _ in xrange(N)]
cd = [map(int, raw_input().split()) for _ in xrange(M)]

for i in xrange(N):
    for j in xrange(M):

        d = abs(ab[i][0]-cd[j][0]) + abs(ab[i][1]-cd[j][1])

        if j == 0:
            t = d
            ans = 1

        elif t > d:
            t = d
            ans = j+1

    print ans

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-


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


n, m = map(int, input().split())
st = [[int(a) for a in input().split()] for _ in range(n)]
cp = [[int(a) for a in input().split()] for _ in range(m)]

for s in st:
    index, dist = 0, 9999999999999999999999
    for i, c in enumerate(cp):
        if distance(s, c) < dist:
            index, dist = i, distance(s, c)
    print(index + 1)

Submission status: Accepted

Solution code:
N, M = [int(v) for v in input().split()]
students = [[int(v) for v in input().split()] for _ in range(N)]
checkpoints = [[int(v) for v in input().split()] for _ in range(M)]

for a, b in students:
    min_d = float("inf")
    ans = None
    for i, (c, d) in enumerate(checkpoints):
        dist = abs(a - c) + abs(b - d)
        if dist < min_d:
            min_d = dist
            ans = i+1
    print (ans)

Submission status: Accepted

Solution code:
# coding: utf-8
import math
num_N, num_M = map(int, input().split())
l_stu = [list(map(int, input().split())) for __ in range(num_N)]
l_che = [list(map(int, input().split())) for __ in range(num_M)]

for stu in l_stu:
    dis_ind = []
    for index, che in enumerate(l_che):
        dis = math.fabs(che[0] - stu[0]) + math.fabs(che[1] - stu[1])
        dis_ind.append([dis, index + 1])

    dis_ind.sort(key=lambda x: (x[0], x[1]))
    print(dis_ind[0][1])

Submission status: Accepted

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

cp=[]
for i in range(m):
    c,d=map(int,input().split())
    cp.append([i+1,c,d])

Q=[]

for i in range(n):
    
    man = 10**8*4

    for j in range(m):

        if abs(cp[j][1]-st[i][0])+abs(cp[j][2]-st[i][1]) < man:
            man = abs(cp[j][1]-st[i][0])+abs(cp[j][2]-st[i][1])
            ans = cp[j][0]

    Q.append(ans)


for i in Q:
    print(i)

Submission status: Accepted

Solution code:
# B-Checkpoints
# 問題URL:http://abc057.contest.atcoder.jp/tasks/abc057_b

N, M = map(int, input().split()) #まずNとMを取得
ABs = [] # 学生のいる座標
CDs = [] #　チェックポイントの座標

# 2行目よりN行分学生の座標を取得してABsに格納
for i in range(N):
    ABs.append([int(x) for x in input().split()])

# 2+N行目よりM行分チェックポイントの座標を取得してCDsに格納
for i in range(M):
    CDs.append([int(x) for x in input().split()])

for a,b in ABs:
    #ABsの中身をa,b、CDsの中身をc,dとして取り出し各チェックポイントごとの距離を測定
    distance = [abs(a-c) + abs(b-d) for c,d in CDs]
    
    #　距離が同じ場合は最も番号が早いものを出力する。=(min()はもともとそのようにできている。早いもの優先）
    #+1はリストは0番目から、チェックポイントは1番目から始まるため
    print(distance.index(min(distance)) + 1)

Submission status: Accepted

Solution code:
from math import *


def read(): return list(map(int, input().split()))


n, m = read()
per = []
for i in range(n):
    per.append(read())

point = []
for i in range(m):
    point.append(read())

for p in per:
    mi = 1145141919
    ans = 0
    for i in range(m - 1, -1, -1):
        d = abs(p[0] - point[i][0]) + abs(p[1] - point[i][1])
        if d <= mi:
            mi = d
            ans = i
    print(ans + 1)

Submission status: Accepted

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


def findshortest(s, checkpoints):
    shortest = 0
    for i in range(1, len(checkpoints)):
        if distance(s, checkpoints[i]) < distance(s, checkpoints[shortest]):
            shortest = i
    return shortest

n, m = map(int, input().split())
students = []
checkpoints = []
for _ in range(n):
    a, b = map(int, input().split())
    students.append((a, b))
for _ in range(m):
    c, d = map(int, input().split())
    checkpoints.append((c, d))

for s in students:
    print(findshortest(s, checkpoints) + 1)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
pos = []
che = []
for i in range(n):
    a, b = map(int,input().split())
    pos.append([a,b])
for i in range(m):
    a, b = map(int,input().split())
    che.append([a,b])
 
for i in range(n):
    dis = []
    for j in range(m):
        dis.append(abs(pos[i][0]-che[j][0])+abs(pos[i][1]-che[j][1]))
    print(dis.index(min(dis))+1)

Submission status: Accepted

Solution code:
import math
n,m=map(int,raw_input().split())
a=[]
b=[]
for i in range(n):
	ia,ib=map(int,raw_input().split())
	a.append(ia)
	b.append(ib)
c=[]
d=[]
for i in range(m):
	ic,id=map(int,raw_input().split())
	c.append(ic)
	d.append(id)
for i in range(n):
	dist=10**9
	ans=0
	for j in range(m):
		ndist=abs(a[i]-c[j])+abs(b[i]-d[j])
		if ndist<dist:
			dist=ndist
			ans=j+1
	print ans

Submission status: Accepted

Solution code:
#!/usr/bin/env python

nm = [int(i) for i in input().split()]
n = nm[0]
m = nm[1]

a = list()
b = list()
c = list()
d = list()

for i in range(n):
    ab = [int(tmp) for tmp in input().split()]
    a.append(ab[0])
    b.append(ab[1])

for j in range(m):
    cd = [int(tmp) for tmp in input().split()]
    c.append(cd[0])
    d.append(cd[1])

for i in range(n):
    min_dist = abs(a[i]-c[0]) + abs(b[i]-d[0])
    checkpoint = 1
    for j in range(m):
        cur_dist = abs(a[i]-c[j]) + abs(b[i]-d[j])
        if min_dist > cur_dist:
            min_dist = cur_dist
            checkpoint = j + 1
    print(checkpoint)

Submission status: Accepted

Solution code:
import sys, array, re, functools
input = lambda: sys.stdin.readline()
@functools.lru_cache(maxsize = 10000)

def Main():
  N, M = map(int , input().split())
  A, B, C, D = [], [], [], []
  for _ in range(N):
    x, y = map(int , input().split())
    A.append(x)
    B.append(y)

  for _ in range(M):
    x, y = map(int, input().split())
    C.append(x)
    D.append(y)
    
  cnt  = 0
  res = []
  zemi = []
  mn = 123456789256913
  
  bal = 0
  sal = M
  rez = []
  zakia , zemi = [], []
  for i in range(N):
    for j in range( M):
      X = abs(A[i] - C[j]) + abs(B[i] - D[j])
      zemi.append(X)
    zakia = zemi
    # zemi.sort()
    chk = min(zemi)
    # print(zakia, len(zakia),  chk)
    
    for l in range(len(zakia)):
      if chk == zakia[l]:
        # print(zakia[l])
        rez.append(l+1)
        break
    
    zemi.clear()
 
  for i in range(len(rez)):
    print(rez[i])
  

if __name__ == '__main__':
  Main()

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
data1 = [list(map(int, input().split())) for i in range(n)]
data2 = [list(map(int, input().split())) for i in range(m)]
def d(i,j):
  return abs(data1[i][0] - data2[j][0]) + abs(data1[i][1] - data2[j][1])
for i in range(n):
  rv = d(i,0)
  rj = 0
  for j in range(1,m):
    v = d(i,j)  
    if v < rv:
      rv = v
      rj = j
  print(rj+1)

Submission status: Accepted

Solution code:
from sys import stdin 
n,m = map(int,stdin.readline().split())
a = []
b = []
valid = [0] * m
for i in xrange(n):
    x,y = map(int,stdin.readline().split())
    a.append((x,y))
for i in xrange(m):
    x,y = map(int,stdin.readline().split())
    b.append((x,y))
for i in xrange(n):
    ans = 10**18 
    ind = -1
    for j in xrange(m):
        #if valid[j]:
         #   continue 
        fir = a[i][0] - b[j][0]
        sec = a[i][1] - b[j][1]
        if fir < 0:
            fir = -fir 
        if sec < 0:
            sec = -sec
        if fir + sec < ans:
            ans = fir + sec 
            ind = j 
    print ind + 1 
    #valid[j] = 1

Submission status: Accepted

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

a=[]
b=[]
c=[]
d=[]

for i in range(0, n):
    x,y = map(int, input().split(" "))
    a.append(x)
    b.append(y)

for i in range(0, m):
    x,y = map(int, input().split(" "))
    c.append(x)
    d.append(y)

for i in range(0, n):
    v = -1
    index = 0
    for j in range(0, m):

        l=abs(a[i] - c[j]) + abs(b[i] - d[j])
        if v == -1 or v > l:
            index = j
            v = l
    print(index + 1)

Submission status: Accepted

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

N, M = [int(x) for x in input().split()]
ABs = []
for n in range(N):
    ABs.append([int(x) for x in input().split()])
CDs = []
for m in range(M):
    CDs.append([int(x) for x in input().split()])
for a, b in ABs:
    dists = [abs(a - c) + abs(b - d) for c, d in CDs]
    print(dists.index(min(dists)) + 1)

Submission status: Accepted

Solution code:
import numpy as np

N, M= list(map(int, raw_input().split()))
student = [list(map(int, raw_input().split())) for i in range(N)]
checkpoint = [list(map(int, raw_input().split())) for i in range(M)]

student = np.array(student)
checkpoint = np.array(checkpoint)

for i in range(N):
    print(np.abs(checkpoint - student[i]).sum(axis=1).argmin()+1)

Submission status: Accepted

Solution code:
n,m=map(int,raw_input().split())
stu=[]
point=[]


for i in xrange(n):
    stu.append(map(int,raw_input().split()))
for j in xrange(m):
    point.append(map(int,raw_input().split()))


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



for co in stu:
    ctr=1
    l=[]
    for po in point:
        l.append((dis(po,co),ctr))
        ctr+=1
    l.sort()
    print l[0][1]

Submission status: Accepted

Solution code:
n, m = map(int, raw_input().split())
lx, ly, lxx, lyy = [], [], [], []
for i in range(n):
	x, y = map(int, raw_input().split())
	lx.append(x)
	ly.append(y)

for i in range(m):
	x, y = map(int, raw_input().split())
	lxx.append(x)
	lyy.append(y)

for i in range(n):
	mi = 10000000000
	note = 0
	for j in range(m):
		if abs(lx[i] - lxx[j]) + abs(ly[i] - lyy[j]) < mi:
			mi = abs(lx[i] - lxx[j]) + abs(ly[i] - lyy[j])
			note = j + 1
	print note

Submission status: Accepted

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

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

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

def query(x):
    res_i = 0
    res = 1e+18 + 7
    for i in range(m):
        dist = abs(a[x] - c[i]) + abs(b[x] - d[i])
        if res > dist:
            res_i = i
            res = dist
    return res_i+1

for i in range(n):
    print(query(i))

Submission status: Accepted

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

    ab = []
    i = 0
    while i < N:
        ab += [tuple(map(int, input().split()))]
        i += 1

    cd = []
    i = 0
    while i < M:
        cd += [tuple(map(int, input().split()))]
        i += 1

    i = 0
    while i < N:
        j = 0
        l = []
        while j < M:
            l.append(abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1]))
            j += 1
        i += 1
        print(l.index(min(l)) + 1)
main()

Submission status: Accepted

Solution code:
import math

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

a, b, c, d = [], [], [], []

for i in xrange(N):
    s = map(int, raw_input().split())
    a.append(s[0])
    b.append(s[1])

for i in xrange(M):
    s = map(int, raw_input().split())
    c.append(s[0])
    d.append(s[1])


ans = 0
t = 0
for i in xrange(N):
    for j in xrange(M):
        if j == 0:
            t = abs(a[i]-c[j]) + abs(b[i]-d[j])
            ans = 1
        elif t > abs(a[i]-c[j]) + abs(b[i]-d[j]):
            t = abs(a[i]-c[j]) + abs(b[i]-d[j])
            ans = j+1
        #print "t = %d" % t
        #print "ans=%d" % ans
    print ans

Submission status: Accepted

Solution code:
def dist(a,b,c,d):
    return abs(a-c)+abs(b-d)

N,M=map(int,raw_input().split())
ns=[]
for i in xrange(N):
    a,b=map(int,raw_input().split())
    ns.append((a,b))
ms=[]
for i in xrange(M):
    c,d=map(int,raw_input().split())
    ms.append((c,d))

for a,b in ns:
    mini=None
    idx=None
    cnt=1
    for c,d in ms:
        
        di = dist(a,b,c,d)
        if di < mini or mini==None:
            idx=cnt
            mini=di
        cnt+=1
    print idx

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):
    cc, dd = list(map(int, input().split()))
    c.append(cc)
    d.append(dd)

ans = []
for i in range(N):
    x = a[i]
    y = b[i]
    ind = 0
    distance = 4*10**8
    for j in range(M):
        if(distance > abs(x - c[j]) + abs(y - d[j])):
            ind = j
            distance = abs(x - c[j]) + abs(y - d[j])
    ans.append(ind)

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python

N,M=map(int,raw_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,raw_input().split())
for j in range(M):
    c[j],d[j]=map(int,raw_input().split())
for i in range(N):
    dist=[0]*M
    for j in range(M):
        dist[j]=abs(a[i]-c[j])+abs(b[i]-d[j])
        #print "student"+str(i)+": distance "+str(dist[j])
    print [i for i,x in enumerate(dist) if x==min(dist)][0]+1

Submission status: Accepted

Solution code:
import numpy as np
N, M = map(int, input().split())
list_coStu = []
list_coChe = []
for i in range(N):
    list_coStu.append(list(map(int, input().split())))
for i in range(M):
    list_coChe.append(list(map(int, input().split())))

#calc distance

for iS in range(len(list_coStu)):
    coStu = np.array(list_coStu[iS])
    min_iC = 0
    d = 4 * 10**8 + 1
    for iC in range(len(list_coChe)):
        coChe = np.array(list_coChe[iC])
        dif = coChe - coStu
        dist = np.sum(np.abs(dif))
        if dist < d:
            min_iC = iC
            d = dist
    print(min_iC + 1)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# get two integers separated with half-width break
N, M = map(int, raw_input().split())
n = []
m = []
for i in range(N):
    n.append(map(int, raw_input().split()))

for i in range(M):
    m.append(map(int, raw_input().split()))

for i in range(N):
    distances = [abs(n[i][0] - m[j][0]) + abs(n[i][1] - m[j][1]) for j in range(M)]
    print(distances.index(min(distances)) + 1)

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 ab_list in ab:
    min_distance = 400000000
    checkpoint = 0
    for cd_list in cd:
        checkpoint += 1
        distance = abs(ab_list[0] - cd_list[0]) + abs(ab_list[1] - cd_list[1])
        if distance < min_distance:
            min_distance = distance
            ans = checkpoint
    print(ans)

Submission status: Accepted

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

for i in range(n):
    res=min(range(m),key=lambda j:abs(a[i]-c[j])+abs(b[i]-d[j]))
    print(res+1)

Submission status: Accepted

Solution code:
import math

N, M = map(int, raw_input().split())
a = []
for i in range(N+M):
    a.append(map(int, raw_input().split()))

b=[]

def mhtn(a,b,c,d):
    return 

for i in range(N):
    best=4*10e8
    num=0
    for j in range(M):
        x=math.fabs(a[i][0]-a[N+j][0])+math.fabs(a[i][1]-a[N+j][1])
        
        if(best>x):
            best=x
            num=j+1
    b.append(num)

for i in b:
    print i

Submission status: Accepted

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

students = []
for i in range(n):
    axis = [int(x) for x in input().split()]
    students.append(axis)

checkpoints = []
for i in range(m):
    axis = [int(x) for x in input().split()]
    checkpoints.append(axis)

ans = []
for s_x, s_y in students:
    distances = []
    for c_x, c_y in checkpoints:
        distances.append(abs(s_x - c_x) + abs(s_y - c_y))
    i_c = 0
    i_d = 4 * 10 ** 8 + 1
    for cnt, distance in enumerate(distances, 1):
        if i_d > distance:
            i_d = distance
            i_c = cnt
        else:
            pass
    ans.append(i_c)

for i in ans:
    print(i)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
a = {}
b = {}
c = {}
d = {} 

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):
    m = 100000000000
    index = 0
    for j in range(M):
        tmp = abs(a[i]-c[j]) + abs(b[i]-d[j])
        if tmp < m:
            m = tmp 
            index = j
    print(index + 1)

Submission status: Accepted

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

a = []
c = []
for i in range(0, N + M):
    s = list(map(int, input().split()))
    if  i < N:
        a.append(s)
    else:
        c.append(s)

for i in range(0, N):
    min_idx = 0
    min_dis = 999999999999
    for j in range(0, M):
        dis = abs(a[i][0] - c[j][0]) + abs(a[i][1] - c[j][1])
        if min_dis > dis:
            min_dis = dis
            min_idx = j + 1
    print(str(min_idx))

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
A = []
for n in range(N):
	a,b = map(int,input().split())
	A.append([a,b])
B = []
for m in range(M):
	l = list(map(int,input().split()))
	l.append(m)
	B.append(l)

for a in A:
	R = min([abs(B[i][0] - a[0]) + abs(B[i][1] - a[1]) for i in range(M)])
	B2 = [b for b in B if abs(b[0] - a[0]) + abs(b[1] - a[1]) == R]
	print(min([b[2] for b in B2]) + 1)

Submission status: Accepted

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


def solve(s_pp, p_pp):
    p_nums = []
    for x, y in s_pp:
        distance = []
        for xx, yy in p_pp:
            n = abs(x - xx) + abs(y - yy)
            distance.append(n)
        min_distance_idx = distance.index(min(distance))
        p_nums.append(min_distance_idx + 1)
    return p_nums


def main():
    students, points = [int(e) for e in input().split()]
    students_ps = []
    points_ps = []

    for _ in range(students):
        x, y = [int(e) for e in input().split()]
        students_ps.append([x, y])
    for _ in range(points):
        x, y = [int(e) for e in input().split()]
        points_ps.append([x, y])
    
    for answer in solve(students_ps, points_ps):
        print(answer)


main()

Submission status: Accepted

Solution code:
def mlen(n,m):
	global M,s,c
	return abs(s[n][0] - c[m][0]) + abs(s[n][1] - c[m][1])

N,M = [int(i) for i in input().split()]
s=[] #position of student
c=[] #position of checkpoint
for i in range(N):
	x,y=[int(i) for i in input().split()]
	s.append([x,y])
for i in range(M):
	x,y=[int(i) for i in input().split()]
	c.append([x,y])
for i in range(N):
	pos = 0
	min = mlen(i,0)
	for j in range(1,M):
		if mlen(i,j) < min:
			pos = j
			min = mlen(i,j)
	print(pos+1)

Submission status: Accepted

Solution code:


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

a=[0 for i in range(n+1)]
b=[0 for i in range(n+1)]
c=[0 for i in range(m+1)]
d=[0 for i in range(m+1)]



for i in range(1,n+1):
    a[i],b[i]=map(int,input().split())
for j in range(1,m+1):
    c[j],d[j]=map(int,input().split())

for i in range(1,n+1):
    min=abs(a[i]-c[1])+abs(b[i]-d[1])+1
    for j in range(1,m+1):
        dis = abs(a[i]-c[j])+abs(b[i]-d[j])
        if dis<min: min=dis ; ans=j
    print(ans)