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())
A = [tuple(map(int, input().split())) for i in range(n)]
C = [tuple(map(int, input().split())) for j in range(m)]
for i in range(n):
  res = 1 
  ans = abs(A[i][0] - C[0][0]) + abs(A[i][1] - C[0][1])
  for j in range(m):
    tmp = abs(A[i][0] - C[j][0]) + abs(A[i][1] - C[j][1])
    if tmp < ans:
      ans = tmp
      res = j+1
  print(res)

Submission status: Accepted

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


"""
https://beta.atcoder.jp/contests/abc057/tasks/abc57_1
"""

import sys
import math
from inspect import currentframe

def debug(*args):
    names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args), file=sys.stderr)

N, M = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N)]
CD = [tuple(map(int, input().split())) for _ in range(M)]

for ab in AB:
    dist = [abs(cd[0] - ab[0]) + abs(cd[1] - ab[1]) for cd in CD]
    
    print(dist.index(min(dist)) + 1)

Submission status: Accepted

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

Submission status: Accepted

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

for ab in abList:
    i = 0
    bestPoint = 0
    bestScore = float('inf')
    for cd in cdList:
        dist = abs(ab[0] - cd[0]) + abs(ab[1] - cd[1])
        if dist < bestScore:
            bestScore = dist
            bestPoint = i + 1
        i += 1
    print(bestPoint)

Submission status: Accepted

Solution code:
n,m = (int(_) for _ in input().split())

ni = [0 for i in range(n)]
nj = [0 for i in range(n)]

mi = [0 for i in range(m)]
mj = [0 for i in range(m)]

for i in range(n):
    ni[i],nj[i] = (int(_) for _ in input().split())

for i in range(m):
    mi[i],mj[i] = (int(_) for _ in input().split())

ans = [0 for i in range(n)]

for i in range(n):
    min_dist = abs(ni[i]-mi[0])+abs(nj[i]-mj[0])
    ans[i] = 1
    for j in range(m):
        cur_dist = abs(ni[i]-mi[j])+abs(nj[i]-mj[j])
        if(min_dist > cur_dist):
            min_dist = cur_dist
            ans[i] = j+1

for i in ans:
    print(i)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
stu=[]
chk=[]
for i in range(n):
    tmp,tmp1=map(int,input().split())
    stu.append([tmp,tmp1])
for i in range(m):
    tmp,tmp1=map(int,input().split())
    chk.append([tmp,tmp1])
for student in stu:
    dist = [abs(j[0]-student[0])+abs(j[1]-student[1]) for j in chk]
    print(dist.index(min(dist))+1)

Submission status: Accepted

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

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


# checpoints
ct = []
for i in range(M):
    c, d = list(map(int, input().rstrip().split()))
    ct.append((c, d))

for i in range(N):
    cp = 0
    dist = -1
    for j in range(len(ct) - 1, -1, -1):
        tmp = abs(st[i][0] - ct[j][0]) + abs(st[i][1] - ct[j][1])
        if dist < 0:
            cp = j + 1
            dist = tmp
        else:
            if tmp <= dist:
                cp = j + 1
                dist = tmp


    print(cp)

Submission status: Accepted

Solution code:
N, M = map(int, raw_input().split())
a = [0]*N
b = [0]*N
for i in range(N):
  a[i], b[i] = map(int, raw_input().split())
c = [0]*M
d = [0]*M
for j in range(M):
  c[j], d[j] = map(int, raw_input().split())
for i in range(N):
  mj = 0
  md = abs(a[i]-c[0])+abs(b[i]-d[0])
  for j in range(1, M):
    dj = abs(a[i]-c[j])+abs(b[i]-d[j])
    if dj < md:
      mj = j
      md = dj
  print mj+1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
ab = []
cd = []
for _ in range(n):
    ab.append(list(map(int, input().split())))
for _ in range(m):
    cd.append(list(map(int, input().split())))
    
dis = [[-1]*m for _ in range(n)]
for nn in range(n):
    a, b = ab[nn]
    for mm in range(m):
        c, d = cd[mm]
        dis[nn][mm] = abs(a-c) + abs(b-d)
        
# print(dis)
  
for nn in range(n):
    min_d = min(dis[nn])
    for mm in range(m):
        if dis[nn][mm]==min_d:
            print(mm+1)
            break

Submission status: Accepted

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

