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())
n=[list(map(int,input().split())) for _ in range(N)]
m=[list(map(int,input().split())) for _ in range(M)]
result=[]
for i in range(len(n)):
  result=[]
  for j in range(len(m)):
    result.append(abs(n[i][0]-m[j][0])+abs(n[i][1]-m[j][1]))
  print(result.index(min(result))+1)

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 a:
  cnt=2*(10**16)
  ans=0
  for j in range(len(b)):
    if abs(i[0]-b[j][0])+ abs(i[1]-b[j][1])<cnt:
      cnt=abs(i[0]-b[j][0])+ abs(i[1]-b[j][1])
      ans=j+1
  print(ans)

Submission status: Accepted

Solution code:
def mht(a,b):
	return abs(a[0]-b[0])+abs(a[1]-b[1])
n,m=map(int,input().split())
p=[list(map(int,input().split())) for _ in range(n)]
c=[list(map(int,input().split())) for _ in range(m)]
for i in p:
	a=[10**9,0]
	for j in range(m):
		if mht(i,c[j])<a[0]:
			a=[mht(i,c[j]),j+1]
	print(a[1])

Submission status: Accepted

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

    cd = [None] * M
    for j in range(M):
        cd[j] = list(map(int, input().split()))
    ans = [None] * N
    for i in range(N):
        Md = 10**16
        for j in range(M):
            Md_temp = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
            if Md > Md_temp:
                Md = Md_temp
                ans[i] = j + 1

    print("\n".join(map(str, ans)))


if __name__ == "__main__":
    main()

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 i in range(N):
    a, b = AB[i]
    x = abs(CD[0][0]-a)+abs(CD[0][1]-b)
    y = 0
    for j in range(1, M):
        c, d = CD[j]
        ky = abs(c-a)+abs(d-b)
        if ky < x:
            x = ky
            y = j
    print(y+1)

Submission status: Accepted

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

for i in range(n):
    p=0
    ans=10**9
    for j in range(m):
        dis=abs(lc[j][1]-ls[i][1])+abs(lc[j][0]-ls[i][0])
        if ans>dis:
            ans=dis
            p=j+1
    print(p)

Submission status: Accepted

Solution code:
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

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

def gg(pos, ssl):
	mmm=m_dist(pos,ssl[0])
	m_id=0
	for i, q in enumerate(ssl[1:], 1):
		td=m_dist(pos, q)
		if td < mmm:
			mmm = td
			m_id = i
	return m_id
		
def main():
	#a = int(input())
	n, m = tin()
	#s = input()
	pl=[lin() for _ in range(n)]
	ssl = [lin() for _ in range(m)]
	for p in pl:
		r = gg(p, ssl)
		#pa((p,ssl))
		print(r+1)
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

Solution code:
def resolve():
    N, M = [int(i) for i in input().split()]
    aabb = [list(map(int, input().split())) for _ in range(N)]
    ccdd = [list(map(int, input().split())) for _ in range(M)]
    for i in range(N):
        a, b = aabb[i]
        minPoint = -1
        minV = 10**9
        for j in range(M):
            c, d = ccdd[j]
            v = abs(a - c) + abs(b - d)
            if v < minV:
                minPoint = j + 1
            minV = min(minV, v)
        print(minPoint)


resolve()

Submission status: Accepted

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

S, C = [], []
for _ in range(N):
    a, b = map(int, input().split())
    S.append((a, b))

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

for a, b in S:
    ans = None
    min_dist = 1 << 32
    for i, (c, d) in enumerate(C):
        dist = abs(c - a) + abs(d - b)
        if dist < min_dist:
            min_dist = dist
            ans = i
    print(ans + 1)

Submission status: Accepted

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

list_a = []
list_b = []
count = 0

for i in range(N):
    a = [int(i) for i in input().split()]
    list_a.append(a)
    
for i in range(M):
    b = [int(i) for i in input().split()]
    list_b.append(b)
    
for i in range(N):
    ans_x = 10**18
    for j in range(M):
        x = abs(list_a[i][0]-list_b[j][0])
        y = abs(list_a[i][1]-list_b[j][1])
        xxx = x + y
        if xxx < ans_x:
            ans_x = xxx
            count = j+1
    print(count)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
