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

li = [ [int(it) for it in input().split()] for i in range(N) ]
lj = [ [int(it) for it in input().split()] for i in range(M) ]

for a,b in li:
  mi = 100000000000
  kk = -1
  k = 0
  for c,d in lj:
    if ( mi > abs(a-c)+abs(b-d) ):
      mi = abs(a-c)+abs(b-d)
      kk = k 
    k += 1
  print ( kk+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 student in ab:
    min_distance = 10**9
    min_idx = 0
    for idx in range(M)[::]:
        check = cd[idx]
        distance = abs(student[0] - check[0]) + abs(student[1] - check[1])
        if distance < min_distance:
            min_distance = distance
            min_idx = idx
    print(min_idx+1)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
stu_pos = [[i for i in map(int,input().split())] for j in range(n)]
check_pos = [[i for i in map(int,input().split())] for j in range(m)]

for i in range(n):
    count = m+1
    dis = 10**9+7
    for j in range(m):
        a  = abs(stu_pos[i][0] - check_pos[j][0]) + abs(stu_pos[i][1] - check_pos[j][1])
        if dis > a : 
            dis = a 
            count = j + 1 
    print("{}".format(count))

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):
    md = []
    for j in range(m):
        md.append(abs(a[i]-c[j])+abs(b[i]-d[j]))
    print(md.index(min(md))+1)

Submission status: Accepted

Solution code:

def manhattan(inlist1,inlist2):
	return abs(inlist1[0]-inlist2[0]) + abs(inlist1[1]-inlist2[1])

n, m = [ int(v) for v in input().split() ]


student_list = [ [ int(v) for v in input().split() ] for i in range(n) ]
point_list = [ [ int(v) for v in input().split() ] for i in range(m) ]
for i in range(n):
	ans = [10**9,0]
	for j in range(m):
		d = manhattan(student_list[i],point_list[j])
		if d < ans[0]:
			ans = [d, j+1]
	print(ans[1])

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
s=[]
c=[]
def mdistance(a,b,c,d):
  return abs(a-c)+abs(b-d)
for i in range(n):
  a=list(map(int,input().split()))
  s.append(a)
for i in range(m):
  c.append(list(map(int,input().split())))
for i in range(n):
  anspoint=0
  for j in range(m):
    if mdistance(s[i][0],s[i][1],c[j][0],c[j][1])<mdistance(s[i][0],s[i][1],c[anspoint][0],c[anspoint][1]):
      anspoint=j
  print(anspoint+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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 aa, bb in zip(a, b):
    l = 2 * 10 ** 8
    num = 1
    for i, (cc, dd) in enumerate(zip(c, d)):
        dis = abs(aa - cc) + abs(bb - dd)
        if dis < l:
            l = dis
            num = i + 1
    print(num)

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

for i in range(n):
    minNum = float('inf')
    ans = 0
    for j in range(m):
        if abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1]) < minNum:
            minNum = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
            ans = j + 1
    print(ans)

Submission status: Accepted

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

for i in range(n):
  min_c = 0
  min_d = float('inf')
  for j in range(m):
    d = abs(s[i][0]-c[j][0]) + abs(s[i][1]-c[j][1])
    if d < min_d:
      min_c = j+1
      min_d = d
  print(min_c)

Submission status: Accepted

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

def solve():
    N, M = list(map(int, input().split()))
    start = []
    for i in range(N):
        a, b = list(map(int, input().split()))
        start.append((a, b))
    
    checkpoints = []
    for i in range(M):
        c, d = list(map(int, input().split()))
        checkpoints.append((c, d))
    
    # 1 <= N,M <= 50 なので、全探索しても高々 N*M = 2500

    for i in range(N):
        min_d = float("inf")
        for j in range(M):
            d = abs(start[i][0]-checkpoints[j][0]) + abs(start[i][1]-checkpoints[j][1])
            if d < min_d:
                min_d = d
                ans = j + 1
        print(ans)


if __name__ == "__main__":
    solve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
