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:
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def to_bin(x: int) -> str: return format(x, 'b') # rev => int(res, 2)
def to_oct(x: int) -> str: return format(x, 'o') # rev => int(res, 8)
def to_hex(x: int) -> str: return format(x, 'x') # rev => int(res, 16)
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i):
            is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]
## libs ##
from itertools import accumulate as acc, combinations as combi, product, combinations_with_replacement as combi_dup
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
#======================================================#

def main():
    n, m = MII()
    ab = [MII() for _ in range(n)]
    cd = [MII() for _ in range(m)]
    for a,b in ab:
        minidx = 0
        mind = 4*(10**8)
        for i,(c,d) in enumerate(cd):
            dist = abs(a-c)+abs(b-d)
            if dist < mind:
                mind = dist
                minidx = i+1
        print(minidx)


if __name__ == '__main__':
    main()

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

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
A = []
B = []
C = []
D = []
ans = []

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

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

for i in range(N):
    item = abs(A[i]-C[0])+abs(B[i]-D[0])
    index = 1
    for j in range(M):
        if item > abs(A[i]-C[j])+abs(B[i]-D[j]):
            item = abs(A[i]-C[j])+abs(B[i]-D[j])
            index = j+1
    ans.append(index)

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

Submission status: Accepted

Solution code:
from collections import defaultdict
d = defaultdict(int)
N, M = map(int, input().split())
abL = [list(map(int, input().split())) for _ in range(N)]
cdL = [list(map(int, input().split())) for _ in range(M)]

for i in range(N):
    for j in range(M):
        d[j] = abs(abL[i][0] - cdL[j][0]) + abs(abL[i][1] - cdL[j][1])

    m = min(d.values())
    for k, v in d.items():
        if (v == m):
            print(k + 1)
            break

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):
    m=0#最小の距離
    for j in range(M):
        if j==0:
            m=abs(cd[j][0]-ab[i][0])+abs(cd[j][1]-ab[i][1])
            ans=j+1
        else:
            if m>abs(cd[j][0]-ab[i][0])+abs(cd[j][1]-ab[i][1]):#最小値を更新する場合
                m=abs(cd[j][0]-ab[i][0])+abs(cd[j][1]-ab[i][1])
                ans=j+1
        #print("j=",str(j),",","m=",str(abs(cd[j][0]-ab[i][0])+abs(cd[j][1]-ab[i][1])))
    print(ans)

Submission status: Accepted

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

ablist=[]
for i in range(N):
  a,b=map(int,input().split())
  ablist.append((a,b))
  
cdlist=[]
for i in range(M):
  c,d=map(int,input().split())
  cdlist.append((c,d))
  
for i in range(N):
  a,b=ablist[i]
  min_dist_arg=-1
  min_dist=float("inf")
  for j in range(M):
    c,d=cdlist[j]
    if min_dist>abs(a-c)+abs(b-d):
      min_dist_arg=j+1
      min_dist=abs(a-c)+abs(b-d)
  print(min_dist_arg)

Submission status: Accepted

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


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 s in students:
    ans = 0
    min_distance = manhattan_distance(s, checkpoints[0])
    for i in range(1, M):
        distance = manhattan_distance(s, checkpoints[i])
        if min_distance > distance:
            min_distance = distance
            ans = i
    print(ans + 1)

Submission status: Accepted

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

for i in range(n):
    a,b = map(int,ab_input[i])
    
    tmp=float('inf')
    for j in range(m):
        c,d = map(int,cd_input[j])
        dist=abs(a-c)+abs(b-d)
        if tmp>dist:
            tmp=dist
            ans=j
    print(ans+1)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
A=[list(map(int,input().split())) for i in range(N)]
C=[list(map(int,input().split())) for i in range(M)]
for i in range(N):
    z=10**10
    ans=0
    for t in range(M):
        if (abs(A[i][0]-C[t][0])+abs(A[i][1]-C[t][1]))<z:
            z=(abs(A[i][0]-C[t][0])+abs(A[i][1]-C[t][1]))
            ans=t+1
        else:
            continue
    print(ans)

