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: Wrong Answer

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


for a, b in ab:
    num = float('inf')
    check = 0
    for i in range(M):
        if num > (a - cd[i][0]) ** 2 + (b - cd[i][1]) ** 2:
            num = (a - cd[i][0]) ** 2 + (b - cd[i][1]) ** 2
            check = i + 1
    ans.append(check)

for i in ans:
    print(i)

Submission status: Wrong Answer

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

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

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

for i in range(n):
    num = 1
    ans = 0
    min_man = 10000
    for j in range(m):
        man = abs(a[i]-c[j])+abs(b[i]-d[j])
        if min_man > man:
            min_man = man
            ans = num
        num+=1
    print(ans)

Submission status: Wrong Answer

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def Yes(): print("Yes"); return
def No(): print("No"); return

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def Base_10_to_n(X, n):
  if X//n:
    return Base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def Base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

N,M = inputIL()
n = inputILL(N)
m = inputILL(M)

ans = []
for c,d in m:
  MIN = (INF,INF)
  count = 0
  for a,b in n:
    count += 1
    dis = abs(a-c)+abs(d-b)
    if dis < MIN[0]:
      MIN = (dis,count)
  ans.append(str(MIN[1]))

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

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
student = []
for _ in range(n):
    student.append([int(x) for x in input().split()])
chkpoint = []
for _ in range(m):
    chkpoint.append([int(x) for x in input().split()])

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

for i in range(n):
    minx = 10**8+1
    goto = 0
    for j in range(m):
        tmp = dist(student[i], chkpoint[j])
        if minx > tmp:
            minx = tmp
            goto = j+1
    print(goto)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
stds = [tuple(map(int,input().split())) for _ in range(n)]
points = [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 std in stds:
  ans = (-1, float('inf'))
  for i, pnt in enumerate(points):
    dst = d(std,pnt)
    #print(i, dst, ans)
    if dst < ans[1]:
      ans = (i, dst)
  print(ans[0]+1)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
stds = [tuple(map(int,input().split())) for _ in range(n)]
points = [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 std in stds:
  ans = (float('inf'), -1)
  for i, pnt in enumerate(points):
    if d(std,pnt) < ans[1]:
      ans = (i, pnt)
  print(i+1)

Submission status: Wrong Answer

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

x = [0]*M
y = [0]*M

for  i in range(M):
    x[i],y[i]= map(int,input().split())

for i in range(N):
    dis = 10000000000000000
    for j in range(M):
        dis = min(dis,(abs(a[i]-x[j])+abs(b[i]-y[j])))
        res = i

    print(res+1)

Submission status: Wrong Answer

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

for i in range(n):
    distance = []
    minDistance = 10 ** 8 + 1
    checkPoint = 1
    for j in range(m):
        distance.append(abs(a[i] - c[j]) + abs(b[i] - d[j]))
        if minDistance > distance[j]:
            minDistance = distance[j]
            checkPoint = j + 1
    print(checkPoint)

Submission status: Wrong Answer

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

for i in range(n):
    distance = []
    tmpDistance = 10 ** 8 + 1
    checkPoint = 0
    for j in range(m):
        distance.append(abs(a[i] - c[j]) + abs(b[i] - d[j]))
        if tmpDistance > distance[j]:
            tmpDistance = distance[j]
            checkPoint = j + 1
    print(checkPoint)

Submission status: Wrong Answer

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

for i in range(n):
    distance = []
    tmpDistance = 10 ** 8
    checkPoint = 0
    for j in range(m):
        distance.append(abs(a[i] - c[j]) + abs(b[i] - d[j]))
        if tmpDistance > distance[j]:
            tmpDistance = distance[j]
            checkPoint = j + 1
    print(checkPoint)

Submission status: Wrong Answer

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 = 2*(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: Wrong Answer

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: Wrong Answer

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: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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][0]-C[t][1]))
            ans=t+1
        else:
            continue
    print(ans)

Submission status: Wrong Answer

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][0]-C[t][1])<z:
            z=abs(A[i][0]-C[t][0])+abs(A[i][0]-C[t][1])
            ans=t+1
        else:
            continue
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline

def main():
    n,m = map(int, input().split())
    s = []
    p = []
    min = [10**8]*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: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline

