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 = []
b = []
for _ in range(n):
    ai, bi = map(int, input().split())
    a.append(ai)
    b.append(bi)
c = []
d = []
for _ in range(m):
    ci, di = map(int, input().split())
    c.append(ci)
    d.append(di)
ans = [float('inf')] * n
cnt = [float('inf')] * n

for i in range(n):
    for j in range(m):
        now = abs(a[i] - c[j]) + abs(b[i] - d[j])
        if cnt[i] > now:
            cnt[i] = now
            ans[i] = j + 1
print(*ans, sep='\n')

Submission status: Accepted

Solution code:
def main():
    N, M = (int(i) for i in input().split())
    AB = [[int(i) for i in input().split()] for j in range(N)]
    CD = [[int(i) for i in input().split()] for j in range(M)]

    for a, b in AB:
        cur = 10**12
        cur_ans = -1
        for i, cd in enumerate(CD):
            if cur > abs(a-cd[0])+abs(b-cd[1]):
                cur = abs(a-cd[0])+abs(b-cd[1])
                cur_ans = i
        print(cur_ans+1)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
st = []
res = [0] * N
for _ in range(N):
  a, b = map(int, input().split())
  st.append((a, b))
cp = []
for _ in range(M):
  a, b = map(int, input().split())
  cp.append((a, b))
for i in range(N):
  a, b = st[i]
  for j in range(M):
    c, d = cp[j]
    x, y = cp[res[i]]
    if abs(c - a) + abs(d - b) < abs(x - a) + abs(y - b):
      res[i] = j
  res[i] += 1
for r in res: print(r)

Submission status: Accepted

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

for a,b in AB:
    ans = -1
    mind = float('inf')
    for i,(c,d) in enumerate(CD):
        dist = abs(a-c) + abs(b-d)
        if dist < mind:
            mind = dist
            ans = i+1
    print(ans)

Submission status: Accepted

Solution code:
N,M = map(int, input().split())
a,b = [0]*N,[0]*N
c,d = [0]*M,[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):
    index = float('inf')
    mini = float('inf')
    for j in range(M):
        if mini > abs(a[i]-c[j])+abs(b[i]-d[j]):
            index = j
            mini = min(mini, abs(a[i]-c[j])+abs(b[i]-d[j]))
    print(index+1)

Submission status: Accepted

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

abl = []
for _ in range(n):
    ab = list(map(int, input().split()))
    abl.append(ab)

cdl = []
for _ in range(m):
    cd = list(map(int, input().split()))
    cdl.append(cd)

ansl = [0 for _ in range(n)]
for i, ab in enumerate(abl):
    ans = 10**10
    for j, cd in enumerate(cdl):
        if abs(ab[0]-cd[0]) + abs(ab[1]-cd[1]) < ans:
            ansl[i] = j
            ans = abs(ab[0]-cd[0]) + abs(ab[1]-cd[1])

for ans in ansl:
    print(ans+1)

Submission status: Accepted

Solution code:
import math

N,M=map(int,input().split())
student=[list(map(int,input().split())) for _ in range(N)]
check=[list(map(int,input().split())) for _ in range(M)]
#print(student,check)
#print("\n")
for i in range(N):
    dist = float("inf")
    point = 0
    for j in range(M):
        if abs(student[i][0]-check[j][0])+abs(student[i][1]-check[j][1])<dist:
            dist=abs(student[i][0]-check[j][0])+abs(student[i][1]-check[j][1])
            point=j+1
        #print(point,dist)
    print(point)

Submission status: Accepted

Solution code:
def solve(n, m, AB, CD):
    ret = []
    for a, b in AB:
        minval = 10 ** 10
        minidx = -1
        for j, (c, d) in enumerate(CD):
            if abs(a - c) + abs(b - d) < minval:
                minval = abs(a - c) + abs(b - d)
                minidx = j
        ret.append(minidx + 1)
    return ret

_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)]
print(*solve(_n, _m, _AB, _CD), sep='\n')

Submission status: Accepted

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