Submission status: Accepted

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

for i in range(N):
    x, y = Student[i]
    destination = 0
    distance = float('inf')
    for j in range(M):
        nx, ny = Checkpoint[j]
        dis = abs(x-nx) + abs(y-ny)
        if dis < distance:
            distance = dis
            destination = j
    print(destination+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:
    distance = float('inf')
    ans = 0
    for i in range(M):
        newDistance = abs(a - CD[i][0]) + abs(b - CD[i][1])
        if distance > newDistance:
            distance = newDistance
            ans = i+1
    print(ans)

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
i=0
while i<N:
    count=0
    j=0
    distance=abs(AB[i][0]-CD[j][0])+abs(AB[i][1]-CD[j][1])
    while j<M:
        if distance>abs(AB[i][0]-CD[j][0])+abs(AB[i][1]-CD[j][1]):
            count=j
            distance=abs(AB[i][0]-CD[j][0])+abs(AB[i][1]-CD[j][1])
        j+=1
    ans[i]=count
    i+=1

for k in ans:
    print(k+1)

Submission status: Accepted

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

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

for student in students:
  ans = (-1, float('inf'))
  for i, point in enumerate(checkpoints):
    distance = abs(student[0]-point[0]) + abs(student[1]-point[1])
    if ans[1] > distance:
      ans = (i, distance)
  print(ans[0]+1)

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 accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
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()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
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 M_dist(p1, p2):
	return abs(p1[0]-p2[0]) + abs(p1[1]-p2[1])

for i in range(N):
	dist = M_dist(ab[i], cd[0])
	ans = 1
	
	for j in range(1, M):
		if dist > M_dist(ab[i], cd[j]):
			dist = M_dist(ab[i], cd[j])
			ans = j+1
	print(ans)

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):
  ans = 10**18
  for j in range(M-1,-1,-1):
    abs_num = abs(AB[i][0]-CD[j][0])+abs(AB[i][1]-CD[j][1])
    ans = min(ans, abs_num)
    if ans == abs_num:
      count = j+1
  print(count)

Submission status: Accepted

Solution code:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
MOD = 10**9 + 7

n,m = map(int,input().split())
ab =[]
cd =[]
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):
    d = 1000000000
    check = 0
    for j in range(m):
        man = abs(cd[j][0] - ab[i][0]) + abs(cd[j][1] - ab[i][1])
        if man<d:
            d = man
            check = j
    print(check+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)]
basyo=0
for i in range(n):
  saisyo=10**9+1
  for j in range(m):
    if saisyo>abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1]):
      saisyo=abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
      basyo=j
  print(basyo+1)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
stu=[list(map(int,input().split()))for i in range(n)]
po=[list(map(int,input().split()))for i in range(m)]
for i in stu:
    tmp=10**12
    for j in po:
        ab=abs(i[0]-j[0])+abs(i[1]-j[1])
        if ab<tmp:
            tmp=ab
            ans=po.index(j)
    print(ans+1)

Submission status: Accepted

Solution code:
# coding: utf-8
import re
import math
from collections import defaultdict
import itertools
from copy import deepcopy
import random
from heapq import heappop,heappush
import time
import os
import queue
import sys
import datetime
from functools import lru_cache
#@lru_cache(maxsize=None)
readline=sys.stdin.readline
sys.setrecursionlimit(2000000)
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def is_power(a,b):#aはbの累乗数か
    now=b
    while now<a:
        now*=b
    if now==a:return True
    else:return False
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def get_facs(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
def get_primes(n,type="int"):
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=2):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(a,b,c):
    if a:return b
    else:return  c
def join(A,c=""):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
def factorize(n,type_="dict"):
    b = 2
    list_ = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            list_.append(b)
        b+=1
    if n > 1:list_.append(n)
    if type_=="dict":
        dic={}
        for a in list_:
            if a in dic:
                dic[a]+=1
            else:
                dic[a]=1
        return dic
    elif type_=="list":
        return list_
    else:
        return None