ab = [0]*n
cd = [0]*m
for i in range(n):
    ab[i] = list(map(int,input().split()))
for i in range(m):
    cd[i] = list(map(int,input().split())) + [i]
for a,b in ab:
    dis = [0]*m
    for c,d,i in cd:
        dis[i] = [abs(a-c) + abs(b-d)] + [i+1]
    dis.sort(key= lambda val : val[0])
    print(dis[0][1])

Submission status: Accepted

Solution code:
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)]

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

ans = []

for a, b in ab:
    best_ind = None
    best_dist = float('inf')
    for j, (c, d) in enumerate(cd):
        tmp_dist = meter(a, b, c, d)
#         print(f'{a=}, {b=}, {c=}, {d=}, {tmp_dist=}, {j=}')
        if tmp_dist < best_dist:
#             print('update')
            best_dist = tmp_dist
            best_ind = j+1
    print(best_ind)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
ab=[[int(j) for j in input().split()] for i in range(n)]
cd=[[int(j) for j in input().split()] for i 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 getN():
    return int(input())


def getNM():
    return map(int, input().split())


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


from collections import defaultdict, deque, Counter
from sys import exit
import math
import copy
from bisect import bisect_left, bisect_right
from heapq import *
import sys

# sys.setrecursionlimit(1000000)
INF = 10 ** 17
MOD = 1000000007

from fractions import *


def inverse(f):
    # return Fraction(f.denominator,f.numerator)
    return 1 / f


def combmod(n, k, mod=MOD):
    ret = 1
    for i in range(n - k + 1, n + 1):
        ret *= i
        ret %= mod

    for i in range(1, k + 1):
        ret *= pow(i, mod - 2, mod)
        ret %= mod

    return ret

MOD = 10 ** 9 + 7

def dist(a, b):
    return abs(a[0] - b[0]) + abs(a[1] - b[1])
def solve():
    n, m = getList()
    st = []
    for i in range(n):
        st.append(getList())

    ch = []
    for i in range(m):
        ch.append(getList())

    for s in st:
        tmp = 10 ** 9
        ans = -1
        for idx, c in enumerate(ch):
            if dist(s, c) < tmp:
                ans = idx + 1
                tmp = dist(s,c)

        print(ans)


def main():
    n = getN()
    for _ in range(n):
        solve()


if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
#!python3

LI = lambda: list(map(int, input().split()))

# input
N, M = LI()
AB = [LI() for _ in range(N)]
CD = [LI() for _ in range(M)]

INF = 10 ** 15


def distance(i, j):
    d = abs(AB[i][0] - CD[j][0]) + abs(AB[i][1] - CD[j][1])
    return d


def solve(i):
    # distance, number
    w = (INF, INF)
    for j in range(M):
        t = (distance(i, j), j + 1)
        w = min(w, t)
    return w[1]


def main():
    for i in range(N):
        ans = solve(i)
        print(ans)
    
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import numpy as np

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):
    person = np.asarray(ab[i])
    shortest = 10**18
    for j in range(M):
        point = np.asarray(cd[j])
        diflist = person - point
        dif = abs(diflist[0])+abs(diflist[1])
        if dif < shortest:
            shortest = dif
            count = j+1
    print(count)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    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:
        min_dist = f_inf
        res = 0
        for i in range(m):
            c, d = CD[i]
            dist = abs(a - c) + abs(b - d)
            if min_dist > dist:
                min_dist = dist
                res = i + 1
        print(res)


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    S = [[int(a) for a in input().split()] for _ in range(N)]
    C = [[int(c) for c in input().split()] for _ in range(M)]
    Ans = [1] * N
    for i in range(N):
        a, b = S[i]
        dist = abs(a - C[0][0]) + abs(b - C[0][1])
        for j in range(1, M):
            tdist = abs(a - C[j][0]) + abs(b - C[j][1])
            if tdist < dist:
                dist = tdist
                Ans[i] = j + 1
    print(*Ans, sep="\n")
    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from fractions import gcd
#from itertools import combinations # (string,3) 3回
#from collections import deque
from collections import defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n,m = readInts()
a = [0] * n;b = [0]*n;c = [0] * m;d = [0]*m;
for i in range(n):
    a_,b_ = readInts()
    a[i] = a_;b[i]=b_;
for i in range(m):
    c_,d_ = readInts()
    c[i] = c_;d[i] = d_;
