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:
#!/usr/bin/env python3

import collections


Point = collections.namedtuple("Point", "x y idx")


def manhattan_dist(p1, p2):
    return abs(p1.x - p2.x) + abs(p1.y - p2.y)


def find_res_point(st, ps):
    def key(p):
        return (manhattan_dist(st, p), p.idx)
    return min(ps, key=key)


def solve(sts, ps):
    return (find_res_point(st, ps) for st in sts)


def main():
    n, m = (int(x) for x in input().split())
    sts = []
    for i in range(n):
        a, b = (int(x) for x in input().split())
        sts.append(Point(a, b, i + 1))
    ps = []
    for j in range(m):
        c, d = (int(x) for x in input().split())
        ps.append(Point(c, d, j + 1))
    for p in solve(sts, ps):
        print(p.idx)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

def dist(s, p):
	return abs(s[0]-p[0])+abs(s[1]-p[1])

for s in S:
	min_dist = dist(s, P[0])
	min_p = 0
	for i in xrange(1, M):
		d = dist(s, P[i])
		if  d < min_dist:
			min_dist = d
			min_p = i
	C.append(min_p+1)
for c in C:
	print c

Submission status: Accepted

Solution code:
def main():
    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):
        min_d = 2 * 10 ** 8
        min_d_j = 0
        for j in range(M):
            md = abs(a[i] - c[j]) + abs(b[i] - d[j])
            if md < min_d:
                min_d = md
                min_d_j = j
        print(min_d_j + 1)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

e=[[0 for j in range(m)] for i in range(n)]
for i in range(n):
  for j in range(m):
    e[i][j]=abs(a[i]-c[j])+abs(b[i]-d[j])
for i in range(n):
  print(e[i].index(min(e[i]))+1)

Submission status: Accepted

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

students=[]
for _ in range(n):
    x,y=raw_input().split(' ')
    students.append((int(x),int(y)))

checkpoint=[]
for _ in range(m):
    x,y=raw_input().split(' ')
    checkpoint.append((int(x),int(y)))

for s in students:
    min_d=99999999999
    min_num=0
    for i,c in enumerate(checkpoint):
        if abs(c[0]-s[0])+abs(c[1]-s[1]) < min_d:
            min_d=abs(c[0]-s[0])+abs(c[1]-s[1])
            min_num=i

    print min_num+1

Submission status: Accepted

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

import os
import sys
import itertools
import math
from collections import Counter, defaultdict

class Main(object):
    
    def __init__(self):
        pass

    def solve(self):
        '''
        insert your code
        '''
        n, m = map(int, input().split())
        students = []
        for i in range(n):
            a, b = map(int, input().split())
            students.append((a, b))
        checkpoints = []
        for j in range(m):
            c, d = map(int, input().split())
            checkpoints.append((c, d))
        for a, b in students:
            ans = -1
            minimum = float('inf')
            for index, (c, d) in enumerate(checkpoints):
                if minimum > abs(a - c) + abs(b - d):
                    minimum = abs(a - c) + abs(b - d)
                    ans = index + 1
            print(ans)
                
        return None

if __name__ == '__main__':
    m = Main()
    m.solve()

Submission status: Accepted

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

a = [[0, 0] for i in range(n)]

c = [[0, 0] for i in range(m)]

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

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

index = 0


for i in range(n):
    for j in range(m):
        if j == 0 :
            k = abs(a[i][0] - c[j][0]) + abs(a[i][1] - c[j][1]) +1

        di = abs(a[i][0] - c[j][0]) + abs(a[i][1] - c[j][1])
        if di < k:
            index = j + 1
            k = di
    print(index)

Submission status: Accepted

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

checkpoints = []
for a in aa:
    d = float("inf")
    checkpoint = -1
    for i,c in enumerate(cc):
        tmpd = min(abs(a[0]-c[0])+abs(a[1]-c[1]),d)
        if not tmpd == d:
            checkpoint = i+1
        d = tmpd
    print(checkpoint)

Submission status: Accepted

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

for i in range(n):
    a0, b0 = map(int, raw_input().split())
    a.append(a0)
    b.append(b0)
for i in range(m):
    c0, d0 = map(int, raw_input().split())
    c.append(c0)
    d.append(d0)
for i in range(n):
    res = 10**9
    ans = 0
    for j in range(m):
        man = abs(a[i]-c[j])+abs(b[i]-d[j])
        if res > man:
            res = man
            ans = j
    print ans+1