def floor_(n,x=1):
    return x*(n//x)
def ceil_(n,x=1):
    return x*((n+x-1)//x)
def hani(x,min_,max_):
    ret=x
    if x<min_:ret=min_
    if x>max_:ret=max_
    return ret
def seifu(x):
    return x//abs(x)
###################################################

def main():
    N,M=map(int,input().split())
    AB=[]
    CD=[]
    ABdict={}
    CDdict={}
    for a in range(N):
        AB.append(list(map(int,input().split())))
    for a in range(M):
        CD.append(list(map(int,input().split())))
    for a in range(N):
        mmin=[inf,inf]
        for b in range(M-1,-1,-1):
            d=abs(AB[a][0]-CD[b][0])+abs(AB[a][1]-CD[b][1])
            if mmin[0]>=d:
                mmin=[d,b+1]
        print(mmin[1])
main()

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
a = [0] * N
b = [0] * N
for i in range(N):
    a[i], b[i] = map(int, input().split())
c = [0] * M
d = [0] * M
for i in range(M):
    c[i], d[i] = map(int, input().split())
for i in range(N):
    mi = 1000000000
    mid = -1
    for j in range(M):
        di = abs(a[i] - c[j]) + abs(b[i] - d[j])
        if mi > di:
            mi = di
            mid = j + 1
    print(mid)

Submission status: Accepted

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

# In[18]:


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


# In[20]:


ans = []
for i in range(len(ab)):
    ans.append(1)
    dist_min = abs(cd[0][0] - ab[i][0]) + abs(cd[0][1] - ab[i][1])
    for j in range(len(cd)):
#         print(cd[j], ab[i])
        dist = abs(cd[j][0] - ab[i][0]) + abs(cd[j][1] - ab[i][1])
#         print(dist)
        if dist < dist_min:
            dist_min = dist
            ans[-1] = j+1
#     print(ans)

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


# In[ ]:

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
a, b = [], []
for _ in range(N):
    A, B = map(int, input().split())
    a.append(A)
    b.append(B)
    
c, d = [], []
for _ in range(M):
    C, D = map(int, input().split())
    c.append(C)
    d.append(D)
    
for A, B in zip(a, b):
    ans = 0
    mn = 10**9
    for i, (C, D) in enumerate(zip(c, d)):
        s = abs(A - C) + abs(B - D)
        if mn > s:
            ans = i
            mn = s
            
    print(ans+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)]

ANS = []
for a,b in AB:
  md = 10 ** 9
  nearest = -1
  for i in range(M):
    c,d = CD[i]
    d = abs(a-c) + abs(d-b)
    if d < md:
      nearest = i+1
      md = d
  ANS.append(nearest)
  
print('\n'.join(map(str,ANS)))

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
A = [0]*N
B = [0]*N
C = [0]*M
D = [0]*M
result = [0]*N
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):
	Cnt = 0
	Dist = float('inf')
	x = A[i]
	y = B[i]
	for j in range(M):
		if abs(x-C[j])+abs(y-D[j]) < Dist:
			#print(i,j,Dist)
			Dist = abs(x-C[j])+abs(y-D[j])
			Cnt = j+1
	result[i]=Cnt
 
for i in range(N):
	print(result[i])

Submission status: Accepted

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

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

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

# print(ab)
# print(cd)

for i in range(N):
    a, b = ab[i]
    tmp = float('inf')
    p = -1
    for j in range(M):
        c, d = cd[j]
        dist = abs(a-c)+abs(b-d)
        if tmp > dist:
            tmp = dist
            p = j+1
    print(p)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
ab = []
for i in range(n):
    ab.append(list(map(int, input().split())))
cd = []
for j in range(m):
    cd.append(list(map(int, input().split())))
for i in range(n):
    a, b = ab[i]
    min_d = 10**10
    for j in range(m):
        c, d = cd[j]
        if min_d > abs(a - c) + abs(b - d):
            min_d = abs(a - c) + abs(b - d)
            check = j+1
    print(check)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
