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,bisect,string,math,time,functools,random,fractions
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
rep=range
def Golf():n,*t=map(int,open(0).read().split())
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def MI():return map(int,input().split())
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def RA():return map(int,open(0).read().split())
def GI(V,E,ls=None,Directed=False,index=1):
    org_inp=[];g=[[] for i in range(V)]
    FromStdin=True if ls==None else False
    for i in range(E):
        if FromStdin:
            inp=LI()
            org_inp.append(inp)
        else:
            inp=ls[i]
        if len(inp)==2:
            a,b=inp;c=1
        else:
            a,b,c=inp
        if index==1:a-=1;b-=1
        aa=(a,c);bb=(b,c);g[a].append(bb)
        if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1):
    #h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1) # sample usage
    mp=[boundary]*(w+2);found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def accum(ls):
    rt=[0]
    for i in ls:rt+=[rt[-1]+i]
    return rt
def bit_combination(n,base=2):
    rt=[]
    for tb in range(base**n):s=[tb//(base**bt)%base for bt in range(n)];rt+=[s]
    return rt
def gcd(x,y):
    if y==0:return x
    if x%y==0:return y
    while x%y!=0:x,y=y,x%y
    return y
def YN(x):print(['NO','YES'][x])
def Yn(x):print(['No','Yes'][x])
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)

mo=10**9+7
inf=float('inf')
FourNb=[(-1,0),(1,0),(0,1),(0,-1)];EightNb=[(-1,0),(1,0),(0,1),(0,-1),(1,1),(-1,-1),(1,-1),(-1,1)];compas=dict(zip('WENS',FourNb));cursol=dict(zip('LRUD',FourNb))
l_alp=string.ascii_lowercase
#sys.setrecursionlimit(10**7)
read=sys.stdin.buffer.read
readline=sys.stdin.buffer.readline
input=lambda: sys.stdin.readline().rstrip()

