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:


def dist(v1, v2):
    return abs(v1[0] - v2[0]) + abs(v1[1] - v2[1])


N, M = (int(e) for e in input().split())

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

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

for i in students:
    min_dist = 1e9
    to = None
    for j, cp in enumerate(checkpoints):
        d = dist(i, cp)
        if min_dist > d:
            to = j+1
            min_dist = d
    print(to)

Submission status: Accepted

Solution code:
def solve():
  ar = raw_input().split(' ')
  N = int(ar[0])
  M = int(ar[1])
  sts = []
  for n in range(N) :
    ar = raw_input().split(' ')
    a = int(ar[0])
    b = int(ar[1])
    sts.append((a, b))
  cks = []
  for m in range(M) :
    ar = raw_input().split(' ')
    c = int(ar[0])
    d = int(ar[1])
    cks.append((c, d))

  for st in sts :
    #print st
    mind = float('inf')
    mini = -1
    for i in range(M):
      ckx = cks[i][0]
      cky = cks[i][1]
      d = abs(st[0] - ckx) + abs(st[1] - cky)
      #print 'd=',d
      if d < mind :
        mind = d
        mini = i
    #print 'mind=',mind, ',mini=',mini 
    print mini + 1

if __name__ == '__main__':
  solve()

Submission status: Accepted

Solution code:
class Point:
	def __init__(self, x, y):
		self.x = x
		self.y = y

	def getDistance(self, to):
		return abs(self.x - to.x) + abs(self.y - to.y)

	def __repr__(self):
		return "({0}, {1})".format(self.x, self.y)

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

a = []
c = []
for _ in range(N):
	x, y = [int(p) for p in input().split(" ")]
	a.append(Point(x, y))

for _ in range(M):
	x, y = [int(p) for p in input().split(" ")]
	c.append(Point(x, y))

for a_i in a:
	min_d = 250000000
	min_i = 0
	for i in range(len(c)):
		d = a_i.getDistance(c[i])
		if d < min_d:
			min_d = d
			min_i = i
	print(min_i + 1)

Submission status: Accepted

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

#N = n[0]
#M = n[1]
n_list = []
m_list = []

for i in range(int(N)):
    tmp_n_list = []
    num = input()
    tmp_num = num.split()
    tmp_n_list.append(int(tmp_num[0]))
    tmp_n_list.append(int(tmp_num[1]))
    n_list.append(tmp_n_list)

for j in range(int(M)):
    tmp_m_list = []
    num = input()
    tmp_num = num.split()
    tmp_m_list.append(int(tmp_num[0]))
    tmp_m_list.append(int(tmp_num[1]))
    m_list.append(tmp_m_list)

for k in range(int(N)):
    for l in range(int(M)):
        if l==0:
            dis = abs(n_list[k][0]-m_list[l][0])+abs(n_list[k][1]-m_list[l][1])
            point = l
        else:
            tmp_dis = abs(n_list[k][0]-m_list[l][0])+abs(n_list[k][1]-m_list[l][1])
            if dis>tmp_dis:
                dis = tmp_dis
                point = l
    print(point+1)

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)

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

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
S = []
T = []
for _ in range(N):
  a,b = map(int,input().split())
  S.append( (a,b) )
for _ in range(M):
  a,b = map(int,input().split())
  T.append( (a,b) )
for (a,b) in S:
  ans = 0
  best = 0
  for i in range(M):
    c,d = T[i]
    here = abs(a-c)+abs(b-d)
    if ans == 0 or best > here:
      ans = (i+1)
      best = here
  print(ans)

Submission status: Accepted

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

ans=[]
for n in range (0,N):
  place=1
  dist=abs(a[n][0]-c[0][0])+abs(a[n][1]-c[0][1])
  for m in range(1,M):
    if abs(a[n][0]-c[m][0])+abs(a[n][1]-c[m][1])<dist:
      dist=abs(a[n][0]-c[m][0])+abs(a[n][1]-c[m][1])
      place=m+1
  ans.append(place)