ab = [list(map(int,input().split())) for x in [0]*n]
cd = [list(map(int,input().split())) for x in [0]*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:
n, m = map(int, input().split())

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

for a, b in students:
    min_distance = float("inf")
    min_checkpoint = 0
    for i, cd in enumerate(checkpoints):
        c, d = cd
        if abs(c - a) + abs(d - b) < min_distance:
            min_checkpoint = i + 1
            min_distance = abs(c - a) + abs(d - b)
    print(min_checkpoint)

Submission status: Accepted

Solution code:
n, m = list(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 val in ab:
  tmp = []
  for point in cd:
    tmp.append(abs(val[0]-point[0])+abs(val[1]-point[1]))
  print(tmp.index(min(tmp))+1)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
student = []
Coodinate = []
for i in range(n):
    student.append(list(map(int,input().split())))
for j in range(m):
    Coodinate.append(list(map(int,input().split())))
ans = []
#print(student)
#print(Coodinate)
for k in student:
    manhattan = 100000000000
    number = 0
    for u in range(m):
        manhattann = abs(k[0]-Coodinate[u][0])+abs(k[1]-Coodinate[u][1])
        if manhattann < manhattan:
            manhattan = manhattann
            number = u+1
    ans.append(number)
for y in ans:
    print(y)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
students = [[int(i) for i in input().split()]+[j] for j in range(N)]
checkP = [[int(i) for i in input().split()]+[j] for j in range(M)]
ans = [0]*N
Inf = 10**9
dif = [Inf]*N


for a,b,c in students:
    for i,j,k in checkP:
        if abs(a-i)+abs(b-j) < dif[c]:
            dif[c] = abs(a-i) + abs(b-j)
            ans[c] = k+1

for i in ans:
    print(i)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
s,c,d = [],[],[0 for i in range(M)]
for i in range(N):
    s += [[int(x) for x in input().split()]]
for i in range(M):
    c += [[int(x) for x in input().split()]]

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])
    print(d.index(min(d))+1)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
li = []
cp = []
ans = 4*10**8
anscp = 0
for i in range(n):
    a, b = map(int, input().split())
    li.append((a, b))
for j in range(m):
    c, d = map(int, input().split())
    cp.append((c, d))
for k in range(n):
    for l in range(m):
        num = abs(li[k][0]-cp[l][0]) + abs(li[k][1]-cp[l][1])
        if num < ans:
            ans = num
            anscp = l+1
    print(anscp)
    ans = 4*10**8

Submission status: Accepted

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

for i in range(N):
    student_x = student[i][0]
    student_y = student[i][1]
    distance = []
    for j in range(M):
        point_x = point[j][0]
        point_y = point[j][1]
        distance.append(abs(student_x - point_x) + abs(student_y - point_y))
    distance_min = min(distance)
    n = 0
    while True:
        if distance_min == distance[n]:
            print(n+1)
            break
        else:
            n += 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 ab:
  x1, y1 = i[0], i[1]
  ans = 0
  MIN = 10 ** 9 + 7
  for key,j in enumerate(cd): 
    x2, y2 = j[0], j[1]
    manhattan = abs(x2-x1) + abs(y2-y1)
    if MIN > manhattan:
      ans = key + 1
      MIN = manhattan
  print(ans)

Submission status: Accepted

Solution code:
def dist(w, x, y, z):
    return abs(w-y)+abs(x-z)

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):
    tmp = 10**9
    a, b = s[i][0], s[i][1]
    for j in range(m):
        c, d = p[j][0], p[j][1]
        if dist(a, b, c, d) < tmp:
            ans = j+1
            tmp = dist(a, b, c, d)
    print(ans)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
ss = [tuple(map(int, input().split())) for _ in range(n)]
ps = [tuple(map(int, input().split())) for _ in range(m)]


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


for s in ss:
    mini = 0
    mind = d(s, ps[0])
    for i in range(1, len(ps)):
        p = ps[i]
        if d(s, p) < mind:
            mini = i
            mind = d(s, p)

    print(mini + 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 = []
for man in ab:
    min_dis = float("inf")
    place = 0
    for i in range(m):
        cp = cd[i]
        dis = abs(cp[0] -man[0]) + abs(cp[1] -man[1])

        if dis < min_dis:
            min_dis = dis
            place = i + 1

    ans += [place]

for i in ans:
    print(i)

Submission status: Accepted

Solution code:
import itertools
N,M = list(map(int,input().split(" ")))
humans = []
points = []

for _ in range(N):
    humans.append(list(map(int,input().split(" "))))
for _ in range(M):
    points.append(list(map(int, input().split(" "))))
for human in humans:
    mindis = 10e10
    minind = -1
    a = human[0]
    b = human[1]
    for ind,point in enumerate(points):
        c = point[0]
        d = point[1]
        dist = abs(a-c) + abs(d-b)
        if mindis > dist:
            minind = ind + 1
            mindis = dist
    print(minind)

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)]
INF = 1000000000