class Tree:
    def __init__(self,inp_size=None,ls=None,init=True,index=1):
        self.LCA_init_stat=False
        self.ETtable=[]
        if init:
            if ls==None:
                self.stdin(inp_size,index=index)
            else:
                self.node_size=len(ls)+1
                self.edges,_=GI(self.node_size,self.node_size-1,ls,index=index)
        return
 
    def stdin(self,inp_size=None,index=1):
        if inp_size==None:
            self.node_size=int(input())
        else:
            self.node_size=inp_size
        self.edges,_=GI(self.node_size,self.node_size-1,index=index)
        return
    
    def listin(self,ls,index=0):
        self.node_size=len(ls)+1
        self.edges,_=GI(self.node_size,self.node_size-1,ls,index=index)
        return
 
    def dfs(self,x,func=lambda pr,prv,nx,dist:prv+dist,root_v=0):
        q=deque([x])
        v=[None]*self.node_size
        v[x]=root_v
        while q:
            c=q.pop()
            for nb,d in self.edges[c]:
                if v[nb]==None:
                    q.append(nb)
                    v[nb]=func(c,v[c],nb,d)
        return v
 
    def bfs(self,x,func=lambda pr,prv,nx,dist:prv+dist,root_v=0):
        q=deque([x])
        v=[None]*self.node_size
        v[x]=root_v
        while q:
            c=q.popleft()
            for nb,d in self.edges[c]:
                if v[nb]==None:
                    q.append(nb)
                    v[nb]=func(c,v[c],nb,d)
        return v
 
    def parent(self,x):
        return self.dfs(0,func=lambda pr,prv,nx,dist:pr,root_v=-1)
 
    def topological_sort(self,x):  # return topological sort of the tree
        tps=[]
        q=deque([x])
        v=[None]*self.node_size
        v[x]=0
        while q:
            c=q.popleft()
            tps.append(c)
            for nb,d in self.edges[c]:
                if v[nb]==None:
                    q.append(nb)
                    v[nb]=0
        return tps
 
    def EulerTour(self,x):
        q=deque()
        q.append(x)
        self.depth=[None]*self.node_size
        self.depth[x]=0
        self.ETtable=[]
        self.ETdepth=[]
        self.ETin=[-1]*self.node_size
        self.ETout=[-1]*self.node_size
        cnt=0
        while q:
            c=q.pop()
            if c<0:
                ce=~c
            else:
                ce=c
                for nb,d in self.edges[ce]:
                    if self.depth[nb]==None:
                        q.append(~ce)
                        q.append(nb)
                        self.depth[nb]=self.depth[ce]+1
            self.ETtable.append(ce)
            self.ETdepth.append(self.depth[ce])
            if self.ETin[ce]==-1:
                self.ETin[ce]=cnt
            else:
                self.ETout[ce]=cnt
            cnt+=1
        return
    
    def doubling_LCA(self,root,x,y):
        if self.LCA_init_stat==False:
            self.depth=[None]*self.node_size
            self.depth=self.bfs(0,func=lambda pr,prv,nxt,dist:prv+1)
            self.par=self.bfs(0,func=lambda pr,prv,nxt,dist:pr)
            self.db=[self.par]
            for i in range(self.node_size.bit_length()):
                #show(self.db)
                self.db+=[[self.db[-1][self.db[-1][i]] for i in range(self.node_size)]]
            self.LCA_init_stat=True
        dx=self.depth[x]
        dy=self.depth[y]
        if dx>dy:
            dx,dy=dy,dx
        c=self.node_size.bit_length()
        while c>0:
            if dx+c<=dy:
                x=self.db[c][x]
                dx+=1<<c
            c>>=1
        
        if x==y:
            return x
        
        c=self.node_size.bit_length()
        while c>0:
            if self.db[c][x]!=self.db[c][y]:
                x=self.db[c][x]
                y=self.db[c][y]
            c>>=1
        
        return self.par[x]
        
    def LCA_init(self,root):
        self.EulerTour(root)
        self.st=SparseTable(self.ETdepth,init_func=min,init_idl=inf)
        #self.st=SegTree(self.node_size*2-1,self.ETdepth,function=min,ide=inf)
        self.LCA_init_stat=True
        return
    
    def LCA(self,root,x,y):
        if self.LCA_init_stat==False:
            self.LCA_init(root)
        xin,xout=self.ETin[x],self.ETout[x]
        yin,yout=self.ETin[y],self.ETout[y]
        a=min(xin,yin)
        b=max(xout,yout,xin,yin)
        id_of_min_dep_in_et=self.st.query_id(a,b+1)
        return self.ETtable[id_of_min_dep_in_et]
 
    def __str__(self):
        return  str(self.edges)
 
    def show(self):
        if all([all([d==1 for nd,d in e]) for e in self.edges]):
            print( [[nd for nd,d in e] for e in self.edges] )
        else:
            print(self)
 
    def dfs2(self,x,func=lambda pr,prv,nx,dist:prv+dist,root_v=0):
        q=deque([x])
        v=[None]*self.node_size
        v[x]=root_v
        dfs_tr=[x]
        while q:
            c=q.pop()
            for nb,d in self.edges[c]:
                if v[nb]==None:
                    q.append(nb)
                    v[nb]=func(c,v[c],nb,d)
                    dfs_tr+=nb,
        return v,dfs_tr

class SparseTable: # O(N log N) for init, O(1) for query(l,r)
    def __init__(self,ls,init_func=min,init_idl=float('inf')):
        self.func=init_func
        self.idl=init_idl
        self.size=len(ls)
        self.N0=self.size.bit_length()
        self.table=[ls[:]]
        self.index=[list(range(self.size))]
        self.lg=[0]*(self.size+1)
        
        for i in range(2,self.size+1):
            self.lg[i]=self.lg[i>>1]+1
 
        for i in range(self.N0):
            tmp=[self.func(self.table[i][j],self.table[i][min(j+(1<<i),self.size-1)]) for j in range(self.size)]
            tmp_id=[self.index[i][j] if self.table[i][j]==self.func(self.table[i][j],self.table[i][min(j+(1<<i),self.size-1)]) else self.index[i][min(j+(1<<i),self.size-1)] for j in range(self.size)]
            self.table+=[tmp]
            self.index+=[tmp_id]
    
    # return func of [l,r)
    def query(self,l,r):
        if r>self.size:r=self.size
        #N=(r-l).bit_length()-1
        N=self.lg[r-l]
        return self.func(self.table[N][l],self.table[N][max(0,r-(1<<N))])
    
    # return index of which val[i] = func of v among [l,r)
    def query_id(self,l,r):
        if r>self.size:r=self.size
        #N=(r-l).bit_length()-1
        N=self.lg[r-l]
        a,b=self.index[N][l],self.index[N][max(0,r-(1<<N))]
        if self.table[0][a]==self.func(self.table[N][l],self.table[N][max(0,r-(1<<N))]):
            b=a
        return b
    
    # return boundary index of r such that func({table[i]} =< x , i in [pos,r]
    def right_bound(self,pos,x):
        k=(self.size-pos).bit_length()
        for j in range(k)[::-1]:
            nx=pos+(1<<j)
            if nx<n and self.query(pos,nx+1)<=x:
                pos+=(1<<j)
        return pos
    
    # return boundary index of l such that func({table[i]} =< x , i in [l,pos]
    def left_bound(self,pos,x):
        k=pos.bit_length()
        for j in range(k)[::-1]:
            nx=pos-(1<<j)
            if 0<=nx and self.query(nx,pos+1)<=x:
                pos-=(1<<j)
        return pos

    def __str__(self):
        return str(self.table[0])
 
    def print(self):
        for i in self.table:
            print(*i)