for A,B in zip(a,b):
    MIN = float('inf')
    i = 1
    for C,D in zip(c,d):
        man = abs(C-A) + abs(D-B)
        if man < MIN:
            idx = i
            MIN = man
        i += 1
    print(idx)

Submission status: Accepted

Solution code:
import math
import string
import collections
from collections import Counter
from collections import deque
from decimal import Decimal
import sys
import fractions


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n, m = map(int, input().split())
ab = [0]*n
cd = [0]*m
for i in range(n):
    ab[i] = readints()
for i in range(m):
    cd[i] = readints()
# print(ab)
# print(cd)
x = []
for i in range(n):
    tmp_li = []
    ans = 10**100
    tmp = 0
    for j in range(m):
        tmp = abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
        # print(ab[i][0], cd[j][0], ab[i][1], cd[j][1])
        # print(i, j)
        tmp_li.append(tmp)
    # print(tmp_li)
    x.append(tmp_li.index(min(tmp_li)))
# print(x)
for i in range(len(x)):
    y = x[i]+1
    print(y)

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):
  ma = 10000000000
  ans = 0
  for j in range(M):
    a = abs(ab[i][0]-cd[j][0]) + abs(ab[i][1]-cd[j][1])
    if ma > a:
      ans = j+1
      ma = a
  print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N)]
XY = [tuple(map(int, input().split())) for _ in range(M)]

ans = [0] * N
for i, (a, b) in enumerate(AB):
    d = abs(XY[0][0] - a) + abs(XY[0][1] - b)
    for j, (x, y) in enumerate(XY):
        e = abs(a - x) + abs(b - y)
        if d > e:
            ans[i] = j
            d = e

print(*[a + 1 for a in ans], sep='\n')

Submission status: Accepted

Solution code:
def dist(x,y):
    return abs(x[0]-y[0])+abs(x[1]-y[1])
N,M = map(int,input().split())
X = [list(map(int,input().split())) for _ in range(N)]
Y = [list(map(int,input().split())) for _ in range(M)]
for i in range(N):
    dmin = 10**9
    for j in range(M-1,-1,-1):
        d = dist(X[i],Y[j])
        if d<=dmin:
            dmin = d
            ind = j+1
    print(ind)

Submission status: Accepted

Solution code:
from sys import exit
import math
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n,m=mi()
a =  [list(map(int, input().split())) for i in range(n)]
c =  [list(map(int, input().split())) for i in range(m)]

INF = 100000000000
dis = INF
ans = 0
for i in range(n):
    for j in range(m):
        if abs(a[i][0]-c[j][0]) + abs(a[i][1]-c[j][1]) < dis:
            dis = abs(a[i][0]-c[j][0]) + abs(a[i][1]-c[j][1])
            ans = j+1

    print(ans)
    dis = INF
    ans = 0

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=[]
b=[]
for i in range(n):
  x,y=map(int,input().split())
  a.append([x,y])
for i in range(m):
  x,y=map(int,input().split())
  b.append([x,y])
for i in a:
  ans=10**18
  t=0
  for j in range(m):
    if abs(i[0]-b[j][0])+abs(i[1]-b[j][1])<ans:
      t=j+1
      ans=abs(i[0]-b[j][0])+abs(i[1]-b[j][1])
  print(t)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
ab = []
for i in range(n):
    ai, bi = map(int, input().split())
    ab.append([ai, bi])
cd = []
for i in range(m):
    ci, di = map(int, input().split())
    cd.append([ci, di])

ans = []
for i in range(n):
    ai, bi = ab[i]
    mini = 10**10
    for j in range(m):
        cj, dj = cd[j]
        dist = abs(ai-cj) + abs(bi-dj)
        if dist < mini:
            mini = dist
            ret = j+1
    ans.append(ret)

for ret in ans:
    print(ret)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
ans=[]
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:
  anss=0
  mm=10**20
  for i in range(m):
    mmm=abs(a-cd[i][0])+abs(b-cd[i][1])
    if mm>mmm:
      anss=i+1
      mm=mmm
  ans.append(anss)