for n in range (0,N):
  print(ans[n])

Submission status: Accepted

Solution code:
import numpy as np
N, M = map(int, raw_input().split())
a, b, c, d = [], [], [], []
for i in range(N):
    x, y = map(int, raw_input().split())
    a.append(x)
    b.append(y)
for j in range(M):
    x, y = map(int, raw_input().split())
    c.append(x)
    d.append(y)
for i in range(N):
    print np.argmin([abs(a[i] - c[j]) + abs(b[i] - d[j]) for j in range(M)]) + 1

Submission status: Accepted

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

student = [  tuple( map(int, input().split()) ) for x in range(N)]
point = [ tuple( map(int, input().split()) ) for x in range(M)]


for (x1, y1) in student :
    data =  [ abs(x1 - x2) + abs(y1 - y2) for (x2, y2) in point ]
    ans = data.index(min(data))
    print(ans + 1)

Submission status: Accepted

Solution code:
b = input().split()
a = [int(b[i]) for i in range(len(b))]

p = []

for j in range(a[0]):
  tmp = input().split()
  tmp = [int(tmp[i]) for i in range(2)]
  p.append((tmp[0], tmp[1]))

c = []

for j in range(a[1]):
  tmp = input().split()
  tmp = [int(tmp[i]) for i in range(2)]
  c.append((tmp[0], tmp[1]))

ans = []

for i in range(a[0]):
  min = (10000000000, 0)
  for j in range(a[1]):
    if(min[0] > abs(p[i][0] - c[j][0]) + abs(p[i][1] - c[j][1])):
      min = (abs(p[i][0] - c[j][0]) + abs(p[i][1] - c[j][1]), j+1)

  ans.append(min[1])

for j in range(a[0]):
  print(ans[j])

Submission status: Accepted

Solution code:
N, M = map(int, input().split(" "))
 
student = [];
pos = [];
for i in range(N) :
	a, b = map(int, input().split(" "))
	student.append((a, b))
 
for i in range(M) :
	a, b = map(int, input().split(" "))
	pos.append((a,b))
 
for st in student :
	ans = -1;
	score = 10**10;
	for i in range(M) :
		tmpscore = abs(st[0] - pos[i][0]) + abs(st[1] - pos[i][1])
		if score > tmpscore :
			score = tmpscore;
			ans = i;
	print(ans+1);

Submission status: Accepted

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

Submission status: Accepted

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

a = []
b = []

for i in range(n):
    tmp1, tmp2 = list(map(int, input().split()))
    a.append(tmp1)
    b.append(tmp2)

c = []
d = []

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

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

Submission status: Accepted

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

for i in range(N):
    s=10**9
    for j in range(M):
        if  s>abs(a[i]-c[j])+abs(b[i]-d[j]):
             s=abs(a[i]-c[j])+abs(b[i]-d[j])
             e=j+1
    print(e)

Submission status: Accepted

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

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

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

def calc_dst(n, m):
    return abs(a[n]-c[m]) + abs(b[n]-d[m])

for n in range(N):
    nearest_id = 0
    nearest_dst = calc_dst(n, 0)
    for m in range(1, M):
        dst = calc_dst(n, m)
        if nearest_dst > dst:
            nearest_id = m
            nearest_dst = dst

    print(nearest_id + 1)

Submission status: Accepted

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

n = x[0]
m = x[1]

a = []
for i in range(0, n):
    y = list(map(int, input().split()))
    a.append([y[0],y[1]])

c = []
for i in range(0, m):
    z = list(map(int, input().split()))
    c.append([z[0],z[1]])

for i in range(0, n):
    s_ = 9999999999
    s = 0
    for j in range(0, m):
        t = abs(a[i][0] - c[j][0]) + abs(a[i][1] - c[j][1])
        if t < s_:
            s_ = t
            s = j + 1
    print(s)