A = [0]*N
B = [0]*N
C = [0]*M
D = [0]*M
result = [0]*N
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):
	Cnt = 0
	Dist = float('inf')
	x = A[i]
	y = B[i]
	for j in range(M):
		if abs(x-C[j])+abs(y-D[j]) < Dist:
			#print(i,j,Dist)
			Dist = abs(x-C[j])+abs(y-D[j])
			Cnt = j+1
	result[i]=Cnt

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

n,m=MI()
stu=[]
che=[]
for i in range(n):
    stu.append(LI())
for j in range(m):
    che.append(LI())
for i in range(n):
    mini=inf
    num=0
    for j in range(m):
        l=abs(che[j][0]-stu[i][0])+abs(che[j][1]-stu[i][1])
        #print(l,end=" ")
        if l<mini:
            mini=l
            num=j+1
    print(num)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

def main():
    n,m = map(int, input().split())
    a = [0]*n
    b = [0]*n
    c = [0]*m
    d = [0]*m
    ans = [1]*n
    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):
        temp = abs(a[i]-c[0]) + abs(b[i]-d[0])
        for j in range(1,m):
            cur = abs(a[i]-c[j]) + abs(b[i]-d[j])
            if temp > cur:
                temp = cur
                ans[i] = j+1
        print(ans[i])

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

def main():
    n,m = map(int, input().split())
    s = []
    p = []
    min = [10**12]*n
    ans = [0]*n
    for _ in range(n):
        s.append(list(map(int, input().split())))
    for _ in range(m):
        p.append(list(map(int, input().split())))
    for i in range(n):
        a, b = s[i]
        for j in range(m):
            c,d  = p[j]
            md = abs(a-c) + abs(b-d)
            if md < min[i]:
                min[i] = md
                ans[i] = j+1
    for i in ans:
        print(i)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from fractions import gcd


def read():
    N, M = map(int, input().strip().split())
    AB = list()
    for i in range(N):
        a, b = map(int, input().strip().split())
        AB.append((a, b))
    CD = list()
    for i in range(M):
        c, d = map(int, input().strip().split())
        CD.append((c, d))
    return N, M, AB, CD


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


def solve(N, M, AB, CD):
    checkpoints = list()
    for a, b in AB:
        min_checkpoint = 0
        min_d = 10**9
        for j, (c, d) in enumerate(CD):
            d = distance(a, b, c, d)
            if d < min_d:
                min_d = d
                min_checkpoint = j + 1
        checkpoints.append(min_checkpoint)
    for c in checkpoints:
        print(c)


if __name__ == '__main__':
    inputs = read()
    solve(*inputs)

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:
    dis = 4 * 10**8
    for i in range(m):
        (c, d) = cd[i]
        tmp = abs(a-c)+abs(b-d)
        if dis > tmp:
            ans = i
            dis = tmp
    print(ans+1)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
gakusei=[]
for i in range(n):
  gakusei.append(list(map(int,input().split())))
check=[]
for j in range(m):
  check.append(list(map(int,input().split())))
for k in range(0,n):
  minkyori=10**100
  keep=-1
  for l in range(0,m):
    kyori=abs(gakusei[k][0]-check[l][0])+abs(gakusei[k][1]-check[l][1])
    if kyori<minkyori:
      minkyori=kyori
      keep=l
  print(keep+1)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
ab = []
for _ in range(n):
    a, b = map(int, input().split())
    ab.append((a, b))
cd = []
for _ in range(m):
    c, d = map(int, input().split())
    cd.append((c, d))

for a, b in ab:
    mi_len = 10**9
    for ind, (c, d) in enumerate(cd):
        l = abs(a-c)+abs(b-d)
        if l<mi_len:
            mi_len = l
            mi_ind = ind+1
    print(mi_ind)

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
A,B,C,D=[],[],[],[]
for i in range(n):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)
for i in range(m):
    c,d=map(int,input().split())
    C.append(c)
    D.append(d)
for i in range(n):
    ans,x=1000000000000,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])
            x=j
    print(x+1)

Submission status: Accepted