for i in range(n):
    tmp = -1
    ans.append('')
    for j in range(m):
        dist = abs(ps[j][0] - stus[i][0]) + abs(ps[j][1] - stus[i][1])
        if tmp == -1 or dist < tmp:
            tmp = dist
            ans[i] = j+1

print('\n'.join(list(map(str,ans))))

Submission status: Accepted

Solution code:
def main():
    n, m = map(int, input().split())
    students = []
    points = []

    for _ in range(n):
        x, y = map(int, input().split())
        students.append((x, y))

    for _ in range(m):
        x, y = map(int, input().split())
        points.append((x, y))

    for s in students:
        idx = 0
        r = distance(s, points[0])

        for i in range(1, m):
            d = distance(s, points[i])
            if d < r:
                idx = i
                r = d
        print(idx + 1)

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

main()

Submission status: Accepted

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

for s in S:
    x, ans = 10**9, 0
    for i, c in enumerate(C):
        y = abs(s[0]-c[0]) + abs(s[1]-c[1])
        if y < x:
            x, ans = y, i+1
    print(ans)

Submission status: Accepted

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

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

for i in range(N):
    distmin = 500000000
    for j in range(M):
        dist = abs(a[i]-c[j]) + abs(b[i]-d[j])
        distmin = min(dist, distmin)
        
    for j in range(M):
        if distmin == abs(a[i]-c[j]) + abs(b[i]-d[j]):
            print(j+1)
            break

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for x in range(n)]
cd = [list(map(int, input().split())) for x in range(m)]
for i in ab:
    atemp = 1000000000
    ans = 0
    for f in range(len(cd)):
        temp = abs(i[0] - cd[f][0]) + abs(i[1] - cd[f][1])
        if atemp > temp:
            atemp = temp
            ans = f + 1
    print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
from sys import maxsize


def main() -> int:
    n = next_int()
    m = next_int()

    students = [tuple(map(int, input().split())) for _ in range(n)]
    check_points = [tuple(map(int, input().split())) for _ in range(m)]

    for i in range(n):
        index = 0
        value = maxsize
        for j in range(m):
            x1 = students[i][0]
            y1 = students[i][1]
            x2 = check_points[j][0]
            y2 = check_points[j][1]
            calc_result = calc(x1, x2, y1, y2)

            if calc_result < value:
                index = j
                value = calc_result
        print(index + 1)
    return 0


def calc(x1, x2, y1, y2: int) -> int:
    return abs(x1 - x2) + abs(y1 - y2)


def next_int() -> int:
    return int(next_str())


def next_str() -> str:
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def create_list(n):
    result = [[i for i in map(int,input().split())] for j in range(n)]
    return result 

n,m = map(int,input().split())
x_list   = create_list(n)
y_list   = create_list(m)

for x in x_list:
    ans   = 0
    min_n = float('inf')
    for i,y in enumerate(y_list):
        temp = abs(x[0]-y[0]) + abs(x[1]-y[1])
        if temp < min_n:
            min_n = temp
            ans = i+1
    print(ans)

Submission status: Accepted

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

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

for i in range(n):
	p = (abs(s[i][0]-c[0][0])+abs(s[i][1]-c[0][1]))
	q = 0
	for j in range(m-1):
		p = min(p,abs(s[i][0]-c[j][0])+abs(s[i][1]-c[j][1]))
		if abs(s[i][0]-c[j+1][0])+abs(s[i][1]-c[j+1][1])<p:
			q = j+1
	print(q+1)

Submission status: Accepted

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

for i in range(N):
    length = 10**9
    ind = 0
    for j in range(M):
        man =  abs(a[i] - c[j])+abs(b[i] - d[j])
        if length > man:
            length = man
            ind = j+1
    ans.append(ind)

for i in ans:
    print(i)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
s=[]
p=[]
md=[[None,float('INF')] for i in range(n)]
for i in range(n):
    t1,t2=map(int,input().split())
    s.append([t1,t2])
for i in range(m):
    t1,t2=map(int,input().split())
    p.append([t1,t2])
for i in range(n):
    for j in range(m):
        if md[i][1]>abs(s[i][0]-p[j][0])+abs(s[i][1]-p[j][1]):
            md[i][0]=j+1
            md[i][1]=abs(s[i][0]-p[j][0])+abs(s[i][1]-p[j][1])