def main():
    n,m = map(int, input().split())
    s = []
    p = []
    min = [10**8]*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 reversed(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: Wrong Answer

Solution code:
N,M=map(int,input().split())
S=[]
L=[]
for i in range(N):
	S.append(list(map(int,input().split())))
for i in range(M):
	L.append(list(map(int,input().split())))
for i in range(N):
	tmp=0
	for j in range(M):
		tmp+=abs(S[i][0]-L[j][0])+abs(S[i][1]-L[j][1])
	if min(tmp//M-tmp/M,tmp//M+1-tmp/M)==tmp//M-tmp/M:
		print(tmp//M)
	else:
		print(tmp//M+1)

Submission status: Wrong Answer

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: Wrong Answer

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 i in range(0,n):
  minkyori=10*100
  keep=0
  for j in range(0,m):
    kyori=abs(gakusei[i][0]-check[j][0])+abs(gakusei[i][1]-check[j][1])
    if kyori<minkyori:
      minkyori=kyori
      keep=j
  print(keep+1)

Submission status: Wrong Answer

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 i in range(0,n):
  minkyori=10*100
  keep=0
  for j in range(0,m):
    kyori=abs(gakusei[i][0]-check[j][0])+abs(gakusei[i][1]-check[j][1])
    if kyori<minkyori:
      minkyori=kyori
      keep=j+1
  print(keep)

Submission status: Wrong Answer

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 i in range(0,n):
  minkyori=10*10
  keep=0
  for j in range(0,m):
    kyori=abs(gakusei[i][0]-check[j][0])+abs(gakusei[i][1]-check[j][1])
    if kyori<minkyori:
      minkyori=kyori
      keep=j+1
  print(keep)

Submission status: Wrong Answer

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=100000000,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: Wrong Answer

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: Wrong Answer

Solution code:
N, M = map(int,input().split())
st = [[] for _ in range(N)]
cp = [[] for _ in range(M)]
for i in range(N):
    a, b = map(int,input().split())
    st[i] = [a, b]
for j in range(M):
    c, d = map(int,input().split())
    cp[j] = [c, d]
for i in range(N):
    ne = 10**12
    p = 0
    for j in range(M):
        dis = abs(st[i][0]-cp[j][0])+abs(st[i][1]-cp[j][1])
        print(dis)
        if dis < ne:
            p = j
            ne = dis
        print(p)
    print(p+1)

Submission status: Wrong Answer

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

ans = [] 
for i in range(n):
    mn = 10**8
    idx = 0
    for j in range(m):
        p = abs(stu[i][0] - chp[j][0]) + abs(stu[i][1] - chp[j][1])
        if p < mn:
            mn = p
            idx = j + 1
    ans.append(idx)
    
for i in range(n):
    print(ans[i])

Submission status: Wrong Answer

Solution code:
# 2020/04/26
# AtCoder Beginner Contest 057 - B

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

stds = list()
chkp = list()

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

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

# Calc
for i in range(n):
    mindist = 10*9
    ans = -1
    for j in range(m):
        dist = abs(chkp[j][0] - stds[i][0]) + abs(chkp[j][1] - stds[i][1])
        if dist < mindist:
            mindist = dist
            ans = j + 1

    # Output
    print(ans)

Submission status: Wrong Answer

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)]
min = 2e+8
c = 0

for i in range(n):
    for j in range(m):
        d = abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
        if d<min:
            min=d
            c = j+1
    min = 2e+8
    print(c)

Submission status: Wrong Answer

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

a, b = [0] * n, [0] * n
c, d = [0] * m, [0] * m
for i in range(n):
    a[i], b[i] = map(int, input().split())
for i in range(m):
    c[i], d[i] = map(int, input().split())
ans = [0] * n
for i in range(n):
    min = 10 * 20
    for j in range(m):
        dis = abs(a[i] - c[j]) + abs(b[i] - d[j])
        if min > dis:
            min = dis
            ans[i] = j + 1
    print(ans[i])

Submission status: Wrong Answer

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)]
print(ab)
print(cd)
for i in range(n):
    seq_min = 1e9
    ans = -1
    for j in range(m):
        seq = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
        if seq_min > seq:
            seq_min = seq
            ans = j
    print(ans + 1)