print(*ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from collections import *

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 a, b in ab:
    m = min(abs(a-c)+abs(b-d) for c, d in cd)
    
    for i in range(M):
        if abs(a-cd[i][0])+abs(b-cd[i][1])==m:
            print(i+1)
            break

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)]
d = {}
for i in range(n):
    for j in range(m):
        d[j] = abs(s[i][0]-c[j][0])+abs(s[i][1]-c[j][1])
    t = sorted(d.items(), key=lambda x:x[1])
    print(t[0][0]+1)
    d = {}

Submission status: Accepted

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

for i in range(n):
    ai,bi=map(int,input().split())
    a.append(ai)
    b.append(bi)
    
for j in range(m):
    ci,di=map(int,input().split())
    c.append(ci)
    d.append(di)
    
for i in range(n):
    for j in range(m):
        x.append(abs(a[i]-c[j]))
        y.append(abs(b[i]-d[j]))
        l.append(x[j+i*m]+y[j+i*m])
    
    p.append(l.index(min(l))+1)   
    l=[]
    #x=[]
    #y=[]
    
for i in range(n):
    print(p[i])

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
s = [list(map(int, input().split())) for i in range(n)]
c = [list(map(int, input().split())) for j in range(m)]
for k in range(n):
    x = abs(s[k][0] - c[0][0]) + abs(s[k][1] - c[0][1])
    ans = 1
    for l in range(1, m):
        y = abs(s[k][0] - c[l][0]) + abs(s[k][1] - c[l][1])
        if y < x:
            x = y
            ans = l + 1
        elif y == x:
            x = y
    print(ans)

Submission status: Accepted

Solution code:
N,M = [int(i) for i in input().split()]
a = [[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)]

n = 100000000000
n1 = 0
n2 = 0

for i in range(N):
    for j in range(M):
        n1 = abs(c[j][0] - a[i][0]) + abs(c[j][1] - a[i][1])
        if n1 < n:
            n = n1
            n2 = j
    n = 100000000000
    print(n2 + 1)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
a = [tuple(map(int,input().split())) for i in range(n)]
b = [tuple(map(int,input().split())) for i in range(m)]
inf = float("inf")
for ai,bi in a:
    d,num = inf,0
    for i in range(m):
        ci,di = b[i]
        x = abs(ai-ci)+abs(bi-di)
        if d > x:
            d = x
            num = i+1
    print(num)

Submission status: Accepted

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

for i in range(N):
    for j in range(M):
        dis = abs(A[i][0] - B[j][0]) + abs(A[i][1] - B[j][1])
        if j == 0:
            min = dis
            tmp = j
        else:
            if dis < min:
                min = dis
                tmp = j
    print(tmp+1)

Submission status: Accepted

Solution code:

def calc(N, M, student, point) : 
  translatepoint = list()
  for i in range(N) : 
    mindistance = 10 ** 9
    minpoint = -1
    for j in range(M) : 
      distance = abs(student[i][0] - point[j][0]) + abs(student[i][1] - point[j][1])
      if distance < mindistance : 
        mindistance = distance
        minpoint = j + 1
    
    translatepoint.append(minpoint)
  return translatepoint


N, M = tuple(map(int, input().split()))
student = list()
point = list()

for i in range(N) : 
  student.append(tuple(map(int, input().split())))
  
for j in range(M) : 
  point.append(tuple(map(int, input().split())))
  
ans = calc(N, M, student, point)

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

Submission status: Accepted

Solution code:
def dist(x,y):
  return abs(x[0]-y[0])+abs(x[1]-y[1])

n,m = map(int,input().split())
s = []
for _ in range(n):
  a,b = map(int,input().split())
  s.append((a,b))
c = []
for _ in range(m):
  c_,d = map(int,input().split())
  c.append((c_,d))
for i in range(n):
  p = s[i]
  md = 10**10
  mi = 0
  for j in range(m):
    ch = c[j]
    d = dist(p,ch)
    if md > d:
      md = d
      mi = j
  print(mi+1)

Submission status: Accepted

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

students = [[int(i) for i in input().split()] for _ in range(n)]
checkpoints = [[int(i) for i in input().split()] for _ in range(m)]

d = []
for i in range(n) :
    d.clear()
    ans = 0
    for j in range(m) :
        x = abs(students[i][0]-checkpoints[j][0])+abs(students[i][1]-checkpoints[j][1])
        d.append(x)
    ans = d.index(min(d))+1
    print(ans)