Submission status: Accepted

Solution code:
n, m = map(int, raw_input().split())
P = [map(int, raw_input().split()) for i in xrange(n)]
C = [map(int, raw_input().split()) for i in xrange(m)]
for a, b in P:
    idx = -1; mi = ()
    for i, (c, d) in enumerate(C):
        di = abs(a-c) + abs(b-d)
        if di < mi:
            mi = di
            idx = i
    print idx+1

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


ans = []

for i in range(n):
    dist = []
    for j in range(m):
        tmp = abs(stu[i][0] - check[j][0]) + abs(stu[i][1] - check[j][1])
        dist.append(tmp)
    mi = dist.index(min(dist))
    ans.append(mi)


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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
s = []
d = []
for i in range(n):
    x, y = map(int, input().split())
    s.append([x, y])
for i in range(m):
    x, y = map(int, input().split())
    d.append([x, y])
for i in s:
    a = 1
    c = abs(i[0] - d[0][0]) + abs(i[1] - d[0][1])
    for j in range(1, m):
        c_t = abs(i[0] - d[j][0]) + abs(i[1] - d[j][1])
        if c_t < c:
            c = min(c, c_t)
            a = j + 1
    print(a)

Submission status: Accepted

Solution code:
import sys, math

n,m = [int(x) for x in sys.stdin.readline().split()]

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

s = [LI() for _ in range(n)]
p = [LI() for _ in range(m)]

def manhattan(a,b):
	return math.fabs(a[0]-b[0]) + math.fabs(a[1]-b[1])

def nearest(a):
	r = 1
	d = manhattan(a,p[0])
	for (i,x) in enumerate(p):
		pd = manhattan(a,x)
		if pd<d:
			r = i+1
			d = pd
	return r

for (i,x) in enumerate(s):
	print(nearest(x))

Submission status: Accepted

Solution code:
a = list(map(int,input().split(" ")))
b = list()
c = list()
ans = list()

for i in range(a[0]):
    b.append(list(map(int,input().split(" "))))

for i in range(a[1]):
    c.append(list(map(int,input().split(" "))))

for i in range(a[0]):
    d = 0
    e = 9999999999
    for ii in range(a[1]):
        if e > abs(b[i][0] - c[ii][0]) + abs(b[i][1] - c[ii][1]):
            e = abs(b[i][0] - c[ii][0]) + abs(b[i][1] - c[ii][1])
            d = ii
    ans.append(d+1)
    
for i in range(a[0]):
    print(ans[i])

Submission status: Accepted

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

nodes, checks = [], []
for i in range(N):
    nodes.append(list(map(int, input().split())))

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

for i in range(N):
    argMin, distMin = None, float('inf')
    for j in range(M):
        dist = abs(nodes[i][0] - checks[j][0]) + abs(nodes[i][1] - checks[j][1])
        if dist < distMin: argMin, distMin = j, dist
    print(argMin + 1)

Submission status: Accepted

Solution code:
import sys
import numpy as np

N, M = (int(i) for i in input().split(" "))
S = [input().split(" ") for i in range(N + M)]

seito = S[0:N]
check = S[N:N+M]

kyori = np.zeros(M)

for j in range(0,N):
	for i in range(0,M):
		kyori[i] = abs(int(seito[j][0]) - int(check[i][0])) + abs(int(seito[j][1]) - int(check[i][1]))
	#kyoriが一番低いiを出力する

	num = np.argmin(kyori) + 1
	print(num)

Submission status: Accepted

Solution code:
n,m=(int(i)for i in input().split())
g=[]
t=[]
for i in range(n):
    g.append([int(i)for i in input().split()])
for i in range(m):
    t.append([int(i)for i in input().split()])