min = 10**9

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

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

for i in range(n):
    for j in range(m):
        dis= abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
        if dis < min:
            min = dis
            buf = j+1
        elif dis == min:
            continue
    print(buf)
    min=10**9

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

man = lambda x,y:abs(x[0] - y[0]) + abs(x[1] - y[1])

for i in range(n):
    a,b = ab[i]
    cost = float('INF')
    pos = 0
    for j in range(m):
        c,d = cd[j]
        c = man(ab[i], cd[j])
        if c < cost:
            cost = c
            pos = j+1
    print(pos)

Submission status: Accepted

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

Submission status: Accepted

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


def main():
    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):
        for j in range(M):
            if j == 0:
                result = abs(AB[i][0] - CD[j][0]) + abs(AB[i][1] - CD[j][1])
                count = j + 1
            elif result > abs(AB[i][0] - CD[j][0]) + abs(AB[i][1] - CD[j][1]):
                result = abs(AB[i][0] - CD[j][0]) + abs(AB[i][1] - CD[j][1])
                count = j + 1
        print(count)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
list_student = []
list_ckeckpoint = []
for x in range(n):
    a, b = map(int, input().split())
    list_student.append([a, b])
for y in range(m):
    c, d = map(int, input().split())
    list_ckeckpoint.append([c, d])
    
def distance(lista, listb):
    return abs(lista[0] - listb[0]) + abs(lista[1] - listb[1])

for no in range(n):
    minValue = 2 * 10**8
    minid = 1
    for id in range(m):
        dis = distance(list_student[no], list_ckeckpoint[id])
        if minValue > dis: minid = id + 1
        minValue = min([minValue, dis])
    print(minid)

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()
A = [LIST() for i in range(N)]
C = [LIST() for i in range(M)]
L = []
for i in range(N):
    index = 0
    mi = INF
    for j in range(M):
        a, b = A[i][0], A[i][1]
        c, d = C[j][0], C[j][1]
        m = abs(a - c) + abs(b - d)
        if mi > min(mi, m):
            mi = min(mi, m)
            index = j
    L.append(index)
for l in L:
    print(l+1)

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
st = []
cp = []
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())
    cp.append([c,d])

ans = []
for x in st:
    t = []
    for y in cp:
        t.append(abs(x[0]-y[0])+abs(x[1]-y[1]))
    ans.append(t.index(min(t))+1)

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

Submission status: Accepted

Solution code:
def ac(n,m,a,c):
    ans = []
    for i in range(n):
        min = 10000000000000
        bang = 0
        for w in range(m):
            if abs(a[i][0] - c[w][0]) + abs(a[i][1] - c[w][1]) < min:
                min = abs(a[i][0] - c[w][0]) + abs(a[i][1] - c[w][1])
                bang = w + 1
        ans.append(bang)
    return ans

def main():
    n , m = map(int, input().split())
    a = [list(map(int , input().split())) for i in range(n)]
    c = [list(map(int , input().split())) for i in range(m)]
    ans = ac(n , m , a , c)
    for i in range(len(ans)):
        print(ans[i])

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()
ab = [LIST() for _ in range(N)]
cd = [LIST() for _ in range(M)]

def dist(p1, p2):
	return abs(p1[0]-p2[0]) + abs(p1[1]-p2[1])

for p1 in ab:
	tmp_dist = INF
	tmp_idx = None
	for i, p2 in enumerate(cd):
		d = dist(p1, p2)
		if d < tmp_dist:
			tmp_dist = d
			tmp_idx = i+1
	print(tmp_idx)

Submission status: Accepted

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


class StudentCoord:

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

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

    def nearest_checkpoint_idx(self, checkpoints):
        min_idx = -1
        min_distance = float('inf')
        for idx, checkpoint in enumerate(checkpoints):
            d = self.distance(checkpoint[0], checkpoint[1])
            if d < min_distance:
                min_idx = idx
                min_distance = d
        return min_idx+1