show_flg=False
show_flg=True

ans=0

#s=list(open(0))

n,m=LI()
s=[LI()for i in rep(n)]
p=[LI()for i in rep(m)]

for a,b in s:
    z=inf
    w=m
    for i in rep(m)[::-1]:
        c,d=p[i]
        t=abs(a-c)+abs(b-d)
        if t<=z:
            z=t
            w=i+1
    print(w)

Submission status: Accepted

Solution code:
# scipyなし
n, m = map(int, input().split())

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

for s in st:
    mandist = float('inf')
    for i, c in enumerate(cp):
        d = abs(s[0] - c[0]) + abs(s[1] - c[1])
        if d < mandist:
            ans_check = i + 1
            mandist = d
    print(ans_check)

Submission status: Accepted

Solution code:
from scipy.spatial.distance import cdist
import numpy as np
#%%
n, m = map(int, input().split())

st = [list(map(int, input().split())) for _ in range(n)]
cp = [list(map(int, input().split())) for _ in range(m)]
#%%

# for s in st:
#     print(cityblock(s, np.array(cp)))
cd = cdist(st, cp, 'cityblock')
idx = np.argmin(cd, axis=1)
for i in idx:
    print(i+1)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
l = [list(map(int,input().split())) for i in range(n)]
a,b = [list(i) for i in zip(*l)]
l = [list(map(int,input().split())) for i in range(m)]
c,d = [list(i) for i in zip(*l)]

for i in range(n):
    p = 10 ** 9
    t = 50
    for j in range(m):
        e = abs(a[i] - c[j]) + abs(b[i] - d[j])
        if p > e:
            p = e
            t = j + 1
    print(t)

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):
  p,q=0,10**9
  for j in range(M):
    if q>abs(c[j][0]-a[i][0])+abs(c[j][1]-a[i][1]):
      q=abs(c[j][0]-a[i][0])+abs(c[j][1]-a[i][1])
      p=j+1
    elif q==abs(c[j][0]-a[i][0])+abs(c[j][1]-a[i][1]):
      if abs(p-i)>abs(j+1-i):
        p=j+1
  print(p)

Submission status: Accepted

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

for i in range(N):
  long=10**9
  ans=-1
  for j in range(M):
    d=abs(A[i][0]-C[j][0])+abs(A[i][1]-C[j][1])
    if long>d:
      ans=C[j][2]
      long=d
  print(ans)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
student = [list(map(int,input().split())) for _ in range(N)]
cpoint = [list(map(int,input().split())) for _ in range(M)]
for i in range(N):
    mannmn = 10**10
    mann = 10**10
    for j in range(M):
        mann = abs(student[i][0] - cpoint[j][0])+abs(student[i][1] - cpoint[j][1])
        if mann < mannmn:
            mannmn = mann
            ref = j
    print(ref+1)

Submission status: Accepted

Solution code:
# abc057_b.py
def calc(p1, p2):
    return abs(p1[0]-p2[0])+abs(p1[1]-p2[1])


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):
    dist = 10**9
    ans = 0
    for j in range(M):
        now_dist = calc(ab[i], cd[j])
        if dist > now_dist:
            dist = now_dist
            ans = j+1
    print(ans)

Submission status: Accepted

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

## Library

import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools
import copy

## input