Submission status: Accepted

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

N = nm[0]
M = nm[1]

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

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

for a in A:
    min_d = 1000000000000000000000000
    min_i = 0
    d = 0
    for i, b in enumerate(B):
        d = abs(a[0]-b[0])+abs(a[1]-b[1])
        if d < min_d:
            min_i = i
            min_d = d
    print(min_i+1)

Submission status: Accepted

Solution code:
import sys

INF = 10**9+7

stdin = sys.stdin
def na(): return map(int, stdin.readline().split())
def ns(): return stdin.readline().strip()
def nsl(): return list(stdin.readline().strip())
def ni(): return int(stdin.readline())
def nil(): return list(map(int, stdin.readline().split()))

n, m = nil()

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

x = []
ans = []

for i in range(n):
    u, v = nil()
    a.append(u)
    b.append(v)
for i in range(m):
    u, v = nil()
    c.append(u)
    d.append(v)

for i in range(n):
    x.append(INF)
    ans.append(0)
    for j in range(m):
        t = abs(a[i] - c[j]) + abs(b[i] - d[j])
        if(x[i] > t):
            ans[i] = j
            x[i] = t

for i in ans:
    print(i+1)

Submission status: Accepted

Solution code:
#!/usr/bin/env pypy3
# -*- coding: UTF-8 -*-

n,m=map(int,input().split())
g={int(i):[] for i in range(n)}
for i in range(n):
    x,y=map(int,input().split())
    g[i].append((x,y))

for i in range(m):
    x,y=map(int,input().split())
    for j in range(n):
        tmp=abs(g[j][0][0]-x)+abs(g[j][0][1]-y)
        if i==0:
            g[j].append(tmp)
            g[j].append(i)
        elif tmp<g[j][1]:
            g[j][1]=tmp
            g[j][2]=i
for i in range(n):
    print(g[i][2]+1)

Submission status: Accepted

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

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

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

for n in range(N):
    near_point = 0
    shortest = 10**9
    for m in range(M):
        manhattan = abs(a[n] - c[m]) + abs(b[n] - d[m])
        if manhattan < shortest:
            shortest = manhattan
            near_point = m + 1
    print(near_point)

Submission status: Accepted

Solution code:
#!/usr/bin/python

import sys

def main(argv):
    line = sys.stdin.readline().rstrip("\n")

    while line:
        n, m = map(lambda x: int(x), line.split(" ", 2))

        students = []
        points = []
        for i in xrange(n):
            x, y = map(lambda x: int(x), raw_input().split(" ", 2))
            students.append((x, y))

        for i in xrange(m):
            x, y = map(lambda x: int(x), raw_input().split(" ", 2))
            points.append((x, y))

        for sx, sy in students:
            min_index = -1
            min_distance = 4 * 100000000

            for (i, (px, py)) in enumerate(points):
                distance = abs(sx - px) + abs(sy - py)
                if distance < min_distance:
                    min_distance = distance
                    min_index = i + 1
            print min_index

        line = sys.stdin.readline().rstrip("\n")

if __name__ == "__main__":
    main(sys.argv)

Submission status: Accepted

Solution code:
def MD(a1, a2):
    return abs(a1[0]-a2[0]) + abs(a1[1]-a2[1])
N, M = map(int, input().split())
a = []
b = []
for i in range(N):
    _a, _b = map(int, input().split())
    a.append(_a)
    b.append(_b)
c = []
d = []
for i in range(M):
    _c, _d = map(int, input().split())
    c.append(_c)
    d.append(_d)

for A, B in zip(a, b):
    min_d = 10 ** 10
    for i, (C, D) in enumerate(zip(c, d)):
        md = MD((A, B), (C, D))
        if md < min_d:
            ans = i + 1
            min_d = md
    print(ans)

Submission status: Accepted

Solution code:

import sys

a, b, x, y = [], [], [], []
oo = 168430090

def rdl():
	return map(int, raw_input().split())


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


#sys.stdin = open("test.in", "r")
n, m = rdl()
for i in range(n):
	l, r = rdl()
	x.append(l), y.append(r)

for i in range(m):
	l, r = rdl()
	a.append(l), b.append(r)

for i in range(n):
	mn, mnid = oo, 0
	for j in range(m):
		if mht(x[i], y[i], a[j], b[j]) < mn:
			mn = mht(x[i], y[i], a[j], b[j])
			mnid = j
	
	print mnid + 1