students = []
for _ in range(N):
    x, y = tuple(map(int, input().split()))
    student = StudentCoord(x, y)
    students.append(student)

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

for student in students:
    idx = student.nearest_checkpoint_idx(checkpoints)
    print(idx)

Submission status: Accepted

Solution code:
n, m = map(int,input().split())
students = [None]*n
points = [None]*m
for i in range(n):
  students[i] = tuple(map(int,input().split()))
for i in range(m):
  points[i] = tuple(map(int,input().split()))

ans = []
for s in students:
  tmp = []
  for p in points:
    tmp.append(abs(s[0] - p[0]) + abs(s[1] - p[1]))
  ans.append(tmp.index(min(tmp)) + 1)
for i in range(n):
  print(ans[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)]
def dist(list1,list2):
  return abs(list1[0]-list2[0])+abs(list1[1]-list2[1])
for human in ab:
  for i in range(m):
    if i==0:
      d=dist(human,cd[0])
      index=1
    else:
      d_new=dist(human,cd[i])
      if d>d_new:
        d=d_new
        index=i+1
  print(index)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n,m = map(int,input().split())
a = [0]*n
b = [0]*n
x = [0]*m
y = [0]*m
for i in range(n):
    s,t = map(int,input().split())
    a[i],b[i] = s,t
for i in range(m):
    s,t = map(int,input().split())
    x[i],y[i] = s,t

for i in range(n):
    min_idx = 1 #これに足すと添字があう
    min_dist = 10**9
    for j in range(m):
        if abs(x[j]-a[i])+abs(y[j]-b[i]) < min_dist:
            min_dist = abs(x[j]-a[i])+abs(y[j]-b[i])
            min_idx = 1 + j
            #print(x[j],a[i],y[j],b[i])
            #print(min_dist)

    print(min_idx)

Submission status: Accepted

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

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

for s in students:
    dis = [abs(s[0] - c[0]) + abs(s[1] - c[1]) for c in checks]
    print(dis.index(min(dis))+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)]
f = lambda ab: min((abs(ab[0]-CD[i][0])+abs(ab[1]-CD[i][1]),i+1) for i in range(M))[1]
print(*[f(ab) for ab in AB], sep="\n")

Submission status: Accepted

Solution code:
arr = input().split()
n = int(arr[0])
m = int(arr[1])
a = [0] * n
b = [0] * n
for i in range(n):
    tmp = input().split()
    tmp = list(map(int,tmp))
    a[i] = tmp[0]
    b[i] = tmp[1]

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

def calc_dist(a,b,c,d):
    return abs(a-c) + abs(b-d)
    
for i in range(n):

    line = 10000000000
    index = 0
    for k in range(m):
        now = calc_dist(a[i],b[i],c[k],d[k])
        if line > now:
            line = now
            index = k
    print(index+1)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    inf=10**9
    n,m=MI()
    s=[LI() for _ in range(n)]
    c=[LI() for _ in range(m)]
    ans=[0]*n
    for si,(sx,sy) in enumerate(s):
        mn=inf
        mi=0
        for ci,(cx,cy) in enumerate(c):
            d=abs(cx-sx)+abs(cy-sy)
            if d<mn:
                mn=d
                mi=ci
        ans[si]=mi
    for a in ans:
        print(a+1)

main()

Submission status: Accepted

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

for a, b in students:
    min_dist = 10 ** 9
    ans = -1
    for i in range(M):
        c, d = checkpoints[i]
        distance = abs(a - c) + abs(b - d)
        if distance < min_dist:
            min_dist = distance
            ans = i + 1
    print(ans)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
gakusei = []
for i in range(N):
    a,b = map(int,input().split())
    gakusei.append((a,b))
check = []
for i in range(1,M+1):
    c,d = map(int,input().split())
    check.append((c,d))
for i in range(N):
    a,b = gakusei[i]
    z = 10**9
    m = 0
    for j in range(1,M+1):
        c,d = check[j-1]
        x = max(a-c,c-a) + max(b-d,d-b)
        if x < z:
            m = j
            z = x
    print(m)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N, M = map(int, input().split())