# N=int(input())
# A,B,C,D=map(int, input().split())
# S = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]
#    S = []
#    for _ in range(N):
#        S.append(list(input()))

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

tmp = 10**10
for i in range(N):
    kyori = tmp
    ans = 0
    for j in range(M):
        tmp2 = abs(AB[i][0]-CD[j][0])+abs(AB[i][1]-CD[j][1])
        if kyori > tmp2:
            kyori = tmp2
            ans = j+1
    print(ans)

Submission status: Accepted

Solution code:
def readInts():
	return list(map(int, input().split()))

n,m = readInts()
ab = [readInts() for i in range(n)]
cd = [readInts() for i in range(m)]

for i in ab:
	ansv = float("inf")
	ansi = -1
	for j in range(len(cd)):
		if abs(i[0]-cd[j][0])+abs(i[1]-cd[j][1])<ansv:
			ansv = abs(i[0]-cd[j][0])+abs(i[1]-cd[j][1])
			ansi = j+1
	print(ansi)

Submission status: Accepted

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

for a, b in ST:
    dif, pos = 1e20, 100
    for j, (c, d) in enumerate(CP):
        tmp = abs(a - c) + abs(b - d)
        if dif > tmp:
            dif, pos = tmp, j + 1
    print(pos)

Submission status: Accepted

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

for a, b in start:
    distance = 1001001001
    ans = 0
    for i in range(len(check)):
        c, d = check[i][0], check[i][1]
        if abs(a - c) + abs(b - d) < distance:
            distance = abs(a - c) + abs(b - d)
            ans = i + 1
    print(ans)

Submission status: Accepted

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

for a, b in ab:
    md = 1001001001
    res = 0
    for i in range(m):
        tmp = abs(a - cd[i][0]) + abs(b - cd[i][1])
        if tmp < md:
            md = tmp
            res = i + 1
    print(res)

Submission status: Accepted

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


for n in range(N):
  ans = []
  for m in range(M):
    ans.append(abs(A[n][0]-C[m][0])+abs(A[n][1]-C[m][1]))
  print(ans.index(min(ans))+1)

Submission status: Accepted

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

  p1 = []
  p2 = []

  for _ in range(N):
    x, y = list(map(int, input().split()))
    p1.append([x, y])
  
  for _ in range(M):
    c, d = list(map(int, input().split()))
    p2.append([c, d])

  for p in p1:
    x1, y1 = p
    near = 10 ** 9
    ans = 0
    
    for i, q in enumerate(p2):
      x2, y2 = q
      d = abs(x1 - x2) + abs(y1 - y2)

      if near > d:
        near = d
        ans = i
    
    print(ans + 1)

if __name__ == "__main__":
  main()

Submission status: Accepted

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

for i in range(N):
    d=float("inf")
    ans=-1
    for j in range(M):
        if d>abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1]):
            d=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())
p = [list(map(int, input().split())) for _ in range(n)]
c = [list(map(int, input().split())) for _ in range(m)]


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


for i in range(n):
    x = min(c, key=lambda x: dist(p[i], x))
    num = c.index(x) + 1
    print(num)

Submission status: Accepted

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


for i in range(n):
    tmp = 10**16
    ans = 0
    for j in range(m):
        b = (abs(s[i][0]-c[j][0])+abs(s[i][1]-c[j][1]))
        if tmp > b:
            tmp = b
            ans = j+1
    print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
a, b, ans = [], [], []
max0 = 10**10

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

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

for i in a:
    for j, k in enumerate(b):
        val = abs(i[0]-k[0])+abs(i[1]-k[1])
        if val < max0:
            pre = j
            max0 = val
    ans.append(pre+1)
    max0 = 10**10
[print(x) for x in ans]

Submission status: Accepted

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

N, M = map(int, input().split())
ab = []
cd = []

# 学生の位置の取得
for i in range(N):
    tmp = list(map(int, input().split()))
    ab.append(tmp)

# チェックポイントの位置の取得
for i in range(M):
    tmp = list(map(int, input().split()))
    cd.append(tmp)


# 変数初期化
tmp_d = 0

# 学生を1人ずつ評価
for i in range(N):
    # 最小番号、最小距離の初期化
    min_d = 2 * (10 ** 8)
    min = 1
    for j in range(M):
        # マンハッタン距離の算出
        tmp_d = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
        if min_d > tmp_d:
            min_d = tmp_d
            min = j + 1
            #print('min', min)
    print(min)