for i in range(n):
    kyr=400000001
    min=-1
    for j in range(m):
        kr=abs(g[i][0]-t[j][0])+abs(g[i][1]-t[j][1])
        if kr<kyr:
            kyr=kr
            min=j+1
    print(min)

Submission status: Accepted

Solution code:
N,M = list(map(int, input().split()))
 
s = [list(map(int,input().split())) for i in range(N)]
c = [list(map(int,input().split())) for j in range(M)]
 
for t1 in s:
    l = list(map(lambda x: abs(t1[0] - x[0]) + abs(t1[1] - x[1]), c))
    print(l.index(min(l)) + 1)

Submission status: Accepted

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

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

c = []
for j in range(M):
    c.append(list(map(int, input().split())))

for t1 in s:
    l = list(map(lambda x: abs(t1[0] - x[0]) + abs(t1[1] - x[1]), c))
    print(l.index(min(l)) + 1)

Submission status: Accepted

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

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

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

ans = [0] * N

for i in range(N):
	mindif = 4 * 10**8 + 1
	for j in range(M):
		dif = abs(students[i][0] - checkpoints[j][0]) + abs(students[i][1] - checkpoints[j][1])
		if dif < mindif:
			mindif = dif
			ans[i] = j + 1

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

Submission status: Accepted

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

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

b = []
for i in range(M):
    b.append(list(map(int, input().split())))

for s in a:
    max_d = 1e9
    cp = 0
    for k,v in enumerate(b):
        tmp_d = dis(s, v)
        if(tmp_d < max_d):
            max_d = tmp_d
            cp = k
    print(cp+1)

Submission status: Accepted

Solution code:
# coding:utf-8

NM = raw_input().split()
N = int(NM[0])
M = int(NM[1])

a = []
b = []
c = []
d = []
for i in xrange(N):
    ab = raw_input().split()
    a.append(int(ab[0]))
    b.append(int(ab[1]))

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

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

Submission status: Accepted

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

def manhattan(n, m):
    return abs(A[n]-C[m]) + abs(B[n]-D[m])

# calculate and output
for n in range(N):
    ind = 0
    dis = manhattan(n, 0)
    for m in range(M):
        dis_m = manhattan(n, m)
        if dis > dis_m:
            ind = m
            dis = dis_m
    print(ind+1)

Submission status: Accepted

Solution code:
#http://abc057.contest.atcoder.jp/tasks/abc057_b
import sys

def myabs(a):
    return a if a >= 0 else -a

def dist(x1, y1, x2, y2):
    return myabs(x1-x2) + myabs(y1-y2)

def calc(people_points, check_points):
    ans = []

    #それぞれの人に関して、チェックポイントまでの距離を求める
    for x_p, y_p in people_points:
        dists = [ dist(x_p, y_p, check_point[0], check_point[1]) for check_point in check_points ]
        ans_ind, ans_dist = sorted(list(enumerate(dists)), key=lambda tpl:tpl[1])[0]
        ans_tpl = (ans_ind, ans_dist)
        ans.append(ans_tpl)


    return ans

def main():
    n_m = sys.stdin.readline().split()
    n = int(n_m[0])
    m = int(n_m[1])

    people_points = []
    check_points = []

    for i in range(n):
        a_b = sys.stdin.readline().split()
        a = int(a_b[0])
        b = int(a_b[1])
        people_points.append((a, b))

    for i in range(m):
        c_d = sys.stdin.readline().split()
        c = int(c_d[0])
        d = int(c_d[1])
        check_points.append((c, d))

    ans = [ind + 1 for ind, dist in calc(people_points, check_points)]
    print("\n".join([str(i) for i in ans]))

    return 0

if __name__ == '__main__':
    sys.exit(main())

Submission status: Accepted

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

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

for i in range(n):
    dis = []
    for j in range(m):
        dis.append(abs(man[i][0] - Location[j][0]) + abs(man[i][1] - Location[j][1]))
    print(dis.index(min(dis)) + 1)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# input