Submission status: Accepted

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

for i in range(n):
    min_dis = 400000000
    min_dis_ind = 0
    for j in range(m):
        tmp = abs(a_b[i][0] - c_d[j][0]) + abs(a_b[i][1] - c_d[j][1])
        if min_dis > tmp:
            min_dis = tmp
            min_dis_ind = j
    print(min_dis_ind  + 1)

Submission status: Accepted

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

for i in n:
    x = 0
    for j in range(M):
        c = m[j]
        k = m[x]
        a = max(i[0], k[0]) - min(i[0], k[0]) + max(i[1], k[1]) - min(i[1], k[1])
        b = max(i[0], c[0]) - min(i[0], c[0]) + max(i[1], c[1]) - min(i[1], c[1])
        if b < a : x = j
    print(x + 1)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N, M = [int(n) for n in input().split()]
students = []
check_points = []

for n in range(N):
    students.append([int(tmp) for tmp in input().split()])

for m in range(M):
    check_points.append([int(tmp) for tmp in input().split()])

for student in students:
    destination = 0
    min_dis = 10**16
    for i, check_point in enumerate(check_points):
        tmp_dis = abs(student[0] - check_point[0]) + abs(student[1] - check_point[1])
        if tmp_dis < min_dis:
            destination = i + 1
            min_dis = tmp_dis
    print(destination)

Submission status: Accepted

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

a = []
b = []
for i in range(N):
    temp1, temp2 = map(int, raw_input().split())
    a.append(temp1)
    b.append(temp2)

c = []
d = []
for i in range(M):
    temp1, temp2 = map(int, raw_input().split())
    c.append(temp1)
    d.append(temp2)

result = []

for student in range(N):
    maxDistance = 0
    closePoint = 0
    for point in range(M):
        distance = abs(c[point] - a[student]) + abs(d[point] - b[student])
        if point == 0 or distance < maxDistance:
            maxDistance = distance
            closePoint = point + 1
    result.append(closePoint)

for c in result:
    print(c)

Submission status: Accepted

Solution code:
import sys

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

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

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func()
    top_str = input_raw.strip().split()
    [N, M] = [int(top_str[0]), int(top_str[1])]

    student_list = []
    checkpoint_list = []
    for i in range(N):
        input_raw = read_func().split()
        (a, b) = (int(input_raw[0]) , int(input_raw[1]))
        student_list.append((a,b))

    for i in range(M):
        input_raw = read_func().split()
        (c, d) = (int(input_raw[0]) , int(input_raw[1]))
        checkpoint_list .append((c, d))

    for i in range(N):
        min_checkpoint = 0
        min_dist = sys.maxint
        studentpoint = student_list[i]
        for j in range(M):
            checkpoint = checkpoint_list[j]
            d = dist(studentpoint[0], studentpoint[1], checkpoint[0], checkpoint[1])
            if d < min_dist:
                min_checkpoint = j
                min_dist = d
        print min_checkpoint + 1


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def distance(sX, sY, pX, pY):
	return abs(sX-pX) + abs(sY-pY)

def getIndex(stuX, stuY, points):
	minDist = -1
	index = 0
	for i in range(len(points)):
		pX = points[i][0]
		pY = points[i][1]
		if (minDist == -1 or distance(stuX, stuY, pX, pY) < minDist):
			minDist = distance(stuX, stuY, pX, pY)
			index = i + 1
	return index

[N, M] = input().split()
N = int(N)
M = int(M)
stus = []
points = []
for n in range(N):
	[x,y] = input().split()
	x = int(x)
	y = int(y)
	stus.append([x, y])
for m in range(M):
	[x,y] = input().split()
	x = int(x)
	y = int(y)
	points.append([x,y])
for s in stus:
	print(getIndex(s[0], s[1], points))

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    n, m = map(int, input().split())
    students, checkpoints = (tuple(tuple(map(int, input().split())) for _ in range(x)) for x in (n, m))

    for x1, y1 in students:
        t = 0
        for i in range(m):
            (x2, y2), (x3, y3) = checkpoints[t], checkpoints[i]
            if abs(x1 - x2) + abs(y1 - y2) > abs(x1 - x3) + abs(y1 - y3): t = i

        print(t + 1)

Submission status: Accepted

Solution code:
import math

