Problem:


Score : 200 points

Problem Statement

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

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

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

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

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

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

Which checkpoint will each student go to?

Constraints

1 \leq N,M \leq 50

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

All input values are integers.

Input

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

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

Output

Print N lines.

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

Sample Input 1

2 2
2 0
0 0
-1 0
1 0

Sample Output 1

2
1

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

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

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

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

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

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

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

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

Sample Input 2

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

Sample Output 2

3
1
2

There can be multiple checkpoints at the same coordinates.

Sample Input 3

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

Sample Output 3

5
4
3
2
1



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


Sample output:
2
1

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
students = list()
points = list()
for i in range(0, N):
    coord = list(map(int, input().split()))
    students.append(coord)
for i in range(0, M):
    coord = list(map(int, input().split()))
    points.append(coord)
for student in students:
    min_dis = 4000000000
    ans = 0
    m = 0
    for point in points:
        m += 1
        temp = abs(student[0] - point[0]) + abs(student[1] - point[1])
        if min_dis > temp:
            min_dis = temp
            ans = m
    print(ans)

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n,m = na()
s = [na() for _ in range(n)]
c = [na() for _ in range(m)]

l = []
for i in s:
    for j in c:
        l.append(abs(i[0]-j[0]) + abs(i[1]-j[1]))
    a = l.index(min(l))
    print(a+1)
    l = []

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
# non 0 student 1 check 2
n_lis = [list(map(int, input().split())) for i in range(n)]
m_lis = [list(map(int, input().split())) for i in range(m)]
import sys

for i in n_lis:
    min_num = sys.maxsize
    ans_index = 0
    for index, j in enumerate(m_lis):
        num = abs(i[0] - j[0]) + abs(i[1] - j[1])
        if min_num > num:
            min_num = num
            ans_index = index + 1
    print(ans_index)

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 j in range(M)]
d=[0 for j in range(M)]
for i in range(N):
  a[i],b[i]=map(int,input().split())
for j in range(M):
  c[j],d[j]=map(int,input().split())
for i in range(N):
  k=0
  for j in range(M):
    if abs(a[i]-c[k])+abs(b[i]-d[k])>abs(a[i]-c[j])+abs(b[i]-d[j]):
      k=j
  print(k+1)

Submission status: Accepted

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

students = [tuple(map(int, input().split())) for i in range(n)]
checkpoints = [tuple(map(int, input().split())) for j in range(m)]

def distance(u, v):
    return abs(u[0] - v[0]) + abs(u[1] - v[1])