Submission status: Wrong Answer

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):
    seq_min = 1e8
    ans = -1
    for j in range(m):
        seq = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
        if seq_min > seq:
            seq_min = seq
            ans = j
    print(ans + 1)

Submission status: Wrong Answer

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):
    seq_min = 1e8
    # seq_min = float('inf')
    ans = -1
    for j in range(m):
        seq = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
        if seq_min > seq:
            seq_min = seq
            ans = j + 1
    print(ans)

Submission status: Wrong Answer

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 = [1e8] * n
for i in range(n):
    seq_min = 1e8
    for j in range(m):
        seq = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
        if seq_min > seq:
            seq_min = seq
            ans[i] = j + 1
for a in ans:
    print(a)

Submission status: Wrong Answer

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((j[0] - i[0]) + (j[1] - i[1])))
    print(l.index(min(l)) + 1)

Submission status: Wrong Answer

Solution code:
def Distance(t_a,t_b):
    return abs(t_a[0]-t_b[0]) + abs(t_a[1]-t_b[1])

n,m = map(int,input().split(' '));
students = []
for p in range(n):
    students.append(tuple(map(int,input().split(' '))))
check = []
for q in range(m):
    check.append(tuple(map(int,input().split(' '))))
ans = ''
for s in students:
    dmin = Distance(s, check[0])
    dindex = 0
    i = 1
    while i < m:
        d0 = Distance(s, check[i])
        if d0 < dmin:
            dmin = d0
            dindex = i
        i += 1
    ans += str(dindex) + '\n'
print(ans)

Submission status: Wrong Answer

Solution code:
N, M = [int(x) for x in input().split()]

P = []
C = []


for i in range(N):
    P += [[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):
    d_min = abs(P[0][0] - C[0][0]) + abs(P[0][1] - C[0][1])
    c_min = 1
    for j in range(M):
        d = abs(P[i][0] - C[j][0]) + abs(P[i][1] - C[j][1])
        if d < d_min:
            d_min = d
            c_min = j+1
    print(c_min)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
a=[list(map(int,input().split())) for a in range(n)]
c=[list(map(int,input().split())) for b in range(m)]
dist=0
minnum=0
for indi,i in enumerate(a):
    min=10*10
    minnum=0
    for indj,j in enumerate(c):
        dist=0 
        dist+=abs(i[0]-j[0])
        dist+=abs(i[1]-j[1])
        #print("dist={}".format(dist))
        if min>dist:
            min=dist
            minnum=indj
    print(minnum+1)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
a=[list(map(int,input().split())) for a in range(n)]
c=[list(map(int,input().split())) for b in range(m)]
dist=0
minnum=0
for indi,i in enumerate(a):
    dist=0
    min=10*16
    minnum=0
    for indj,j in enumerate(c):
        dist+=abs(i[0]-j[0])
        dist+=abs(i[1]-j[1])
        if min>dist:
            min=dist
            minnum=indj
        dist=0 
    print(minnum+1)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
a=[list(map(int,input().split())) for a in range(n)]
c=[list(map(int,input().split())) for b in range(m)]
dist=0
minnum=0
for indi,i in enumerate(a):
    dist=0
    min=10*14
    for indj,j in enumerate(c):
        dist+=abs(i[0]-j[0])
        dist+=abs(i[1]-j[1])
        if min>dist:
            min=dist
            minnum=indj
        dist=0 
    print(minnum+1)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
a=[list(map(int,input().split())) for a in range(n)]
c=[list(map(int,input().split())) for b in range(m)]
print(a)
print(c)
dist=0
minnum=0
for indi,i in enumerate(a):
    dist=0
    min=10*14
    for indj,j in enumerate(c):
        dist+=abs(i[0]-j[0])
        dist+=abs(i[1]-j[1])
        if min>dist:
            min=dist
            minnum=indj
            print(dist)
        dist=0 
    print(minnum+1)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
a=[list(map(int,input().split())) for a in range(n)]
c=[list(map(int,input().split())) for b in range(m)]
dist=0
min=10*12
minnum=-1
for indi,i in enumerate(a):
    dist=0
    min=10*12
    for indj,j in enumerate(c):
        dist+=abs(i[0]-j[0])
        dist+=abs(i[1]-j[1])
        if min>dist:
            min=dist
            minnum=indj
        dist=0
    
    print(minnum+1)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
A=[[0,0]for i in range(n)]
B=[[0,0] for i in range(m)]
E=[1]*n
for i in range(n):
    A[i][0],A[i][1]=map(int,input().split())
for i in range(m):
    B[i][0],B[i][1]=map(int,input().split())
for i in range(n):
    c=abs(A[i][0]-B[0][0])+abs(A[i][1]-B[0][1])
    for j in range(1,m):
        if abs(A[i][0]-B[j][0])+abs(A[i][1]-B[j][1])<c:
            E[i]=j+1
for i in range(n):
    print(E[i])

Submission status: Wrong Answer

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):
    tmp = float("inf")
    ans = 0
    y = float("inf")
    for j in range(m):
        x = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
        if x < tmp or x == tmp and abs(i - j) < y:
            tmp = x
            ans = j + 1
            y = abs(i - j)
    print(ans)