ab = []
cd = []
for i in range(N):
    H = list(map(int, input().split()))
    ab.append(H)

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

for i in range(N):
    s = abs(ab[i][0] - cd[0][0])+abs(ab[i][1] - cd[0][1])
    ans = 1
    for j in range(M):
        if s > abs(ab[i][0] - cd[j][0])+abs(ab[i][1] - cd[j][1]):
            ans = j+1
            s = abs(ab[i][0] - cd[j][0])+abs(ab[i][1] - cd[j][1])
    print(ans)

Submission status: Accepted

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

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

ans = []
for x,y in lst1:
    res = 10**9
    for i,seq in enumerate(lst2):
        a = seq[0]
        b = seq[1]
        if res > abs(a-x)+abs(b-y):
            ct = i
            res = abs(a-x)+abs(b-y)
    ans.append(ct)

for i in ans:
    print(i+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):
    dist = abs(a[i][0]-c[0][0])+abs(a[i][1]-c[0][1])
    ans = 1
    for j in range(m):
        if(dist > (abs(a[i][0]-c[j][0])+abs(a[i][1]-c[j][1]))):
            dist = abs(a[i][0]-c[j][0])+abs(a[i][1]-c[j][1])
            ans = j+1
        if(j == m-1):
            print(ans)

Submission status: Accepted

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

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)]
ans=[[] for _ in range(n)]
for i in range(n):
  p,q=a[i]
  for j in range(m):
    r,s=c[j]
    d=abs(p-r)+abs(q-s)
    ans[i].append((d,j+1))
  ans[i]=sorted(ans[i])
for i in ans:
  print(i[0][1])

Submission status: Accepted

Solution code:
def main():
    n, m = map(int, input().split())
    Students = [list(map(int,input().split())) for _ in range(n)]
    Check = [list(map(int,input().split())) for _ in range(m)]
    for s in Students:
        ans = 1
        for i, c in enumerate(Check, 1):
            dist = abs(c[0]-s[0]) + abs(c[1]-s[1])
            if i<2:
                min_dist = dist
            elif dist < min_dist:
                min_dist = dist
                ans = i
        print(ans)
main()

Submission status: Accepted

Solution code:
def man(q,r,s,t):
    #print(q,r,s,t,(abs(q-s)) + (abs(r-t)))
    return (abs(q-s)) + (abs(r-t))

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

a=[]
b=[]

for _ in range(n):
    aa,bb = map(int,input().split())
    a.append(aa)
    b.append(bb)

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

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

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
students = [list(map(int, input().split())) for _ in range(n)]
chkpoints = [list(map(int, input().split())) for _ in range(m)]
dist = 0
ans = 0
for student in students:
  min_dist = 1000000000
  for i in range(m):
    dist = abs(student[0]-chkpoints[i][0])+abs(student[1]-chkpoints[i][1])
    if dist < min_dist:
      min_dist = dist
      ans = i+1
  print(ans)

Submission status: Accepted

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

for nll in nl:
  c=0
  ii=1
  for i,mll in enumerate(ml):
    cc = abs(nll[0]-mll[0])+abs(nll[1]-mll[1])
    if i == 0:
      c = cc
      continue
    
    if c > cc:
      ii = i+1
      c = cc
    
  ans.append(ii)
  
[print(x) for x in ans]

Submission status: Accepted

Solution code:
N,M = [int(i) for i in input().split()]
ab = [0] * N
cd = [0] * M
index = [-1] * N
for i in range(N) :
    ab[i] = [int(j) for j in input().split()]
for i in range(M) :
    cd[i] = [int(j) for j in input().split()]
for i in range(N) :
    indexa = []
    min = 10000000000
    for j in range(M) :
        l = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
        if l < min :
            indexa.clear()
            indexa.append(j+1)
            min = l
        elif l == min :
            indexa.append(j+1)
    if len(indexa) == 1 :
        index[i] = indexa[0]
    else :
        indexa.sort()
        index[i] = indexa[0]