for i in range(n):
    print(md[i][0])

Submission status: Accepted

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

for i in range(N):
    minlength = float("inf")
    nearpoint = 0
    for j in range(M):
        if minlength > abs(S[i][0] - C[j][0]) + abs(S[i][1] - C[j][1]):
            minlength = abs(S[i][0] - C[j][0]) + abs(S[i][1] - C[j][1])
            nearpoint = j+1
    print(nearpoint)

Submission status: Accepted

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

listForStudent = []
index=0
while index < n:
    listI = list(map(int, input().split()))
    listForStudent.append(listI)
    index+=1

listForCheck=[]
index2=0
while index2 < m:
    listI2= list(map(int, input().split()))
    listForCheck.append(listI2)
    index2+=1

index3=0
listForAnswer=[]
while index3 < len(listForStudent):
    answer=2*(10**8)
    index4=0
    while index4 < len(listForCheck):
        if index4==0:
            indexA = index4+1
        distX = max(listForCheck[index4][0], listForStudent[index3][0]) - \
            min(listForCheck[index4][0], listForStudent[index3][0])
        distY = max(listForCheck[index4][1], listForStudent[index3][1]) - \
            min(listForCheck[index4][1], listForStudent[index3][1])
        totalDist = distX+distY
        if answer > totalDist:
            answer = totalDist
            indexA = index4+1
        index4+=1
    listForAnswer.append(indexA)
    index3+=1

for ans in listForAnswer:
    print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

ab_list = []
cd_list = []

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

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

for a, b in ab_list:
    num = -1
    min_num = 10 ** 10 + 1
    count = 0
    for c, d in cd_list:
        count += 1
        distance = abs(a-c) + abs(b-d)
        if distance < min_num:
            min_num = distance
            num = count
    print(num)

Submission status: Accepted

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

a = []
b = []

c = []
d = []

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

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



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

        elif cal == buf:
            buf = cal
            ans = min(ans, j)

    print(ans + 1)

Submission status: Accepted

Solution code:
N, M  = map( int, input().split())
A = [ list( map( int, input().split())) for _ in range(N)]
C = [ list( map( int, input().split())) for _ in range(M)]
for i in range(N):
    ans = 1
    x, y = A[i]
    path = abs(x-C[0][0]) + abs(y-C[0][1])
    for j in range(1,M):
        if path > abs(x-C[j][0]) + abs(y-C[j][1]):
            ans = j+1
            path = abs(x-C[j][0]) + abs(y-C[j][1])
    print(ans)

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
list_stu = []
for i in range(0,n):
    list_stu.append(list((map(int, input().split()))))
#print(list_stu)
list_check = []
for i in range(0,m):
    list_check.append(list((map(int, input().split()))))
#print(list_check)
for stu in list_stu:
    min = 10 ** 9
    min_point = 0
    for check in list_check:
        #print(abs(stu[0] - check[0]) + abs(stu[1] - check[1]))
        if min > (abs(stu[0] - check[0]) + abs(stu[1] - check[1])):
            min = abs(stu[0] - check[0]) + abs(stu[1] - check[1])
            min_point = list_check.index(check) + 1
    print(min_point)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
p = [list(map(int, input().split())) for _ in range(n)]
q = [list(map(int, input().split())) for _ in range(m)]
ans = [0]*n
for i in range(n):
    comp = abs(p[i][0]-q[0][0]) + abs(p[i][1]-q[0][1])
    for j in range(m):
        temp = abs(p[i][0]-q[j][0]) + abs(p[i][1]-q[j][1])
        if temp < comp:
            ans[i] = j
            comp = temp
for i in range(n):
    print(ans[i]+1)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
a = []
b = []
c = []
d = []
ansmin = 10**10
for i in range(n):
    tempa,tempb = map(int,input().split())
    a.append(tempa)
    b.append(tempb)
for j in range(m):
    tempc,tempd = map(int,input().split())
    c.append(tempc)
    d.append(tempd)

for i in range(n):
    ansindex = 10**10
    ansmin = 10**10
    for j in range(m):
        temp_min = abs(a[i]-c[j])+abs(b[i]-d[j]) 
        if temp_min < ansmin:
            ansindex = j+1
            ansmin = temp_min
    print(ansindex)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
A = []
B = []
C = []
D = []
for i in range(N) :
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
for j in range(M) :
    c,d = map(int,input().split())
    C.append(c)
    D.append(d)