Solution code:
def main():
    n, m = map(int, input().split())
    student = [[int(x) for x in input().split()] for _ in range(n)]
    point = [[int(x) for x in input().split()] for _ in range(m)]
    answer = [0 for _ in range(n)]
    for i, begin in enumerate(student):
        a, b = begin
        dist = float("inf")
        for j, goal in enumerate(point):
            c, d = goal
            if abs(a - c) + abs(b - d) < dist:
                dist = abs(a - c) + abs(b - d)
                answer[i] = j + 1
    print("\n".join(map(str, answer)))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

  for a in ab:
    ans = 0
    dist = 10000000000
    for i in range(m):
      tmp = abs(a[0] - cd[i][0]) + abs(a[1] - cd[i][1])
      if tmp < dist:
        ans = i+1
        dist = tmp
    print(ans)
  return

if __name__ == "__main__":
  resolve()

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.buffer.readline
    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:
        ansD = 10**9
        ans = 0
        for j, cd in enumerate(CD):
            curD = abs(a - cd[0]) + abs(b - cd[1])
            if curD < ansD:
                ansD = curD
                ans = j+1
        print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

C=[]
for i in range(M):
    c,d=map(int, input().split())
    C.append((c,d,i+1))
#print(C)
for s in S:
    a,b=s
    now=0
    dis=10**9

    for t in C:
        c,d,n=t
        D=abs(c-a)+abs(d-b)
        
        if D<dis:
            dis=D
            now=n
    print(now)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n,m=map(int, input().split())
    lp=[list(map(int, input().split())) for i in range(n)]
    lb=[list(map(int, input().split())) for i in range(m)]

    for x in range(n):
        kyorimin=4*10**8
        ans=m
        for y in range(m):
            kyori = abs(lp[x][0] - lb[y][0]) + abs(lp[x][1] - lb[y][1])
            if kyori<kyorimin:
                kyorimin=kyori
                ans=y+1
        print(ans)
resolve()

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 x, y in students:
    distance = float('inf')

    for i in range(M):
        gx, gy = checkpoints[i][0], checkpoints[i][1]
        tmp_dis = abs(x - gx) + abs(y - gy)
        if tmp_dis < distance:
            distance = tmp_dis
            ans = i + 1
    print(ans)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
a,c = [],[]
for _ in range(n):
    a.append(list(map(int,input().split())))
for _ in range(m):
    c.append(list(map(int,input().split())))
li = []
for i in range(n):
    min_distance = 1000000000000
    min_j = 0
    for j in range(m):
        if abs(a[i][0]-c[j][0]) + abs(a[i][1]-c[j][1]) < min_distance:
            min_distance = abs(a[i][0]-c[j][0]) + abs(a[i][1]-c[j][1])
            min_j = j+1
    li.append(min_j)
for i in range(n):
    print(li[i])

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
stud = [list(map(int, input().split())) for _ in range(n)]
goal = [list(map(int, input().split())) for _ in range(m)]
for x,y in stud:
    ansd = float("inf")
    for i in range(m):
        x2,y2 = goal[i][0],goal[i][1]
        d = abs(x-x2) + abs(y-y2)
        if d < ansd:
            ans = i+1
            ansd = d
    print(ans)

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

p = [float("INF")] * n
check = [""]*n
for i in range(n):
    for j in range(m):
        if abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1]) < p[i]:
            p[i] = abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
            check[i] = j+1
for s in check: print(s)

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())
A = [list(map(int,input().split())) for _ in range(N)]
B = [list(map(int,input().split())) for _ in range(M)]
for i in range(N):
    ind = 0
    dmin = 10**9
    for j in range(M-1,-1,-1):
        if dist(A[i],B[j])<=dmin:
            ind = j+1
            dmin = dist(A[i],B[j])
    print(ind)

Submission status: Accepted

Solution code:
import sys
def main():
    input = sys.stdin.readline
    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)]
    ans=[0]*N
    for i in range(N):
        a,b=S[i]
        tmp=10**10
        for j in range(M):
            c,d=C[j]
            if tmp > abs(a-c)+abs(b-d):
                tmp = abs(a-c)+abs(b-d)
                ans[i]=j+1
    for i in range(N):
        print(ans[i])

if __name__ == '__main__':
    main()