Submission status: Wrong Answer

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

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

INF = 10 ** 8 * 2
for s in ss:
    dist = INF
    c_point = 0
    a, b = s
    for i, v in enumerate(p):
        c, d = v
        manhattan = abs(a - c) + abs(b - d)
        if manhattan < dist:
            c_point = i + 1
            dist = manhattan
    print(c_point)

Submission status: Wrong Answer

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)]
def d(x,y):
    return abs(x[0]-y[0])+abs(x[1]+y[1])
for i in a:
    ans=10101001010
    ch=0
    for j in range(m):
        if d(i,c[j])<ans:
            ch=j
            ans=d(i,c[j])
    print(ch+1)

Submission status: Wrong Answer

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

cd = [tuple(map(int, input().split())) for i in range(M)]


for a, b in ab:
    ret = -1
    dis = 10**20
    for i, x in enumerate(cd):
        c, d = x
        if dis > (c-a)**2 + (d-b)**2:
            dis = (c-a)**2 + (d-b)**2
            ret = i
    print(ret+1)

Submission status: Wrong Answer

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

cd = [tuple(map(int, input().split())) for i in range(M)]


for a, b in ab:
    ret = 0
    dis = 10**20
    for i, x in enumerate(cd):
        c, d = x
        if dis > (c-a)**2 + (d-b)**2:
            dis = (c-a)**2 + (d-b)**2
            ret = i
    print(ret+1)

Submission status: Wrong Answer

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

cd = [tuple(map(int, input().split())) for i in range(M)]


for a, b in ab:
    ret = 0
    dis = 10**17
    for i, x in enumerate(cd):
        c, d = x
        if dis > (c-a)**2 + (d-b)**2:
            dis = (c-a)**2 + (d-b)**2
            ret = i
    print(ret+1)

Submission status: Wrong Answer

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

for x in range(N):
    min_y = 0
    min_value = 1000000
    for y in range(M):
        distance = abs(n_student[x][0] - m_point[y][0]) + \
            abs(n_student[x][1] - m_point[y][1])
        if distance < min_value:
            min_value = distance
            min_y = y + 1
    print(min_y)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
stu = []
check = []
for i in range(N):
    s = list(map(int, input().split()))
    stu.append(s)
for i in range(M):
    c = list(map(int, input().split()))
    check.append(c)
ans = [0 for i in range(N)]
for i in range(N):
    min = 1000000
    for j in range(M):
        dis = abs(stu[i][0]-check[j][0])+abs(stu[i][1]-check[j][1])
        if min > dis:
            min = dis
            ans[i] = j+1
for i in ans:
    print(i)

Submission status: Wrong Answer

Solution code:
import numpy as np
from scipy.spatial.distance import minkowski

n, m = map(int, input().split())
a = np.array([list(map(int, input().split())) for i in range(n)])
for i in range(m):
    b = np.array(list(map(int,input().split())))
    c = np.array([minkowski(i, b , 1) for i in a], dtype=np.int64)
    ans = np.argmin(c) + 1
    print(ans)

Submission status: Wrong Answer

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 ab:
	e=10**8
	f=0
	for p,j in enumerate(cd):
		g=abs(i[0]-j[0])+abs(i[1]-j[1])
		if e>g:
			e,f=g,p
	print(f+1)