n, m = map(int, input().split())
persons = []
checks = []
for i in range(n):
    point = tuple(map(int, input().split()))
    persons.append(point)
for i in range(m):
    point = tuple(map(int, input().split()))
    checks.append(point)

# print(persons)
# print(checks)
    
def get_distance(person, check):
    return abs(person[0] - check[0]) + abs(person[1] - check[1])
    
for i in range(n):
    min_distance = 10 ** 10
    min_distance_point_num = -1

    # calculate min distance from n to each m
    for j in range(m):
        distance = get_distance(persons[i], checks[j])
        if distance < min_distance:
            min_distance = distance
            min_distance_point_num = j + 1

    print(min_distance_point_num)

Submission status: Accepted

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

A=[]
B=[]
C=[]
D=[]


for _ in range(N):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)
    
for _ in range(M):
    c,d=map(int,input().split())
    C.append(c)
    D.append(d)
     
for i in range(N):
        L=[]
        for j in range(M):
            K=abs(A[i]-C[j])+abs(B[i]-D[j])  
            L.append(K)  
        next
        P=L.index(min(L))
        print(P+1)

Submission status: Accepted

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

b = []
for i in range(M):
    b.append(list(map(int, input().split())))

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

m = []
for i in range(N):
    mdis = distance(i,0)
    mn = 0+1
    for j in range(1,M):
        if(mdis > distance(i,j)):
            mdis = distance(i,j)
            mn = j+1

    m.append(mn)

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
n, m = map(int, input().split())
student = np.zeros([n,2])
check_point = np.zeros([m,2])
res = np.ones([n,m])
for i in range(n):
    student[i,0], student[i,1] = map(int, input().split())
for i in range(m):
    check_point[i,0], check_point[i,1] = map(int, input().split())
    res[:,i] = abs(student[:,0]-check_point[i,0])+abs(student[:,1]-check_point[i,1])
for i in range(n):
    print(np.argmin(res[i,:])+1)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
import math

N,M = map(int, raw_input().split())
a = np.zeros(N,dtype='int')
b = np.zeros(N,dtype='int')
c = np.zeros(M,dtype='int')
d = np.zeros(M,dtype='int')
for i in range(N):
    a[i],b[i] = map(int, raw_input().split())
for i in range(M):
    c[i],d[i] = map(int, raw_input().split())
    
for i in range(N):
    MinDist = 999999999
    CheckPoint = -1
    for j in range(M):
        ManhattanDist = math.fabs(a[i]-c[j])+math.fabs(b[i]-d[j])
        if(MinDist>ManhattanDist):
            MinDist = ManhattanDist
            CheckPoint = j+1
    print(CheckPoint)

Submission status: Accepted

Solution code:
import math

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

a,b,c,d,L=[],[],[],[],[]
for i in range(N):
    f,g=map(int,input().split())
    a.append(f)
    b.append(g)

for i in range(M):
    f,g=map(int,input().split())
    c.append(f)
    d.append(g)

for i in range(N):
    L.clear()
    for j in range(M):
        L.append(int(math.fabs(a[i]-c[j])+math.fabs(b[i]-d[j])))
    for k in range(M):
        if L[k]==min(L):
            print(k+1)
            break

Submission status: Accepted

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

for i in range(n):
  mindis = 10 ** 9
  res = 0
  for j in range(m):
    dist = abs(a[i] - c[j]) + abs(b[i] - d[j])
    if dist < mindis:
      mindis = dist
      res = j + 1
  print(res)

Submission status: Accepted

Solution code:
def mDistance(a, b):
    axisDist = [abs(x0 - x1) for x0, x1 in zip(a, b)]
    return(sum(axisDist))


N, M = map(int, input().split())
An, Am = ([], [])

while len(An) < N:
    An.append(tuple(map(int, input().split())))

while len(Am) < M:
    Am.append(tuple(map(int, input().split())))