for a, b in AB:
    min_dist = INF
    min_cp = -1
    for cp in range(1, M+1):
        dist = abs(a-CD[cp-1][0]) + abs(b-CD[cp-1][1])
        if dist < min_dist:
            min_dist = dist
            min_cp = cp
    print(min_cp)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
a=[]
b=[]
c=[]
d=[]
for i in range(n):
    a1,b1=map(int,input().split())
    a.append(a1)
    b.append(b1)
for i in range(m):
    c1,d1=map(int,input().split())
    c.append(c1)
    d.append(d1)
for i in range(n):
    min_len = 1000000000
    cnt = None
    for j in range(m):
        len = abs(c[j]-a[i])+abs(d[j]-b[i])
        if len < min_len:
            min_len=len
            cnt = j+1
    print(cnt)

Submission status: Accepted

Solution code:
def md(a, b):
    return abs(a[0] - b[0]) + abs(a[1] - b[1])


N, M = map(int, input().split())
P = [tuple(map(int, input().split())) for _ in range(N)]
C = [tuple(map(int, input().split())) for _ in range(M)]
ANS = []

for p in P:
    min_c = None
    min_d = float('inf')
    for c in C:
        d = md(p, c)
        if d < min_d:
            min_c = c
            min_d = d
    ANS.append(min_c)

print(*[C.index(c) + 1 for c in ANS], sep='\n')

Submission status: Accepted

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math

mod = 10**9+7

N,M = map(int,input().split())
start = [0 for i in range(N)]
for i in range(N):
    start[i] = [int(i) for i in input().split()]

goal = [[] for i in range(M)]
for i in range(M):
    goal[i] = [int(i) for i in input().split()]

# print(start,goal)
ans = [0 for i in range(N)]
for i in range(N):
    tmp = mod
    for j in range(M):
        if tmp > abs(start[i][0]-goal[j][0])+abs(start[i][1]-goal[j][1]):
            ans[i] = j+1
            tmp = abs(start[i][0]-goal[j][0])+abs(start[i][1]-goal[j][1])
for i in range(N):
    print(ans[i])

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a,b=[],[]
for i in range(n):a.append(list(map(int,input().split())))
for i in range(m):b.append(list(map(int,input().split())))
for i in range(n):
    x,y=a[i][0],a[i][1]
    c,ans=0,float("inf")
    for j in range(m):
        d=abs(b[j][0]-x)+abs(b[j][1]-y)
        if d<ans:c,ans=j+1,d
    print(c)

Submission status: Accepted

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

for k in range(n):
    tmp=[]
    for j in range(m):
        tmp.append(abs(a[k][0]-c[j][0])+abs(a[k][1]-c[j][1]))
    print(tmp.index(min(tmp))+1)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
a, b = [], []
for i in range(N):
    _a, _b = map(int, input().split())
    a.append(_a)
    b.append(_b)
c, d = [], []
for j in range(M):
    _c, _d = map(int, input().split())
    c.append(_c)
    d.append(_d)

for i in range(N):
    ans = 10 ** 9
    for j in range(M):
        tmp = abs(a[i]-c[j]) + abs(b[i]-d[j])
        if tmp < ans:
            ans = tmp
            jj = j
    print(jj + 1)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
stu = []
che = []
for i in range(N):
  stu.append(list(map(int, input().split())))
for i in range(M):
  che.append(list(map(int, input().split())))
  
for i in stu:
  x, y = i[0], i[1]
  ans = 0
  tmp = 99999999999999
  for num, j in enumerate(che):
    if abs(x-j[0])+abs(y-j[1]) < tmp:
      tmp = abs(x-j[0])+abs(y-j[1])
      ans = num + 1
  print(ans)