n,m=[int(i) for i in input().split()]
ab=[]
cd=[]
for i in range(n):
    x,y=[int(i) for i in input().split()]
    ab.append([x,y])
for i in range(m):
    x,y=[int(i) for i in input().split()]
    cd.append([x,y])


for i in range(n):
    dist=1000000000
    point=0
    for j in range(m):
        temp=abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
        if temp<dist:
            dist=temp
            point=j+1
    print(point)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
As = []
Bs = []
for _ in range(N):
    a, b = map(int, input().split())
    As.append(a)
    Bs.append(b)
Cs = []
Ds = []
for _ in range(M):
    c, d = map(int, input().split())
    Cs.append(c)
    Ds.append(d)

ans = []
for i in range(N):
    a = As[i]
    b = Bs[i]
    dist = 5 * 10**8
    tmp = 1
    for j in range(M):
        c = Cs[j]
        d = Ds[j]
        if abs(a - c) + abs(b - d) < dist:
            dist = abs(a - c) + abs(b - d)
            tmp = j + 1
    ans.append(tmp)
    
print('\n'.join(list(map(str, ans))))

Submission status: Accepted

Solution code:

def amin(_data):
    ans = 0
    dst = 1000000000

    for idx, point in enumerate(checks):
        # x = abs(point[0] - _data[0])
        # y = abs(point[1] - _data[1])
        x = abs(_data[0] - point[0])
        y = abs(_data[1] - point[1])

        _dst = x + y

        if _dst < dst:
            ans = idx + 1
            dst = _dst

    return ans



N, M = list(map(int, input().split()))
points = list()
checks = list()

for _ in range(N):
    data = list(map(int, input().split()))
    points.append(data)

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

for point in points:
    print(amin(point))

Submission status: Accepted

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

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

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

def dis(x,y,a,b):
	return(abs(x-a)+abs(y-b))

res = []

for x,y in (gaku):
	c = 1
	mind = float("inf")
	minc = 0
	for a,b in (cp):
		if dis(x,y,a,b) < mind:
			minc = c
			mind = dis(x,y,a,b)
		c+=1
	res.append(minc)


for i in res:
	print(i)

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):
    maxIdx = 0
    for j in range(M):
        d1 = abs(a[i] - c[j]) + abs(b[i] - d[j])
        d2 = abs(a[i] - c[maxIdx]) + abs(b[i] - d[maxIdx])
        if d1 < d2:
            maxIdx = j

    print(maxIdx + 1)

Submission status: Accepted

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

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

for i in range(n):
	aa,bb = a[i],b[i]
	ans = []
	for j in range(m):
		ans.append((dist(aa,bb,c[j],d[j]),j))
	ans.sort()
	print(ans[0][1]+1)

Submission status: Accepted

Solution code:
class Point(object):
    def __init__(self, x, y):
        self.x = x
        self.y = y
def diff(p1, p2):
    return abs(p1.x - p2.x) + abs(p1.y - p2.y)
N, M = map(int, raw_input().split())
S = []
for i in xrange(N):
    x, y = map(int, raw_input().split())
    s = Point(x, y)
    S.append(s)
C = []
for i in xrange(M):
    x, y = map(int, raw_input().split())
    c = Point(x, y)
    C.append(c)
for s in S:
    index = None
    dist = 1e9
    for i, c in enumerate(C):
        d = diff(s, c) 
        if d < dist:
            dist = d
            index = i
    print index + 1

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    n,m = LI()
    a = [LI() for _ in range(n)]
    b = [LI() for _ in range(m)]
    r = []
    for ai in a:
        mi = -1
        mm = inf
        for i in range(m):
            bi = b[i]
            t = abs(ai[0]-bi[0]) + abs(ai[1]-bi[1])
            if t < mm:
                mi = i+1
                mm = t
        r.append(mi)

    return '\n'.join(map(str, r))



print(main())

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    N,M = map(int, input().split())
    data = []
    for i in range(N):
        a,b = map(int, input().split())
        data.append([a, b])
    checks = []
    for i in range(M):
        c,d = map(int, input().split())
        checks.append([c, d])

    for a,b in data:
        res = 1 << 50
        p = -1
        for idx, check in enumerate(checks):
            tmp = abs(a - check[0]) + abs(b - check[1])
            if (tmp < res):
                res = tmp
                p = idx + 1
        print (p)

Submission status: Accepted