for a in An:
    B = map(lambda b: mDistance(a, b), Am)
    I, _ = min(enumerate(list(B)), key=lambda b: b[1])
    print(I + 1)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys,copy,math,heapq,itertools as it,fractions,re,bisect,collections as coll

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

for i, (a, b) in enumerate(ab):
    mn = 1e10
    p = -1
    for j, (c, d) in enumerate(cd, 1):
        tmp = abs(a - c) + abs(b - d)
        if tmp < mn:
            mn = tmp
            p = j
    print p

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed Apr  5 11:25:59 2017

@author: syaga
"""
import math


def getMan(x, y):
    man = math.fabs(x[0]-y[0])+math.fabs(x[1]-y[1])
    return man

if __name__ == "__main__":
    student = []
    check = []
    answer = []
    N, M = list(map(int, input().split()))
    for i in range(N):
        student.append(list(map(int, input().split())))
    for i in range(M):
        check.append(list(map(int, input().split())))
    for i in student:
        min_tmp = 1000000000000000000
        min_index = 0
        for j in check:
            man = getMan(i, j)
            if min_tmp > man:
                min_tmp = man
                min_index = check.index(j)+1
        answer.append(min_index)
    for i in answer:
        print(i)

Submission status: Accepted

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

for sx, sy in students:
    mindist = 10 ** 9
    num = 0
    for i in range(M):
        cx, cy = checkpoints[i]
        dist = abs(sx-cx) + abs(sy-cy)
        if mindist > dist:
            mindist = dist
            num = i
    print(num+1)

Submission status: Accepted

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

stu = []
for _ in range(n):
    stu.append((map(int, raw_input().split())))

che = []
for _ in range(m):
    che.append((map(int, raw_input().split())))


for st in range(n):
    min_dis = float("inf")
    idx = -1
    for ch in range(m):
        dist = abs(stu[st][0] - che[ch][0]) + abs(stu[st][1] - che[ch][1])
        if dist < min_dis:
            min_dis = dist
            idx = ch
    print idx + 1

Submission status: Accepted

Solution code:
import math

class Point:
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def distanceTo(self, point):
        dist = math.fabs(self.x - point.x) + math.fabs(self.y - point.y)
        return dist

students = []
checkpoints = []

N, M = map(int, raw_input().split(" "))
for i in range(0, N):
    x, y = map(int, raw_input().split(" "))
    students.append(Point(x, y))

for i in range(0, M):
    x, y = map(int, raw_input().split(" "))
    checkpoints.append(Point(x, y))


for student in students:
    minDist = 1000000000
    minIndex = 0
    for i in range(0, M):
        dist = student.distanceTo(checkpoints[i])
        if dist < minDist:
            minDist = dist
            minIndex = i
    print minIndex + 1

Submission status: Accepted

Solution code:
import math

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

#a_1, b_1 to a_N, b_N
student_coordinates = []
for i in range(argv[0]):
    student_coordinates.append([int(x) for x in input().split(" ")])

#c_1, d_1 to c_N, d_N
check_points = []
for i in range(argv[1]):
    check_points.append([int(x) for x in input().split(" ")])

def manhattan_dist(point_1, point_2):
    return math.fabs(point_1[0] - point_2[0]) + math.fabs(point_1[1] - point_2[1])

def select_check_point(student):
    dist_list = []
    for i in range(argv[1]):
        dist_list.append(manhattan_dist(student, check_points[i]))
    return dist_list.index(min(dist_list))

for i in range(argv[0]):
    print(select_check_point(student_coordinates[i]) + 1)

Submission status: Accepted

Solution code:
[N,M] = map(int, raw_input().split())
sl = []
for i in range(N):
    sl.append(map(int, raw_input().split()))
pl = []
for i in range(M):
    pl.append(map(int, raw_input().split()))
ans = []
for (x,y) in sl:
    dmin = 400000001
    imin = -1
    for (i, (px, py)) in enumerate(pl):
        d = abs(x - px) + abs(y - py)
        if(d < dmin):
            dmin = d
            imin = i
    ans.append(imin+1)
for i in ans:
    print i

Submission status: Accepted

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

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

a_list, b_list, c_list, d_list = [], [], [], []

#student
for i in range(N):
	a, b = map(int, input().split())
	a_list.append(a)
	b_list.append(b)

#checkpoint
for i in range(M):
	c, d = map(int, input().split())
	c_list.append(c)
	d_list.append(d)

for j in range(N):
	dist = []
	for k in range(M):
		dist.append(abs(a_list[j] - c_list[k]) + abs(b_list[j] - d_list[k]))
	print(dist.index(min(dist))+1)

Submission status: Accepted

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

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

students = [map(int,raw_input().split()) for _ in range(n)]
checkpoints = [map(int,raw_input().split()) for _ in range(m)]

#%%

for a,b in students:
    idx = -1
    dist = 10**9
    for j in range(m):
        c,d = checkpoints[j]
        manhat = abs(a-c)+abs(b-d)
        if manhat < dist:
            dist = manhat
            idx = j+1
    print(idx)

Submission status: Accepted

Solution code:
data = list(map(int,input().split(" ")))
stdnt = []
for i in range(data[0]):
	stdnt.append(list(map(int,input().split(" "))))
point = []
for i in range(data[1]):
	point.append(list(map(int,input().split(" "))))
def check(st,po):
	for i in range(len(st)):
                distance = []
                for j in range(len(po)):
                        distance.append(abs(st[i][0]-po[j][0])+abs(st[i][1]-po[j][1]))
                print(distance.index(min(distance)) + 1)
check(stdnt,point)

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-
N, M = map(int, input().split())
coordinate = []
checkpoint = []
tmplist = []
for tmp in range(N):
    a, b = map(int, input().split())
    coordinate.append((a,b))
for tmp in range(M):
    c, d = map(int, input().split())
    checkpoint.append((c,d))
for i in range(N):
    for j in range(M):
        tmplist.append(abs(coordinate[i][0]-checkpoint[j][0])+abs(coordinate[i][1]-checkpoint[j][1]))
    print(tmplist.index(min(tmplist))+1)
    tmplist = []

Submission status: Accepted

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

import sys
import os


N, M = list(map(int, input().split()))
students = []
checkpoints = []

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

for i in range(M):
    a, b = list(map(int, input().split()))
    checkpoints.append([a, b])

for student in students:
    min_dist = float('inf')
    min_i = None
    for i, checkpoint in enumerate(checkpoints):
        manhattan_dist = abs(checkpoint[0] - student[0]) + abs(checkpoint[1] - student[1])
        if manhattan_dist < min_dist:
            min_dist = manhattan_dist
            min_i = i
    print(min_i + 1)

Submission status: Accepted

Solution code:
import sys

if __name__=="__main__":
    ab=[]
    cd=[]
    [n,m]=map(int,input().split(" "))
    for i in range(n):
        ab.append(list(map(int,input().split(" "))))
    for j in range(m):
        cd.append(list(map(int,input().split(" "))))
    for i in range(n):
        min=sys.maxsize
        index=0
        for j in range(m):
            distance = abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
            if min > distance :
                min=distance 
                index=j
        print(index+1)

Submission status: Accepted

Solution code:
import sys

if __name__=="__main__":
    ab=[]
    cd=[]
    [n,m]=map(int,raw_input().split(" "))
    for i in range(n):
        ab.append( map(int,raw_input().split(" ")) )
    for j in range(m):
        cd.append( map(int,raw_input().split(" ")) )
    for i in range(n):
        min=sys.maxint
        index=0
        for j in range(m):
            distance = abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
            if min > distance :
                min=distance 
                index=j
        print(index+1)