Submission status: Accepted

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

for i in range(N):
    l=[]
    for k in range(M):
        l.append(abs(A[i][0]-C[k][0])+abs(A[i][1]-C[k][1]))
    print(l.index(min(l))+1)

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):
    dist = 10 ** 9
    for j in range(M):
        if abs(a[i] - c[j]) + abs(b[i] - d[j]) < dist:
            dist = abs(a[i] - c[j]) + abs(b[i] - d[j])
            index = j + 1
            
    print(index)

Submission status: Accepted

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

for i in range(N):
  ans = 0
  min_l = pow(10, 10)
  for j in range(M):
    l = abs(stu[i][0] - che[j][0]) + abs(stu[i][1] - che[j][1])
    if l < min_l:
      min_l = l
      ans = j+1
  print(ans)

Submission status: Accepted

Solution code:
def ipt(N=0,switch=0):
    if N == 0:
        return list(map(int,input().split()))
    else:
        if switch==0:
            return [list(map(int,input().split())) for _ in range(N)]
        else:
            return [int(input()) for _ in range(N)]

N,M=ipt()
ab=ipt(N)
cd=ipt(M)

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

for i in range(N):
    ans = ""
    ans_d = 10**9
    for j in range(M):
        m = m_dist(ab[i][0],ab[i][1],cd[j][0],cd[j][1])
        if ans_d > m:
            ans_d = m
            ans = j+1
    print(ans)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
ab = [list(map(int,input().split())) for _ in [0]*N]
cd = [list(map(int,input().split())) for _ in [0]*M]
for a,b in ab:
    i = -1
    m = 10**9
    for j,tmp in enumerate(cd,1):
        c,d = tmp
        l = abs(a-c)+abs(b-d)
        if l < m:
            m = l
            i = j
    print(i)

Submission status: Accepted

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

for k in range(n):
    s=[abs(ab[k][0]-cd[l][0])+abs(ab[k][1]-cd[l][1]) for l in range(m)]
    print(s.index(min(s))+1)

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+1]

for a,b in ab:
    m = min(cd,key=lambda x:10000*(abs(a-x[0])+abs(b-x[1]))+x[2])
    print(m[2])

Submission status: Accepted

Solution code:
n, m = [int(i) for i in input().split()]
ab = []
cd = []
for i in range(n):
  ab.append([int(j) for j in input().split()])
for i in range(m):
  cd.append([int(j) for j in input().split()])
for ni in range(n):
  d = []
  for mi in range(m):
    d.append(abs(ab[ni][0]-cd[mi][0]) + abs(ab[ni][1]-cd[mi][1]))
  print(d.index(min(d))+1)

Submission status: Accepted

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

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

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

for i in range(N):
  # 距離の最小値（1つ目のチェックポイントへの距離で初期化している）
  d=abs(l1[i][0]-l2[0][0])+abs(l1[i][1]-l2[0][1])

  # 最も近いチェックポイントの番号（1番目で初期化）
  b=1

  # 2つ目以降のチェックポイントへの距離を求める
  for j in range(1,M):
    x=abs(l1[i][0]-l2[j][0])+abs(l1[i][1]-l2[j][1])

    # 距離がより小さい場合のみ更新
    if x<d:
      d=x
      # 0-index なので調整するために +1 している
      b=j+1

  # チェックポイントの番号を出力
  print(b)

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):
    minSum = 999999999999999999
    index = 0
    for j in range(M):
        current = abs(a[i][0] - b[j][0]) + abs(a[i][1] - b[j][1])
        if minSum > current:
            minSum = current
            index = j+1
    print(index)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
l_ab=list(list(map(int,input().split())) for _ in range(n))
l_cd=list(list(map(int,input().split())) for _ in range(m))
for i in range(n):
    c=-100
    a=10**9
    for j in range(m):
        if a>(abs(l_ab[i][0]-l_cd[j][0])\
             +abs(l_ab[i][1]-l_cd[j][1])):
                a=abs(l_ab[i][0]-l_cd[j][0])\
                 +abs(l_ab[i][1]-l_cd[j][1])
                c=j+1
    print(c)

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)]
ans = [0]*n