for i in range(N) :
    print(index[i])

Submission status: Accepted

Solution code:
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    n,m=INTM()
    A=[]
    C=[]
    for i in range(n):
        A.append(LIST())
    for i in range(m):
        C.append(LIST())
    for i in range(n):
        temp=10**9
        a,b=A[i][0],A[i][1]
        for j in range(m):
            c,d=C[(m-1)-j][0],C[(m-1)-j][1]
            #print(a,b,c,d)
            man=abs(a-c)+abs(b-d)
            #print(float(a-c),float(b-d))
            if man<=temp:
                #print(man,temp)
                ans=m-j
                temp=man
        print(ans)
            
    
if __name__ == '__main__':
    do()

Submission status: Accepted

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

for i in g:
    tmp=10**9
    
    for j in range(m):
        t2=abs(i[0]-c[j][0]) + abs(i[1]-c[j][1])
        if t2 <tmp:
            no=j+1
            tmp=t2
            
    print(no)

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):
  d = []
  for j in range(M):
    d.append(abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1]))
  print(d.index(min(d)) + 1)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
student_positions = [input().split() for _ in range(N)]
student_positions = [[int(a[0]), int(a[1])] for a in student_positions]
check_points = [input().split() for _ in range(M)]
check_points = [[int(a[0]), int(a[1])] for a in check_points]


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


def get_nearest_point(x, candidates):
    min_distance = 10 ** 10
    for idx, candidate in enumerate(candidates):
        distance = calc_manhattan_distance(x, candidate)
        if distance < min_distance:
            min_distance = distance
            nearest_point = idx
    return nearest_point


for p in student_positions:
    print(get_nearest_point(p, check_points)+1)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
student_positions = [input().split() for _ in range(N)]
student_positions = [[int(a[0]), int(a[1])] for a in student_positions]
check_points = [input().split() for _ in range(M)]
check_points = [[int(a[0]), int(a[1])] for a in check_points]


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


def get_closest_point(x, candidates):
    prev_distance = 10 ** 10
    for idx, candidate in enumerate(candidates):
        distance = calc_manhattan_distance(x, candidate)
        if distance < prev_distance:
            prev_distance = distance
            target_idx = idx
    return target_idx


for p in student_positions:
    print(get_closest_point(p, check_points)+1)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
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):
    le=float("inf")
    a,b=ab[i][0],ab[i][1]
    for j in range(m):
        c,d=cd[j][0],cd[j][1]
        if le>abs(a-c)+abs(b-d):
            ans=j+1
            le=abs(a-c)+abs(b-d)
    print(ans)

Submission status: Accepted

Solution code:
# N人
# M個のチェックポイント
N, M = map(int, input().split())

# 学生の初期値
student = []
for _ in range(N):
    student.append(list(map(int, input().split())))
    
# チェックポイントの座標
cp = []
for _ in range(M):
    cp.append(list(map(int, input().split())))
    
# ゴールまでの距離を格納する配列
goal = [10**9 for _ in range(N)]
# 学生が進むチェックポイント
ans = [0 for _ in range(N)]


for n in range(N):
    for m in range(M):
        # マンハッタン距離を測る
        x = abs(student[n][0] - cp[m][0])
        y = abs(student[n][1] - cp[m][1])
        #print(student[n], cp[m])
        #print("abs(x-y)", x, y, x+y)
        # 最短の場合は目標チェックポイントを更新
        if goal[n] > x+y:
            goal[n] = x+y
            ans[n] = m +1
            #print(goal[n], ans[n])


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

Submission status: Accepted

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

for stu in ab:
    mind = float("inf")
    for i,cp in enumerate(cd,1):
        d = sum(map(abs,(stu[0]-cp[0],stu[1]-cp[1])))
        if mind > d:
            ans = i
            mind = d
    else:
        print(ans)

Submission status: Accepted

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

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

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