Submission status: Accepted

Solution code:
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)]
    ans =[]
    for AB in ab:
        m = 10**9
        mza = None
        for i,CD in enumerate(cd):
            d = dist(AB,CD)
            if m > d:
                mza = i+1
                m = d
        ans.append(mza)
    for a in ans:
        print(a)
    
def dist(ab, cd):
    return abs(ab[0]-cd[0])+abs(ab[1]-cd[1])
        
if __name__ == "__main__":
    main()

Submission status: Accepted

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

def manhattan(x1,y1,x2,y2):
    res = abs(x1-x2) + abs(y1-y2)
    return res

for i in range(N):
    memo = [float("inf")]*M
    for j in range(M):
        memo[j] = manhattan(*students[i],*checkpoints[j])
    ans = memo.index(min(memo)) + 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):
  s = 0
  t = float('inf')
  for j in range(m):
    p = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
    if p < t:
      s = j+1
      t = p
  print(s)

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:
    L = 10 ** 9
    p = 0
    i = 1
    for c, d in cd:
        l = abs(a - c) + abs(b - d)
        if l < L:
            L = l
            p = i
        i += 1
    print(p)

Submission status: Accepted

Solution code:
n,m=map(int, input().split())
a_list=[]
b_list=[]
for i in range(n):
  a,b=map(int, input().split())
  a_list.append(a)
  b_list.append(b)
c_list=[]
d_list=[]
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=2*(10**8)
  min_number=0
  for j in range(m):
    d=abs(a_list[i]-c_list[j])+abs(b_list[i]-d_list[j])
    if d<min:
      min=d
      min_number=j
  print(min_number+1)

Submission status: Accepted

Solution code:
# from pprint import pprint
# import math
# import collections

# n = int(input())
n, m = map(int, input().split(' '))
# a = list(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)

move = [[0] * m for i in range(n)]

for i in range(n):
    for j in range(m):
        move[i][j] = abs(a[i] - c[j]) + abs(b[i] - d[j])

ans = [0] * n
for i in range(n):
    for j in range(m):
        _min = min(move[i])
        ans[i] = move[i].index(_min) + 1

for a in ans:
    print(a)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a, b = [], []
for _ in range(n):
    a_i, b_i = map(int, input().split())
    a.append(a_i)
    b.append(b_i)
c, d = [], []
for _ in range(m):
    c_i, d_i = map(int, input().split())
    c.append(c_i)
    d.append(d_i)
for i in range(n):
    min_idx = -1
    min_distance = 10**10
    for j in range(m):
        distance = abs(a[i]-c[j]) + abs(b[i]-d[j])
        if min_distance > distance:
            min_idx = j
            min_distance = distance
    print(min_idx + 1)

Submission status: Accepted

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

A = [0 for _ in range(N)]
B = [0 for _ in range(N)]
C = [0 for _ in range(M)]
D = [0 for _ in range(M)]

for _ in range(N):
    A[_], B[_] = map(int, input().split())

for _ in range(M):
    C[_], D[_] = map(int, input().split())

# マンハッタン距離
# A(x1, y1), B(x2, y2)とすると、dist(A,B)=|x1-x2|+|y1-y2|

# N, M の最大値は50
# 50個のcheck pointに対して50個の学生を調べても余裕で間に合う
# 普通に実装してOK
ans = []
for s in range(N):
    nearest_cp = -1
    nearest_dist = 10e12 
    for c in range(M):
        d = abs(A[s]-C[c]) + abs(B[s]-D[c])
        if d < nearest_dist:
            nearest_dist = d
            nearest_cp = c
    
    ans.append(nearest_cp+1)

for a in ans:
    print(a)

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	B
# CreatedDate:  2020-06-26 15:54:41 +0900
# LastModified: 2020-06-26 16:12:17 +0900
#


import copy
# import numpy as np
# import pandas as pd


def main():
    n, m = map(int, input().split())
    x_y = []
    goal = []
    for i in range(n):
        x_y.append(list(map(int, input().split())))
    for i in range(m):
        goal.append(list(map(int, input().split())))

    for xy in x_y:
        tmp = list(map(lambda x: abs(xy[0]-x[0])+abs(xy[1]-x[1]), goal))
        print(tmp.index(min(tmp))+1)



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
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
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
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(), i+1) for i in range(M)]

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