for i in range(n):
    point = 0
    for j in range(m):
        num = abs(ab[i][0]-cd[j][0]) + abs(ab[i][1]-cd[j][1])
        if j == 0:
            prev = num
            point = j + 1
        elif prev > num:
            prev = num
            point = j + 1
    ans[i] += point

print(*ans, sep='\n')

Submission status: Accepted

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

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

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


for i in range(N):
    # 距離の最小値（1つ目のチェックポイントへの距離で初期化している）
    d=abs(l1[i][0]-l2[0][0])+abs(l1[i][1]-l2[0][1])

    # 最も近いチェックポイントの番号（1番目で初期化）
    b=1

    # 2つ目以降のチェックポイントへの距離を求める
    for j in range(1,M):
        x=abs(l1[i][0]-l2[j][0])+abs(l1[i][1]-l2[j][1])

        # 距離がより小さい場合のみ更新
        if x<d:
            d=x
            # 0-index なので調整するために +1 している
            b=j+1

    # チェックポイントの番号を出力
    print(b)

Submission status: Accepted

Solution code:
N,M = [int(x) for x in input().split()]
S = [[int(x) for x in input().split()]for _ in range(N)]
C = [[int(x) for x in input().split()]for _ in range(M)]
ans = []
for x in S:
  mindist = 10**10
  mincheck = 0
  for ind,j in enumerate(C):
    if(abs(j[0]-x[0])+abs(j[1]-x[1])<mindist):
      mindist = abs(j[0]-x[0])+abs(j[1]-x[1])
      mincheck = ind + 1
  ans.append(mincheck)
for i in ans:
  print(i)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=[[int(b) for b in input().split()] for _ in range(n)]
c=[[int(d) for d in input().split()] for _ in range(m)]
for i in range(n):
    p=a[i]
    tmp=10**10
    pos=-1
    for j in range(m):
        cp=c[j]
        dist=abs(cp[0]-p[0])+abs(cp[1]-p[1])
        if dist < tmp:
            tmp=dist
            pos=j+1
    print(pos)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
a,b=[],[]
for i in range(N):
    s,t=map(int,input().split())
    a.append(s)
    b.append(t)
c,d=[],[]
for i in range(M):
    s,t=map(int,input().split())
    c.append(s)
    d.append(t)
for i in range(N):
    x,y=a[i],b[i]
    dist = []
    for j in range(M):
        z,w=c[j],d[j]
        dist.append(abs(x-z)+abs(y-w))
    print(dist.index(min(dist))+1)

Submission status: Accepted

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

student = []

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

point = []

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

for a, b in student:
    length = 10 ** 10
    pn = 0
    for j in range(m):
        c, d = point[j]
        if abs(a-c) + abs(b-d) < length:
            length = abs(a-c) + abs(b-d)
            pn = j + 1
    print(pn)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
s = [tuple(map(int, input().split())) for _ in range(N)]
c = [tuple(map(int, input().split())) for _ in range(M)]
for i in range(N):
    mn = [abs(s[i][0]-c[j][0])+abs(s[i][1]-c[j][1]) for j in range(M)]
    print(mn.index(min(mn))+1)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
ab=[[int(i) for i in input().split()] for i in range(n)]
cd=[[int(i) for i in input().split()] for i in range(m)]
distance=[[] for i in range(n)]
for i in range(n):
    for l in range(m):
        distance[i].append(abs(ab[i][0]-cd[l][0])+abs(ab[i][1]-cd[l][1]))
for i in range(n):
    print(distance[i].index(min(distance[i]))+1)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
ab=[[int(i) for i in input().split()] for i in range(n)]
cd=[[int(i) for i in input().split()] for i in range(m)]
count=[0]*n
distance=[[] for i in range(n)]
for i in range(n):
    for l in range(m):
        distance[i].append(abs(ab[i][0]-cd[l][0])+abs(ab[i][1]-cd[l][1]))