for s in students:
    distants = [abs(s[0]-p[0]) + abs(s[1]-p[1]) for p in points]
    print(distants.index(min(distants)) + 1)

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):
    dim, num = 10**9,-1
    for j in range(m):
        if abs(ab[i][0]-cd[j][0]) + abs(ab[i][1]-cd[j][1]) < dim:
            dim = abs(ab[i][0]-cd[j][0]) + abs(ab[i][1]-cd[j][1])
            num = j
    print(num +1)

Submission status: Accepted

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

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

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

for i in range(n):
  for j in range(m):
      if j == 0 :
        mD = abs(sList[i][0]-pList[0][0])+abs(sList[i][1]-pList[0][1])
        minDIndex = 0
      else:
        mDT = abs(sList[i][0]-pList[j][0])+abs(sList[i][1]-pList[j][1])
        if mD > mDT:
          mD = mDT
          minDIndex = j 
  #list index と checkpoint numberの違いのため＋1
  print(minDIndex+1)

Submission status: Accepted

Solution code:
INF = 10**10
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())))         

for abi in ab:
  dist = INF
  nearest = -1
  for i,cdi in enumerate(cd):
    tmp = abs(abi[0]-cdi[0]) + abs(abi[1]-cdi[1])
    if tmp<dist:
      dist = tmp
      nearest = i+1
    dist = min(tmp,dist)
    
  print(nearest)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N, M = [int(x) for x in input().split()]
ab = []
for _ in range(N):
    ab.append([int(x) for x in input().split()])
cd = []
for _ in range(M):
    cd.append([int(x) for x in input().split()])
for i in ab:
    a, b = i
    ans = [10 ** 9, 0]
    for j in range(M):
        c, d = cd[j]
        j += 1
        if abs(a - c) + abs(b - d) < ans[0]:
            ans = [abs(a - c) + abs(b - d), j]
    print(ans[1])

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)]
ans=[0]*n
for i in range(n):
    cnt=float('inf')
    dist=0
    a,b=AB[i]
    for j in range(m):
        c,d=CD[j]
        dist=abs(a-c)+abs(b-d)
        if cnt>dist:
            ans[i]=j
            cnt=dist
        else:
            continue
for i in range(n):
    print(ans[i]+1)

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

def manh(x,y):
    return abs(x[0]-y[0])+abs(x[1]-y[1])


ans=[]
for i in range(n):
    ans_sub=[0,manh(ab[i],cd[0])]
    for j in range(m):
        k=manh(ab[i],cd[j])
        if k<ans_sub[1]:
            ans_sub=[j,k]
    ans.append(ans_sub[0])
for i in range(n):
    print(ans[i]+1)

Submission status: Accepted

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

s = []
for i in range(n):
   tmp = [int(x) for x in input().split()]
   s.append(tmp)

c = []
for i in range(m):
   tmp = [int(x) for x in input().split()]
   c.append(tmp)

for i in range(n):
   d1 = []
   for j in range(m):
      d2 = abs(s[i][0] - c[j][0]) + abs(s[i][1] - c[j][1])
      d1.append(d2)

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

Submission status: Accepted

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

ab = []
for i in range(N):
    tmp = list(map(int ,input().split()))
    ab.append(tmp)
    
cd = []
for i in range(M):
    tmp = list(map(int, input().split()))
    cd.append(tmp)
    
for i in range(N):
    a, b = ab[i][0], ab[i][1]
    d = 10**12
    for j in range(M):
        tmp = abs(a - cd[j][0]) + abs(b - cd[j][1])
        if tmp < d:
            d = tmp
            ans = j+1
    print(ans)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
import numpy as np
A = np.empty((N,2), dtype=np.int)
CP = np.empty((M,2), dtype=np.int)
for _ in range(N):
  A[_][:] = list(map(int,input().split()))
for _ in range(M):
  CP[_][:] = list(map(int,input().split()))
for n in range(N):
  ans = 0
  mnda = 4*10**8
  for m in range(M):
    mnd = sum(np.abs(A[n]-CP[m]))
    if mnd < mnda:
      mnda = mnd
      ans = m+1
  print(ans)