Submission status: Accepted

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

for a,b in S:
  D = []
  for c,d in P:
    D.append(abs(a-c)+abs(b-d))
  print(1+D.index(min(D)))

Submission status: Accepted

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

for a,b in S:
  D = []
  for c,d in P:
    D.append(abs(a-c)+abs(b-d))
  print(1+P.index(P[D.index(min(D))]))

Submission status: Accepted

Solution code:
def mht(a,b):
	return abs(a[0]-b[0])+abs(a[1]-b[1])
n,m=map(int,input().split())
p=[list(map(int,input().split())) for _ in range(n)]
c=[list(map(int,input().split())) for _ in range(m)]
#print(p)
#print(c)
for i in p:#全ての人に対してループ
	a=[10**9,0]#[最小距離、チェックポイントの番号]
	for j in range(m):#全てのチェックポイントに対してループ
		if mht(i,c[j])<a[0]:#最小距離を更新した場合
			a=[mht(i,c[j]),j+1]
	print(a[1])#i番目の学生が行くチェックポイント

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))
P=[]
for i in range(M):
  c,d=map(int,input().split())
  P.append((c,d)) 
for i in range(N):
  D=10**9
  ans=0
  for j in range(M-1,-1,-1):
    if D>=(abs(S[i][0]-P[j][0])+abs(S[i][1]-P[j][1])):
      D=(abs(S[i][0]-P[j][0])+abs(S[i][1]-P[j][1]))
      ans=j
  print(ans+1)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
A = {}
for i in range (1,n+1):
    a,b = map(int,input().split())
    A[i] = [a,b]

B = {}
for i in range(1,m+1):
    c,d = map(int,input().split())
    B[i] = [c,d]

for v in A.values():
    t = float('inf')
    ans = 0
    for x,w in B.items():
        if abs(v[0]-w[0])+abs(v[1]-w[1]) < t:
            t = abs(v[0]-w[0])+abs(v[1]-w[1])
            ans = x
    print (ans)

Submission status: Accepted

Solution code:
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 x in a:
  ans,dist = -1,1000000000
  for i in range(m):
    d = abs(x[0]-b[i][0])+abs(x[1]-b[i][1])
    if d < dist:
      ans, dist = i+1,d
  print(ans)

Submission status: Accepted

Solution code:
import sys
N,M = map(int,input().split())
students = [None] * N
checkpoints = [None] * M
for student in range(0,N):
    students[student] = list(map(int,input().split()))
for checkpoint in range(0,M):
    checkpoints[checkpoint] = list(map(int,input().split()))

if N < 0 or N > 50 or M < 0 or M > 50:
    sys.exit()
for student in students:
    if student[0] < -100000000 or student[1] > 100000000:
        sys.exit()
for checkpoint in checkpoints:
    if checkpoint[0] < -100000000 or checkpoint[1] > 100000000:
        sys.exit()

distance = [40000000000000000] * N
result = [0] * N
count = 0
for student in students:
    checkpoint_count = 0
    for checkpoint in checkpoints:
        tmp_distance = int(abs(student[0] - checkpoint[0]) + abs(student[1] - checkpoint[1]))
        if int(distance[count]) > int(tmp_distance):
            distance[count] = tmp_distance
            result[count] = checkpoint_count + 1
        checkpoint_count += 1
    count += 1

for I in result:
    print(I)

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

for i in range(n):
    l = float('inf')
    for j in range(m):
        ls = abs(s[i][0]-c[j][0]) + abs(s[i][1]-c[j][1])
        if l > ls:
            l = ls
            ans[i] = j+1
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
def main():
  n,m = list(map(int,input().split()))
  ab = [map(int, input().split()) for _ in range(n)]
  a, b = [list(i) for i in zip(*ab)]
  cd = [map(int, input().split()) for _ in range(m)]
  c, d = [list(i) for i in zip(*cd)]
  
  for i in range(0,n):
    min=abs(a[i]-c[0])+abs(b[i]-d[0])
    min_index=0
    for j in range(1,m):
      if min>abs(a[i]-c[j])+abs(b[i]-d[j]):
        min=abs(a[i]-c[j])+abs(b[i]-d[j])
        min_index=j
    print(min_index+1)
  
main()