Submission status: Accepted

Solution code:
def list_add(l1, l2):
    tmp = [abs(a-b) for a, b in zip(l1, l2)]
    return tmp


# manhattan distance |x1-x2|+|y1-y2|
N, M = map(int, input().split())
students = [[int(i) for i in input().split()] for _ in range(N)]
checkpoints = [[int(i) for i in input().split()] for _ in range(M)]

for i in students:
    cur_point = 0
    min_point = 1
    smallest = sum(list_add(i, checkpoints[0]))
    for j in checkpoints:
        cur_point += 1
        sum_li = sum(list_add(i, j))
        if sum_li < smallest:
            smallest = sum_li
            min_point = cur_point
    print(min_point)

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

ans = []
for i in range(n):
  d = {}
  for j in range(m):  
    d[j + 1] = abs(s[i][0] - c[j][0]) + abs(s[i][1] - c[j][1])
  d = sorted(d.items(), key=lambda x:x[1])
  ans.append(d[0][0])
for e in ans:
  print(e)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def main():
    N,M = [int(i) for i in input().strip().split()]
    students = [[int(i) for i in input().strip().split()] for _ in range(N)]
    checkpoints = [[int(i) for i in input().strip().split()] for _ in range(M)]
    ans = [0] * N

    for i,student in enumerate(students):
        dist = [float("inf")] * M
        for j, checkpoint in enumerate(checkpoints):
            dist[j] = abs(student[0] - checkpoint[0]) + abs(student[1] - checkpoint[1])
        ans[i] = dist.index(min(dist)) + 1

    return ans


if __name__ == "__main__":
    for n in main():
        print(n)

Submission status: Accepted

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

a=[0]*N
b=[0]*N
c=[0]*M
d=[0]*M


for i in range(N):
    a[i],b[i] = map(int,input().split())
    
    
for i in range(M):
    c[i],d[i] = map(int,input().split())
    
    
for i in range(N):
    x = a[i]
    y = b[i]
    
    for j in range(M):
        
        cx = c[j]
        cy = d[j]
        
        temp = abs(cx-x) + abs(cy-y)
        
        if j==0:
            Min = temp
            result =1
        elif Min > temp:
            result = j+1
            Min = temp
            
            
    print(result)

Submission status: Accepted

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

student = list()

for x in range(n):
    student.append(list(map(int, input().split())))

checkpoint = list()

for y in range(m):
    checkpoint.append(list(map(int, input().split())))

INF = 4*(10**8) + 1
tmp = INF
ans = 51

for x in range(n):
    for y in range(m-1, -1, -1):
        distance = abs(student[x][0] - checkpoint[y][0]) + \
            abs(student[x][1] - checkpoint[y][1])

        if tmp >= distance:
            tmp = distance
            ans = y
    print(ans+1)
    tmp = INF

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 a, b in ab:
  cost, idx = 10**18, 0
  for i, (c, d) in enumerate(cd):
    if cost > abs(a - c) + abs(b - d):
      cost = abs(a - c) + abs(b - d)
      idx = i + 1
  print(idx)

Submission status: Accepted

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

for i in range(n) :
  cost, ans = 10**18, 0
  for j in range(m) :
    if cost > abs(a[i] - c[j]) + abs(b[i] - d[j]) :
      cost = abs(a[i] - c[j]) + abs(b[i] - d[j])
      ans = j+1
  print(ans)

Submission status: Accepted

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

for i in range(N):
  closed_manhattan=10**16
  closed_j=0
  for j in range(M):
    x=abs(students[i][0]-checks[j][0])
    y=abs(students[i][1]-checks[j][1])
    manhattan=x+y
    if closed_manhattan > manhattan:
      closed_manhattan=manhattan
      closed_j=j+1
  print(closed_j)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
ls = [list(map(int,input().split())) for _ in range(n)]
di = [list(map(int,input().split())) for _ in range(m)]
mn = [float("inf")]*n
num = [0]*n
for i in range(n):
    for j in range(m):
        k = abs(ls[i][0]-di[j][0]) + abs(ls[i][1]-di[j][1])
        if k < mn[i]:
            mn[i] = k
            num[i] = j+1
for p in range(n):
    print(num[p])

Submission status: Accepted

Solution code:
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
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)]