for s in students:
    j = -1
    v = 2*10**9
    for i, cp in enumerate(checkpoints):
        d = distance(s, cp)
        if d < v:
            j = i
            v = d
    print(j+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
s=[list(map(int,input().split())) for i in range(n)]
p=[list(map(int,input().split())) for i in range(m)]
man=0
inde=1
for i in range(n):
    arr=[abs(s[i][0]-p[0][0])+abs(s[i][1]-p[0][1])]
    for j in range(1,m):
        man=abs(s[i][0]-p[j][0])+abs(s[i][1]-p[j][1])
        if man<min(arr):
            arr.append(man)
            inde=j+1
    print(inde)
    inde=1

Submission status: Accepted

Solution code:
import sys
N,M=map(int,input().split())
ai=[0for i in range(N)]
bi=[0for i in range(N)]
ci=[0for i in range(M)]
di=[0for i in range(M)]
disti=[10**9 for i in range(N)]
checki=[0 for i in range(N)]

for i in range(N):
    ai[i],bi[i]=map(int,input().split())
for i in range(M):
    ci[i],di[i]=map(int,input().split())
    
for i in range(N):
    for j in range(M):
        dist=abs(ai[i]-ci[j])+abs(bi[i]-di[j])
        if(disti[i]>dist):
            disti[i]=dist
            checki[i]=j+1
            
for i in checki:
    print(i)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc057/tasks/abc057_b

"""
import sys
from sys import stdin
input = stdin.readline


def calc_dist(s, c):
    return abs(s[0] - c[0]) + abs(s[1] - c[1])


def solve(students, checkpoints):
    ans = []

    for s in students[1:]:
        dist = [float('inf')]
        for c in checkpoints[1:]:
            d = calc_dist(s, c)
            dist.append(d)
        min_dist = min(dist)
        cp_num = dist.index(min_dist )
        ans.append(cp_num)
    return ans


def main(args):
    students = [[0, 0]]
    N, M = map(int, input().split())
    for _ in range(N):
        a, b = map(int, input().split())
        students.append([a, b])
    checkpoints = [[0, 0]]
    for _ in range(M):
        c, d = map(int, input().split())
        checkpoints.append([c, d])
    ans = solve(students, checkpoints)
    print(*ans, sep='\n')


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
N, M = [int(i) for i in input().split()]
Student = [[int(i) for i in input().split()] for j in range(N)]
Checkpoint = [[int(i) for i in input().split()] for j in range(M)]

for x, y in Student:
    ans = [-1, float('inf')]
    for j, (x2, y2) in enumerate(Checkpoint):
        dist = abs(x2 - x) + abs(y2 - y)
        if dist < ans[1]:
            ans = [j, dist]
    print(ans[0] + 1)

Submission status: Accepted

Solution code:
N,M=map(int, input().split())
 
A=[]
B=[]
for i in range(N):
    a,b=map(int, input().split())
    A.append(a)
    B.append(b)
 
C=[]
D=[]
for i in range(M):
    c,d=map(int, input().split())
    C.append(c)
    D.append(d)
 
T=[]
S=[]
for i in range(N):
    for j in range(M):
        T.append(abs(A[i]-C[j])+abs(B[i]-D[j]))
    S.append(T.index(min(T))+1)
    T=[]
 
for i in range(N):
    print(S[i])

Submission status: Accepted

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

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

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

T=[]
S=[]
for i in range(N):
    for j in range(M):
        T.append(abs(A[i]-C[j])+abs(B[i]-D[j]))
    S.append(T.index(min(T))+1)
    T=[]

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

Submission status: Accepted

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

for x1, y1 in crd:
   ans = 0
   min_m = float("inf")
   for i, (x2, y2) in enumerate(chk, 1):
      m = abs(x1 - x2) + abs(y1 - y2)
      if min_m > m:
         ans = i
         min_m = m
 
   print(ans)

Submission status: Accepted

Solution code:
n, m = [int(x) for x in input().split()]
s = []
c = []
for _ in range(n):
    a, b = [int(x) for x in input().split()]
    s.append((a, b))
for _ in range(m):
    a, b = [int(x) for x in input().split()]
    c.append((a, b))
for sx, sy in s:
    v = []
    for i, (cx, cy) in enumerate(c):
        v.append((i, abs(cx - sx) + abs(cy - sy)))
    print(sorted(v, key=lambda x: x[1])[0][0] + 1)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
cd = [list(map(int, input().split())) for _ in range(m)]
for a, b in ab:
    l = [abs(a-c)+abs(b-d) for c, d in cd]
    print(l.index(min(l))+1)

Submission status: Accepted

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

    for x1, y1 in pos:
        ans = 0
        min_m = float("inf")
        for i, (x2, y2) in enumerate(checkpoints, 1):
            m = abs(x1 - x2) + abs(y1 - y2)
            if min_m > m:
                ans = i
                min_m = m

        print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    N, M = map(int, input().split())
    
    A = []
    B = []
    for _ in range(N):
        hoge = list(map(int, input().split()))
        A.append(hoge[0])
        B.append(hoge[1])

    C = []
    D = []
    for _ in range(M):
        hoge = list(map(int, input().split()))
        C.append(hoge[0])
        D.append(hoge[1])

    for x in range(N):
        fuga = 10 ** 9
        c = 0
        for y in range(M):
            hoge = abs(A[x] - C[y]) + abs(B[x] - D[y])
            if hoge < fuga:
                fuga = hoge
                c = y + 1
        print(c)



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
INF = 10 ** 10

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

for i in range(n):
    mn = INF
    mi = -1
    for j in range(m):
        x = abs(a[i]-c[j]) + abs(b[i]-d[j])
        if x < mn:
            mn = x
            mi = j
    print(mi+1)

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

ans=[]
l= float("inf")
for a,b in A:
	l= float("inf")
	for i,c in enumerate(C):
		if l>abs(a-c[0])+abs(b-c[1]):
			l=abs(a-c[0])+abs(b-c[1])
			x=i+1
	else:
		ans.append(x)

for i in ans:
	print i

Submission status: Accepted

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

for i in range(m):
  check.append(list(map(int, input().split())))

for i in students:
  dis = []
  for j in check:
    dis.append(abs(i[0] - j[0]) + abs(i[1] - j[1]))
  
  print(dis.index(min(dis)) + 1)

Submission status: Accepted

Solution code:
num = [int(x) for x in input().split()]

student = []
for i in range(0, num[0]):
    student.append([int(x) for x in input().split()])
checkpoint = []
for j in range(0, num[1]):
    checkpoint.append([int(x) for x in input().split()])


res = []
cnt = 0
for k in student:
    dis = float("inf")
    for l in checkpoint:
        if dis > abs(k[0]-l[0]) + abs(k[1]-l[1]):
            dis = abs(k[0]-l[0]) + abs(k[1]-l[1])
            cnt = checkpoint.index(l)
    res.append(cnt+1)


for m in res:
    print(m)

Submission status: Accepted

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

def length(x, y, x2, y2):
    return abs(x - x2) + abs(y - y2)

for i in range(n):
    num = -1
    min_ = float("inf")
    for j in range(m):
       tmp = length(an[i][0], an[i][1], cm[j][0], cm[j][1])
       if(tmp < min_):
           min_ = tmp
           num = j + 1
    print(num)

Submission status: Accepted

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

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

for a, b in students:
    tmp = [abs(a-x) + abs(b-y) for x, y in checkpts]
    print(tmp.index(min(tmp))+1)

Submission status: Accepted

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


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


for i in range(N):
    ans = 1e9
    anss = -1
    for j in range(M):
        if ans > dist(X[i], Y[j]):
            ans = dist(X[i], Y[j])
            anss = j + 1
    print(anss)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# !/usr/bin/env python
# vim: set fileencoding=utf-8 :

"""
#
# author:   noname
# url:      https://github.com/pettan0818
# license:  mit license
# created: 木 10/12 18:57:45 2017

# usage
#
"""
import math


def calc_distance(student_post, checkpoint_post):
    return int(math.fabs(student_post[0] - checkpoint_post[0]) + math.fabs(student_post[1] - checkpoint_post[1]))


if __name__ == '__main__':
    import doctest
    doctest.testmod()

    first = input()
    first = first.split(" ")
    data = [int(line) for line in first]

    student_num = data[0]
    checkpoint_num = data[1]

    student_pos_data = [[int(i) for i in input().split(" ")] for i in range(student_num)]
    checkpoint_data = [[int(i) for i in input().split(" ")] for i in range(checkpoint_num)]

    for each_student in student_pos_data:
        dis_list = [calc_distance(each_student, i) for i in checkpoint_data]
        print(dis_list.index(min(dis_list)) + 1)

Submission status: Accepted

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

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

st_cp=[]

for a, b in students:
  min_d=10000000000
  cp = 0
  for m, (c, d) in enumerate(checkpoints):
    dist = abs(a-c) + abs(b-d)
    if dist < min_d:
      min_d = dist
      cp = m+1
  st_cp.append(cp)

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
pos = []
mini = [float('inf') for _ in range(N)]
ret = [-1 for _ in range(N)]
for _ in range(N):
    pos.append((tuple(map(int, input().split()))))

for j in range(M):
    c, d = map(int, input().split())
    for i, s in enumerate(pos):
        diff = abs(c - s[0]) + abs(d - s[1])
        if mini[i] > diff:
            ret[i] = j + 1
            mini[i] = diff

for r in ret:
    print(r)

Submission status: Accepted

Solution code:
N, M = [int(i) for i in input().split()]
a = []
b = []
c = []
d = []
for i in range(N):
    a_, b_ = [int(i) for i in input().split()]
    a.append(a_)
    b.append(b_)
for i in range(M):
    c_, d_ = [int(i) for i in input().split()]
    c.append(c_)
    d.append(d_)
for i in range(N):
    road_old  = float("inf")
    for n in range(M):
        road = abs(a[i] - c[n]) + abs(b[i] - d[n])
        if road < road_old:
            ans = n + 1
            road_old = road
    print(ans)

Submission status: Accepted

Solution code:
def solve():
    N, M = map(int, input().split())
    students = []
    points = []
    
    for _ in range(N):
        a, b = map(int, input().split())
        students.append([a, b])
        
    for _ in range(M):
        c, d = map(int, input().split())
        points.append([c, d])
    
    for [a, b] in students:
        md = []
        for [c, d] in points:
            md.append(abs(a-c) + abs(b-d))
        md_min = min(md)
        md_min_idx = md.index(md_min)
        print(md_min_idx + 1)

if __name__ == '__main__':
    solve()

Submission status: Accepted

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


def main():
    n, m = map(int, input().split())
    s_list = [list(map(int, input().split())) for _ in range(n)]
    c_list = [list(map(int, input().split())) for _ in range(m)]

    for s in s_list:
        minv = 1000000000
        for i, c in enumerate(c_list):
            tmp = man_dis(s, c)
            if tmp < minv:
                minv = tmp
                idx = i
        print(idx+1)
    

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n,m=[int(x) for x in input().split()]
student=[]
checkpoint=[]
for i in [0]*n:
    student.append([int(x) for x in input().split()])
for i in [0]*m:
    checkpoint.append([int(x) for x in input().split()])
from math import fabs
for a,b in student:
    l=float("inf")
    for i,(c,d) in enumerate(checkpoint):
        kyori=fabs(a-c)+fabs(b-d)
        if l>kyori:
            ans=i+1
            l=kyori
    print(ans)

Submission status: Accepted

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


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

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

    checkpoint = []
    for _ in range(m):
        c, d = map(int, input().split())
        checkpoint.append([c, d])

    for s in student:
        d = {}
        for i, c in enumerate(checkpoint):
            d[i] = manhattan_distance(s, c)
        print(sorted(d.items(), key=lambda x: x[1])[0][0]+1)
    


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
man,pt=[],[]
def getter(freq,obj):
    for _ in range(freq):
        a,b=map(int,input().split())
        obj.append([a,b])
def solve():
    for tm in man:
        judg=[]
        for tp in pt:
            judg.append(abs(tm[0]-tp[0])+abs(tm[1]-tp[1]))
        print(judg.index(min(judg))+1)
def main():
    getter(N,man)
    getter(M,pt)
    solve()
if __name__ =='__main__':
    main()

Submission status: Accepted

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

import sys
import re
import math
import collections
import itertools
import functools

DEBUG = True
DEBUG = False

def dbg(*args):
    if DEBUG:
        print("DBG: ", file=sys.stderr, end="")
        print(*args, file=sys.stderr)

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

def main():
    N, M = map(int, input().split())
    A = []
    for _ in range(N):
        a, b = map(int, input().split())
        A.append((a,b))
    B = []
    for _ in range(M):
        c, d = map(int, input().split())
        B.append((c,d))

    for i, a in enumerate(A):
        argmin = 0
        dmin = dist(a, B[0])
        for j, b in enumerate(B):
            d = dist(a, b)
            if d < dmin:
                argmin = j
                dmin   = d
        print(argmin+1)

if __name__ == "__main__": main()

Submission status: Accepted

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

for i in range(n):
    a = input()
    nli.append(a)

for i in range(m):
    b = input()
    mli.append(b)

for i in range(n):
    mans = []
    for j in range(m):
        xns = mli[j]
        a, b = map(int, xns.split())
        yns = nli[i]
        c, d = map(int, yns.split())
        ans = abs(a-c) + abs(b-d)
        mans.append(ans)
    e = min(mans)
    print(mans.index(e)+1)

Submission status: Accepted

Solution code:
def distance(p1, p2):
  (x1, y1) = p1
  (x2, y2) = p2
  return abs(x1 - x2) + abs(y1 - y2)

N, M = map(int, input().split())
stu = [0]*N
point = [0]*M

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

ans = [-1]*N  # (ind, score)
for j, now in enumerate(stu):
  ans[j] = -1
  score = 1e18
  for i in range(M):
    pos = point[i]
    if distance(now, pos) < score:
      score = distance(now, pos)
      ans[j] = i+1

for e in ans:
  print(e)

Submission status: Accepted

Solution code:
def ri(): return int(input())
def rli(): return list(map(int, input().split()))
def rls(): return list(input())
def pli(a): return "".join(list(map(str, a)))

n, m = rli()
student = [[] for i in range(n)]
ans = [[-1,1145148101919] for i in range(n)]
for i in range(n):
    student[i] = rli()
for i in range(m):
    x, y = rli()
    for j in range(n):
        if(abs(x-student[j][0]) + abs(y-student[j][1]) < ans[j][1]):
            ans[j] = [i, abs(x-student[j][0]) + abs(y-student[j][1])]
for i in range(n):
    print(ans[i][0] + 1)

Submission status: Accepted

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

ab = []
cd = []

for _ in range(N):
    a, b = list(map(int, input().split(" ")))
    ab.append([a, b])
    
for _ in range(M):
    c, d = list(map(int, input().split(" ")))
    cd.append([c, d])

for i in range(N):
    best = 1e9
    best_idx = 0
    for j in range(M):
        manhattan = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
        if manhattan < best:
            best = manhattan
            best_idx = j
            
    print(best_idx+1)

Submission status: Accepted

Solution code:
from collections import defaultdict


def main():
    N, M = map(int, input().split())
    students = []
    for _ in range(N):
        a, b = map(int, input().split())
        students.append((a, b))

    checkpoints = []
    for _ in range(M):
        c, d = map(int, input().split())
        checkpoints.append((c, d))

    for s in students:
        ans = ""
        best = float("inf")
        for i, c in enumerate(checkpoints, start=1):
            if abs(s[0] - c[0]) + abs(s[1] - c[1]) < best:
                best = abs(s[0] - c[0]) + abs(s[1] - c[1])
                ans = i
        print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
a=[]
b=[]
for i in range(1,N+1):
    A,B = map(int,input().split())
    a.append(A)
    b.append(B)
c=[]
d=[]
for j in range(1,M+1):
    C,D = map(int,input().split())
    c.append(C)
    d.append(D)
for i in range(1,N+1):
    e=[]
    for j in range(1,M+1):
        E = abs(a[i-1]-c[j-1])+abs(b[i-1]-d[j-1])
        e.append(E)
    x = min(e)
    print(e.index(x)+1)

Submission status: Accepted

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

	
for i in range(n):
	mindis = 500000000
	minCheckPoint = -1
	for j in range(m):
		dis = abs(a[i]-c[j]) + abs(b[i]-d[j])
		if mindis > dis:
			mindis = dis
			minCheckPoint = j + 1
	print(minCheckPoint)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
nab = [list(map(int, input().split())) for x in range(n)]
mab = [list(map(int, input().split())) + [x + 1] for x in range(m)]
print("\n".join(map(str, [min(mab, key=lambda x: abs(x[0] - a) + abs(x[1] - b))[-1] for a, b in nab])))

Submission status: Accepted

Solution code:
import math;

n, m = map(int, input().split(" "));
ab = [];
for i in range(0, n):
    ab.append(input().split(" "));

cd = [];
for i in range(0, m):
    cd.append(input().split(" "));

for i in range(0, n):
    dist=9999999999999
    nearm=0;
    for j in range(0, m):
         dist2 = math.fabs(int(ab[i][0]) - int(cd[j][0])) + math.fabs(int(ab[i][1]) - int(cd[j][1]));
         if dist2 < dist:
            dist = dist2;
            nearm=j;
    print(nearm+1);

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
student = []
check = []
ans = []

def add(num,point):
    for i in range(num):
        point.append(input().split())
    for i in range(len(point)):
        for j in range(len(point[i])):
            point[i][j] = int(point[i][j])

add(n,student)
add(m,check)

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

Submission status: Accepted

Solution code:
N, M = list(map(int, input().split()))
a = []
l = []
for i in range(N+M):
    a.append(list(map(int, input().split())))
for i in range(0, N):
    l = []
    for j in range(0, M):
        d = abs((a[i][0] - a[N+j][0])) + abs((a[i][1] - a[N+j][1]))
        l.append(d)
    #print(l)
    print(l.index(min(l))+1)

Submission status: Accepted

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

import sys
import subprocess
import json
import time
import math
import re
import sqlite3

N, M = map(int, input().split())
a = []
b = []
c = []
d = []

for i in range(N):
    a_v, b_v = map(int, input().split())
    a.append(a_v)
    b.append(b_v)

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

for i in range(N):
    res_id = 0
    res = 10000000000
    for j in range(M):
        j_res = abs(a[i] - c[j]) + abs(b[i] - d[j])
        if j_res < res:
            res_id = j
            res = j_res
    print(res_id + 1)

Submission status: Accepted

Solution code:
def calcManhattanDistance(student, checkpoint):
    return abs(student[0] - checkpoint[0]) + abs(student[1] - checkpoint[1])


if __name__ == "__main__":
    # input process
    N, M = map(int, input().split())
    students = [list(map(int, input().split())) for i in range(N)]
    checkpoints = [list(map(int, input().split())) for i in range(M)]

    # calculation process
    for student in students:
        distance_list = []

        for checkpoint in checkpoints:
            distance_list.append(calcManhattanDistance(student, checkpoint))

        # print the first index(+1) of minimum value
        minval = min(distance_list)
        print(distance_list.index(minval) + 1)

    # END

Submission status: Accepted

Solution code:
import sys

# sys.stdin = open('b1.in')


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


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def distance(p1, p2):
    x1, y1 = p1
    x2, y2 = p2
    return abs(x1-x2) + abs(y1 - y2)


n, m = read_int_list()
students = [read_int_list() for i in range(n)]
checkpoints = [read_int_list() for j in range(m)]

for student in students:
    dist = 10 ** 20
    res = -1
    for index, checkpoint in enumerate(checkpoints):
        distance1 = distance(student, checkpoint)
        if distance1 < dist:
            dist = distance1
            res = index + 1
    print(res)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# get a integer
# get two integers separated with half-width break
n, m = map(int, raw_input().split())
# get a string
nn = range(2*n)
mm = range(2*m)
for i in range(n):
    nn[i*2], nn[i*2 + 1] = map(int, raw_input().split())
for i in range(m):
    mm[i*2], mm[i*2 + 1] = map(int, raw_input().split())
#print nn,mm
for i in range(n):
    for j in range(m):
        s = abs(mm[j*2]-nn[i*2]) + abs(mm[j*2+1]-nn[i*2+1])
        if j == 0:
            ma = s
            p = j + 1
        elif s < ma:
            ma = s
            p = j + 1
    print p

Submission status: Accepted

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

a = []
b = []
ans = []
dis = []

for i in range(n):
    p, q = map(int, input().split())
    a.append(p)
    b.append(q)
    ans.append(-1)
    dis.append(100000000000)

for i in range(m):
    x, y = map(int, input().split())
    
    for j in range(n):
        calc_dis = abs(a[j]-x) + abs(b[j]-y)

        if dis[j] > calc_dis:
            ans[j] = i+1
            dis[j] = calc_dis

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Here your code !
import numpy as np
n,m = [int(x) for x in input().split(' ')]
chil = []
check = []
minlist = []
for i in range(n):
    chil.append([int(x) for x in input().split(' ')])
for i in range(m):
    check.append([int(x) for x in input().split(' ')])
for c in chil:
    min = 10**12
    index = 0
    for inde,ch in enumerate(check):
        if abs(ch[1]-c[1]) + abs(ch[0]-c[0]) < min:
            min = abs(ch[1]-c[1]) + abs(ch[0]-c[0])
            index = inde
    minlist.append(index + 1)
for i in minlist:
    print(i)

Submission status: Accepted

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

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

results = [[] for i in range(n)]

for std in std_map:
    print(min(enumerate([abs(std[0] - ch[0]) + abs(std[1] - ch[1]) for ch in ch_map], 1), key=lambda x: x[1])[0])

Submission status: Accepted

Solution code:
a = input().split()
students = int(a[0])
checkpoints = int(a[1])

st_coord = []
for i in range(students):
    b = input().split()
    st_coord.append((int(b[0]), int(b[1])))

ch_coord = []
for j in range(checkpoints):
    c = input().split()
    ch_coord.append((int(c[0]), int(c[1])))


shortest = abs(st_coord[0][0] - ch_coord[0][0]) + abs(st_coord[0][1] - ch_coord[0][1])
for k in range(len(st_coord)):
    index = 1
    shortest = abs(st_coord[k][0] - ch_coord[0][0]) + abs(st_coord[k][1] - ch_coord[0][1])
    for l in range(len(ch_coord)):
        distance = abs(st_coord[k][0] - ch_coord[l][0]) + abs(st_coord[k][1] - ch_coord[l][1])
        if distance < shortest:
            shortest = distance
            index = l + 1
    print(index)