Solution code:
def ri():
    return map(int, raw_input().split())

n,m = ri()
students = [ri() for _ in range(n)]
checkpoints = [ri() for _ in range(m)]
for a,b in students:
    idx = -1
    dist = 10**9
    for i,(c,d) in enumerate(checkpoints):
        tmp = abs(c-a) + abs(d-b)
        if tmp < dist:
            dist = tmp
            idx = i
    print idx + 1

Submission status: Accepted

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

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

for a, b in zip(A, B):
    best = 1<<30
    res = None
    for i in range(M):
        d = abs(a - C[i]) + abs(b - D[i])
        if res is None or best > d:
            best = d
            res = i
    print(res + 1)

Submission status: Accepted

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

stu = []
che = []
ans = []

for i in xrange(n):
    a, b = map(int, raw_input().split())
    stu.append((a, b))
    
for i in xrange(m):
    a, b = map(int, raw_input().split())
    che.append((a, b))
    
for i in xrange(n):
    dis = float('inf')
    for j in xrange(m):
        if abs(stu[i][0] - che[j][0]) + abs(stu[i][1] - che[j][1]) < dis:
            index = j
            dis = abs(stu[i][0] - che[j][0]) + abs(stu[i][1] - che[j][1])
    ans.append(index)
    
for i in ans:
    print i+1

Submission status: Accepted

Solution code:
def md(a,b,c,d):
    return abs(a-c) + abs(b-d)
n,m = map(int, input().split())
s = []
for i in range(n):
    y,x = map(int, input().split())
    s.append((y,x))
c = []
for i in range(m):
    y,x = map(int, input().split())
    c.append((y,x))
for i in range(n):
    min_j = 0
    min_d = float('inf')
    for j in range(m):
        d = md(s[i][0], s[i][1], c[j][0], c[j][1])
        if min_d > d:
            min_j = j
            min_d = d
    print(min_j+1)

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)]
ans=[]
for i in xrange(n):
    a,b=ab[i]
    tmp=10**12
    idx=-1
    for j in xrange(m):
        c,d=cd[j]
        if abs(a-c)+abs(b-d)<tmp:
            tmp=abs(a-c)+abs(b-d)
            idx=j
    ans.append(idx)
for i in xrange(n):
    print ans[i]+1

Submission status: Accepted

Solution code:
import sys

def solve():
    N, M = map(int, input().split())
    st = [[int(i) for i in input().split()] for j in range(N)]
    cp = [[int(i) for i in input().split()] for j in range(M)]

    for a, b in st:
        ans = 0
        min_len = 10**9

        for i, (c, d) in enumerate(cp):
            tmp = abs(c - a) + abs(d - b)
            if tmp < min_len:
                min_len = tmp
                ans = i + 1

        print(ans)


def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin


def na(): return map(int, stdin.readline().split())


def ns(): return stdin.readline().strip()


n,m=na()
abss = []
for i in range(n):
    abss.append(list(na()))
cds = []
for i in range(m):
    cds.append(list(na()))

for ab in abss:
    mind = 999999999
    argmin = -1
    import math
    for j in range(m):
        v = abs(cds[j][0]-ab[0])+abs(cds[j][1]-ab[1])
        if v < mind:
            mind = v
            argmin = j
    print(argmin+1)

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):
    mi = -1
    mv = float('inf')
    for j in xrange(M):
        dist = abs(ab[i][0]-cd[j][0]) + abs(ab[i][1]-cd[j][1])
        if dist < mv:
            mv = dist
            mi = j
    print mi+1

Submission status: Runtime Error

Solution code:
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
ips = lambda:input().split()
import collections
import math
import itertools
import heapq as hq
import sys
n,m = ma()
ckp = []
st = []

for i in range(n):
    st.append(lma())
for i in range(m):
    ckp.append(lma())
for a,b in st:
    tmp=10**15
    ans=0
    for i  in range(m):
        if tmp<abs(a-c)+abs(b-d):
            tmp=abs(a-c)+abs(b-d)
            ans=i+1
    print(ans)

Submission status: Runtime Error

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

def check(a,b):
    x = a[0] - b[0]
    y = a[1] - b[1]
    if x < 0:
        x = -x
    if y < 0:
        y = -y
    return x + y

for a in al:
    min = 100000000
    cnt = 1
    for b in bl:
        tmp = check(a,b)
        if tmp < min:
            ans = cnt
            min = tmp
        cnt += 1
    print(ans)