for i in range(n):
    print(distance[i].index(min(distance[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)]
for i in ab:
	man = []
	for j in cd:
		man.append(abs(i[0]-j[0])+abs(i[1]-j[1]))
	print(man.index(min(man))+1)

Submission status: Accepted

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

for a, b in ab:
    manh = 10**9
    num = 0
    for c, d in cd:
        if abs(a - c) + abs(b - d) < manh:
            manh = abs(a - c) + abs(b - d)
            num = cd.index([c, d]) + 1
    print(num)

Submission status: Accepted

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

for s in students:
    min_d = 10 ** 10
    min_p = 100
    for i in range(M):
        d = abs(points[i][0] - s[0]) + abs(points[i][1] - s[1])
        if d < min_d:
            min_d = d
            min_p = i
    print(min_p + 1)

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:
    minC = 10**10
    idx = 0
    for i, c in enumerate(C):
        d = abs(s[0]-c[0]) + abs(s[1]-c[1])
        if d < minC:
            minC = d
            idx = i + 1
    print(idx)

Submission status: Accepted

Solution code:
# ABC057B - Checkpoints
n, m = list(map(int, input().rstrip().split()))
st = [list(map(int, input().rstrip().split())) for _ in range(n)]
ch = [list(map(int, input().rstrip().split())) for _ in range(m)]
dis_lst = []
for i in st:
    temp_lst = []
    for j in ch:
        temp_lst.append(abs(i[0] - j[0]) + abs(i[1] - j[1]))
    dis_lst.append(temp_lst.index(min(temp_lst)) + 1)

for i in dis_lst:
    print(i)

Submission status: Accepted

Solution code:



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

for i in range(n):
  ret = [0,10**11]
  for j in range(m):
    if abs(ab[i][0]-cd[j][0]) + abs(ab[i][1]-cd[j][1]) < ret[1]:
      ret = [j+1, abs(ab[i][0]-cd[j][0]) + abs(ab[i][1]-cd[j][1])]
  print(ret[0])

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
p=[list(map(int,input().split()))for _ in range(n)]
s=[list(map(int,'0'*m))for _ in range(n)]
for j in range(m):
  c,d=map(int,input().split())
  for i in range(n):
    s[i][j]=abs(p[i][0]-c)+abs(p[i][1]-d)
else:
  for i in range(n):print(1+s[i].index(min(s[i])))

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
a_list = []
b_list = []
c_list = []
d_list = []
lists = []
for i in range(N):
    a,b = map(int,input().split())
    a_list.append(a)
    b_list.append(b)
for i in range(M):
    c,d = map(int,input().split())
    c_list.append(c)
    d_list.append(d)
for i in range(N):
    min = 9999999999999999999999999
    for j in range(M):
        distance = abs(a_list[i] - c_list[j]) + abs(b_list[i] - d_list[j])
        if min > distance:
            min = distance
            ind = j
    lists.append(ind+1)
for i in range(len(lists)):
    print(lists[i])

Submission status: Accepted

Solution code:
import sys
from collections import Counter

n, m = map(int, input().split())
ab_list = [ list(map(int, input().split())) for i in range(n)]
cd_list = [ list(map(int, input().split())) for i in range(m)]
ans_list = [[None, None] for i in range(n)]

for i in range(n):
    for j in range(m):
        x_dist = abs(ab_list[i][0] - cd_list[j][0])
        y_dist = abs(ab_list[i][1] - cd_list[j][1])
        tmp = x_dist + y_dist
        if ans_list[i][0] == None or tmp < ans_list[i][1]:
            ans_list[i] = [j+1, tmp]

for i in range(n):
    print(ans_list[i][0])

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 j in range(m)]
for a,b in ab:
    abcd=[abs(a-c)+abs(b-d) for c,d in cd]
    print(abcd.index(min(abcd))+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 i in range(N):
    nearest_diatance = 4*10**8
    ans = 0
    for j in range(M):
        x = abs(ab[i][0] - cd[j][0])
        y = abs(ab[i][1] - cd[j][1])
        if x+y < nearest_diatance:
            nearest_diatance = x+y
            ans = j+1
    else:
        print(ans)

Submission status: Accepted

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

for i in range(N):
    ans = float("inf")
    ansidx = 0
    for j in range(M):
        if ans > abs(A[i] - C[j]) + abs(B[i] - D[j]):
            ans = abs(A[i] - C[j]) + abs(B[i] - D[j])
            ansidx = j + 1
    print(ansidx)