for k in range(N) :
    distance = 10**17
    answer = -1
    for l in range(M) :
        p = abs(A[k]-C[l])
        q = abs(B[k]-D[l])
        d = p+q
        if d < distance :
            distance = d
            answer = l+1
    print(answer)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
a=[list(map(int,input().split())) for i in range(N)]
b=[list(map(int,input().split())) for i in range(M)]
for i in range(N):
    dmin=abs(a[i][0]-b[0][0])+abs(a[i][1]-b[0][1])
    num=1
    for j in range(M):
        dist=abs(a[i][0]-b[j][0])+abs(a[i][1]-b[j][1])
        if dmin>dist:
            dmin=dist
            num=j+1
    print(num)

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


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

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

    for a, b in s:
        ans = 0
        min_dist = INF
        for i, (c, d) in enumerate(p):
            dist = abs(a - c) + abs(b - d)
            if dist < min_dist:
                ans = i + 1
                min_dist = dist
        print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

for n in range(N):
    a,b = A[n],B[n]
    ind = 0
    for m in range(M):
        c,d = C[m],D[m]
        diff = abs(a-c) + abs(b-d)

        if ind == 0:
            ind = 1
            ans = diff
        elif diff < ans:
            ind = m+1
            ans = diff

    print(ind)

Submission status: Accepted

Solution code:
import math
def distance(x, y, i, j):
    return abs(x - i) + abs(y - j)

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

for i in student:
    mini = 1000000000000
    minicp = 0
    for k in range(M):
        j = checkpoint[k]
        if distance(i[0], i[1], j[0], j[1]) < mini:
            mini = distance(i[0], i[1], j[0], j[1])
            minicp = k + 1
    print(minicp)

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())

n,m = li()
stu = []
for _ in range(n):
    stu.append(tuple(li()))
chk = []
for _ in range(m):
    chk.append(tuple(li()))
    
for s in stu:
    ans_cand = []
    for c in chk:
        ans_cand.append(abs(c[0] - s[0]) + abs(c[1] - s[1]))
    
    ans = min(ans_cand)
    print(ans_cand.index(ans) + 1)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
A = [tuple(map(int,input().split())) for i in range(N)]
C = [tuple(map(int,input().split())) for i in range(M)]
for ax,ay in A:
    min_d = 10**10
    min_i = -1
    for i,(cx,cy) in enumerate(C):
        d = abs(ax-cx) + abs(ay-cy)
        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())
p=[list(map(int,input().split())) for i in range(n)]
q=[list(map(int,input().split())) for i in range(m)]
for x in range(n):
  c=[]
  for y in range(m):
    c.append(abs(p[x][0]-q[y][0])+abs(p[x][1]-q[y][1]))
  print(c.index(min(c))+1)

Submission status: Accepted

Solution code:
N, M = 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())))

def manh_dist(S, C):
  return abs(S[0] - C[0]) + abs(S[1] - C[1])
  