Ans = [-1]*N
for i in range(N):
    a,b = AB[i]
    md0 = 10**10

    for j in range(M):
        c,d = CD[j]
        md = abs(a-c) + abs(b-d)
        if md < md0:
            md0 = md
            Ans[i] = (j+1)

for ans in Ans:
    print(ans)

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

N, M = map(int, readline().split())
students = []
for _ in range(N):
    a, b = map(int, readline().split())
    students.append((a, b))
flags = []
for _ in range(M):
    c, d = map(int, readline().split())
    flags.append((c, d))


# マンハッタン距離を計算する
def calc(x1, y1, x2, y2):
    return abs(x1 - x2) + abs(y1 - y2)

ans = [0] * N
distances = [INF] * N
for i, (x1, y1) in enumerate(students):
    for j, (x2, y2) in enumerate(flags):
        dis = calc(x1, y1, x2, y2)
        # print("i: {} j: {} dis: {}".format(i, j, dis))
        if dis < distances[i]:
            ans[i] = j + 1
            distances[i] = dis

for a in ans:
    print(a)

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 j in range(m)]

L = []
for i in range(n):
  l = []
  for j in range(m):
    d = abs(A[i][0] - B[j][0]) + abs(A[i][1] - B[j][1])
    l.append(d)
  L.append(l)
  
for i in range(n):
  print(L[i].index(min(L[i]))+1)

Submission status: Accepted

Solution code:
import numpy as np
s = list(map(int, input().split()))
n=s[0]
m=s[1]
student=[]
check=[]
for i in range(n):
    s = list(map(int, input().split()))
    student.append(s)
for i in range(m):
    s = list(map(int, input().split()))
    check.append(s)
student=np.array(student)
check=np.array(check)
for i in student:
    c=np.copy(check)
    c=np.abs(c-i)
    c=c[:,0]+c[:,1]
    print(np.argmin(c)+1)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
s = []
for _ in range(N):
    a,b = map(int,input().split())
    s.append((a,b))
check = []
for _ in range(M):
    c,d = map(int,input().split())
    check.append((c,d))
res_list = []
for i in s:
    a = i[0]
    b = i[1]
    tmp = 1e+9
    res = 0
    for j in range(len(check)):
        c = check[j][0]
        d = check[j][1]
        ans = abs(a-c)+abs(b-d)
        if tmp > ans:
            res = j+1
            tmp = ans
    res_list.append(res)
for i in res_list:
    print(i)

Submission status: Accepted

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

a = [list(map(int,input().split())) for x in range(N)]
c = [list(map(int,input().split())) for x in range(M)]

min_cpoint = 0
num_stack = 100100100100100

for i in range(N):
    for j in range(M):
        if num_stack > abs(a[i][0]-c[j][0]) + abs(a[i][1]-c[j][1]):
            num_stack = abs(a[i][0]-c[j][0]) + abs(a[i][1]-c[j][1])
            min_cpoint = j+1
    print(min_cpoint)
    num_stack = 100100100100100

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
st=[]
for i in range(n):
  s_d=list(map(int,input().split()))
  st.append(s_d)
cp=[]
for i in range(m):
  c_d=list(map(int,input().split()))
  cp.append(c_d)
sc=[]
for i in range(n):
  scd=[]
  for j in range(m):
    scd_d=abs(st[i][0]-cp[j][0])+abs(st[i][1]-cp[j][1])
    scd.append(scd_d)
  sc.append(scd.index(min(scd))+1)
  
for i in range(n):
  print(sc[i])

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
listn=[]
listm=[]
ans=[]
num=0
for i in range(n):
    listn.append(input().split())
for i in range(m):
    listm.append(input().split())
for i in range(n):
    numx=int(listn[i][0])
    numy=int(listn[i][1])
    count=10**10
    for j in range(m):
        numd=abs(int(listm[j][0])-numx)+abs(int(listm[j][1])-numy)
        if count>numd:
            count=numd
            num=j+1
    ans.append(num)
for i in range(n):
    print(ans[i])

Submission status: Accepted

Solution code:
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 a, b in ab:
  n = 10 ** 9
  m = 0
  for i, (c, d) in enumerate(cd):
    x = abs(a - c) + abs(b - d)
    if x < n:
      n = x
      m = i + 1
      
  print(m)