Submission status: Runtime Error

Solution code:
N,M = [int(c) for c in input().split()]
ab = [list(map(int,input().split())) for c in range(N)]
cd = [list(map(int,input().split())) for c in range(M)]
for i in range(N):
    mi = 2*10**8+1
    for j in range(M):
        tmp = abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
        if mi > tmp:
            mi = tmp
            ans = j+1
    print(ans)

Submission status: Runtime Error

Solution code:
N,M = [int(c) for c in input().split()]
ab = [list(map(int,input().split())) for c in range(N)]
cd = [list(map(int,input().split())) for c in range(M)]
for i in range(N):
    mi = 2*10**8
    for j in range(M):
        tmp = abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
        if mi > tmp:
            mi = tmp
            ans = j+1
    print(ans)

Submission status: Runtime Error

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

a_lis=[list(map(int,input())) for i in range(n)]
c_lis=[list(map(int,input())) for i in range(m)]

for i in range(n):
  num=0
  ans=10**10
  for j in reversed(range(m)):
    a=a_lis[i]
    c=c_lis[j]
    num=abs(a[0]-c[0])+abs(a[1]-c[1])
    ans=min(ans,num)
    if num==ans:
      cnt=j+1
  print(cnt)

Submission status: Runtime Error

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

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

for i in range(n):
  num=0
  ans=10**8
  for j in reversed(range(m)):
    a=a_lis[i]
    c=c_lis[j]
    num=abs(a[0]-c[0])+abs(a[1]-c[1])
    ans=min(ans,num)
    if num==ans:
      cnt=j+1
  print(cnt)

Submission status: Runtime Error

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

a_lis=[list(map(int,input())) for i in range(n)]
c_lis=[list(map(int,input())) for i in range(m)]

for i in range(n):
  num=0
  ans=10**8
  for j in reversed(range(m)):
    a=a_lis[i]
    c=c_lis[j]
    num=abs(a[0]-c[0])+abs(a[1]-c[1])
    ans=min(ans,num)
    if num==ans:
      cnt=j+1
  print(cnt)

Submission status: Runtime Error

Solution code:
n,m = map(int, input().split())
st = []
pt = []
ch = []
for i in range(n):
  st.append(list(map(int, input().split())))
for i in range(n):
  pt.append(list(map(int, input().split())))
for j in st:
  for k in pt:
    d = abs(j[0]-k[0]) + abs(j[1]-k[1])
    ch.append(d)
  print(ch.index(min(ch))+1)
  ch = []

Submission status: Runtime Error

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

for _ in range(n):
    c,d = map(int, input().split())
    cdl.append((c,d))


for a,b in abl:
    cmin = 10**10
    mini = -1
    for i,(c,d) in enumerate(cdl):
        v = abs(a-c)+abs(b-d)
        if v < cmin:
            cmin = v
            minc,mind = c,d
            mini = i+1
    print(mini)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
bool PN(int x)
{
  if (x <= 1)
    return false;
  if (x == 2)
    return true;
  for (int i = 2; i < sqrt(x) + 1; i++)
    if (x % i == 0)
      return false;
  return true;
}

void solve()
{
  int n, m; cin >> n >> m;
  int a[n], b[n];
  int x[m], y[m];
  for(int i = 0; i < n; ++i){
    cin >> a[i] >> b[i];
  }
  for(int i = 0; i < m; ++i){
    cin >> x[i] >> y[i];
  }
  for(int i =0 ; i < n; ++i){
    int mi = 1000500000;
    int ans = -1;
    for(int j = 0; j < m; ++j){
      if(mi > abs(a[i]-x[j]) + abs(b[i]-y[j])){
        ans = j+1;
        mi = abs(a[i]-x[j]) + abs(b[i]-y[j]);
      }
    }

    cout << ans << endl;
  }
}

int main()
{
  solve();
  return 0;
}

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
stud = []
poit = []
for i in range(n):
    a, b = map(int, input().split())
    stud.append([a, b])
for i in range(n):
    c, d = map(int, input().split())
    poit.append([c, d])
for a, b in stud:
    # print(a, b)
    dist = float('inf')
    for i, info in enumerate(poit):
        c = info[0]
        d = info[1]
        mdist = abs(a-c) + abs(b-d)
        if dist > mdist:
            dist = mdist
            ans = i+1
    print(ans)
    # print(i, info)