for i in range(N):
  index = M+1
  dist = 1e9
  for j in range(M):
    #print(manh_dist(S[i], C[j]), dist)
    if dist > manh_dist(S[i], C[j]):
      dist = manh_dist(S[i], C[j])
      index = j
  print(index+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 ab in AB:
    m=float('inf')
    for i,cd in enumerate(CD):
        if m>abs(ab[0]-cd[0])+abs(ab[1]-cd[1]):
            m=abs(ab[0]-cd[0])+abs(ab[1]-cd[1])
            tmp=i+1
    print(tmp)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Sep  2 16:39:28 2018
ABC057B
@author: maezawa
"""

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

sx = []
sy = []
cx = []
cy = []

for i in range(n):
    sxi, syi = list(map(int, input().split()))
    sx.append(sxi)
    sy.append(syi)
    
for i in range(m):
    cxi, cyi = list(map(int, input().split()))
    cx.append(cxi)
    cy.append(cyi)

for i in range(n):
    l = 10**9
    nj = 0
    for j in range(m):
        lj = abs(sx[i]-cx[j])+abs(sy[i]-cy[j])
        if l > lj:
            l = lj
            nj = j
            #print('({},{}), ({}, {})'.format(sx[i],sy[i],cx[j],cy[j]))
    print(nj+1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
s = [list(map(int, input().split())) for _ in range(n)]
p = [list(map(int, input().split())) for _ in range(m)]
for i in range(n):
    mindis = 10 ** 9
    for j in range(m):
        dis = abs(s[i][0] - p[j][0]) + abs(s[i][1] - p[j][1])
        if mindis > dis:
            point = j+1
            mindis = dis
    print(point)

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

for i in range(N):
    dist = []

    for j in range(M):
        tmp = abs(a[i]-c[j]) + abs(b[i]-d[j])
        dist.append(tmp)

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

Submission status: Accepted

Solution code:
import numpy as p;
n,m=map(int,input().split())
a=[list(map(int,input().split()))for _ in[0]*(int(n)+int(m))]
for x,y in a[:n]:
    print(1+p.argmin(list(abs(x-X)+abs(y-Y)for X,Y in a[n:])))

Submission status: Accepted

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

nList = [list(map(int, input().split())) for _ in range(n)]
mList = [list(map(int, input().split())) for _ in range(m)]

for i in range(n):
    minDistance = 10**9
    for j in range(m):
        d = abs(nList[i][0]-mList[j][0]) + abs(nList[i][1]-mList[j][1])
        if d < minDistance:
            minDistance = d
            mIndex = j + 1
    print(mIndex)

Submission status: Accepted

Solution code:
#57b
n,m = map(int,input().split())
a=[list(map(int,input().split())) for _ in range(n)]
b=[list(map(int,input().split())) for _ in range(m)]

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

Submission status: Accepted

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

Submission status: Accepted

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

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

    ab_list = []
    cd_list = []
    for _ in range(n):
        ab_list.append(list(map(int, input().split())))
    for _ in range(m):
        cd_list.append(list(map(int, input().split())))
    
    for i in ab_list:
        min_distance = float('inf')
        for j in range(m):
            distance = abs(i[0] - cd_list[j][0]) + abs(i[1] - cd_list[j][1])
            if distance < min_distance:
                min_distance = distance
                min_coord = j + 1
        print(min_coord)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
s = [map(int,input().split()) for i in range(N)]
c = [list(map(int,input().split())) for i in range(M)]
for x1, y1 in s:
    m = float('inf')
    mi = 0
    for i,(x2, y2) in enumerate(c):
        if m > abs(x1-x2) + abs(y1-y2):
            m = abs(x1-x2) + abs(y1-y2)
            mi = i+1
    print(mi)

Submission status: Accepted

Solution code:
f=lambda x,y:abs(x[0]-y[0])+abs(x[1]-y[1])
N,M=map(int,input().split())
l=[tuple(map(int,input().split())) for _ in range(N)]
m=[tuple(map(int,input().split())) for _ in range(M)]
for i in l:
  print(min([(f(i,j),k+1) for (k,j) in enumerate(m)])[1])

Submission status: Accepted

Solution code:
n, m = list(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:
    min_dist = 4*10**8+1
    for i, (c, d) in enumerate(cd):
        dist = abs(a-c)+abs(b-d)
        if dist < min_dist:
            min_dist = dist
            ans = i+1
    print(ans)

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 nx, ny in ab:
    distances = [abs(nx-mx)+abs(ny-my) for mx, my in cd]
    print(distances.index(min(distances))+1)

Submission status: Accepted

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

for a, b in ab:
    ans = [None, float('inf')]
    for i in range(M):
        c, d = cd[i]
        d = abs(a - c) + abs(b - d)
        if ans[1] > d:
            ans = [i + 1, d]
    print(ans[0])

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
a = [list(map(int,input().split())) for i in range(N)]
c = [list(map(int,input().split())) for j in range(M)]
ans=[]
for i in a:
    temp=4*10**8
    temp2=50
    for j in range(M):
        if abs(i[0]-c[j][0])+abs(i[1]-c[j][1])<temp:
            temp=abs(i[0]-c[j][0])+abs(i[1]-c[j][1])
            temp2=j+1
    ans.append(temp2)
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
stu=[]
for i in range(n):
    stu.append(list(map(int,input().split())))
check=[]
for i in range(m):
    check.append(list(map(int,input().split())))
for i in stu:
    res=float('inf')
    point=-1
    for q,j in enumerate(check):
        tmp = abs(i[0]-j[0])+abs(i[1]-j[1])
        if res>tmp:
            res=tmp
            point=q+1
    print(point)