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:
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b = LI()
    print((a+b)%24)
    return

#B
def B():
    n, m = LI()
    ab = LIR(n)
    cd = LIR(m)
    for a, b in ab:
        ans = inf
        an = 0
        for num, cdi in enumerate(cd):
            c, d = cdi
            if ans > abs(a - c) + abs(b - d):
                ans = abs(a - c) + abs(b - d)
                an = num
        print(an) 
    return

#C
def C():
    return

#D
def D():
    return

#Solve
if __name__ == '__main__':
    B()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b = LI()
    print((a+b)%24)
    return

#B
def B():
    n, m = LI()
    ab = LIR(n)
    cd = LIR(m)
    for a, b in ab:
        ans = inf
        an = 0
        for num, cdi in enumerate(cd):
            c, d = cdi
            if ans > abs(a - c) + abs(b - d):
                an = num
        print(an) 
    return

#C
def C():
    return

#D
def D():
    return

#Solve
if __name__ == '__main__':
    B()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b = LI()
    print((a+b)%24)
    return

#B
def B():
    n, m = LI()
    ab = LIR(n)
    for _ in range(m):
        c, d = LI()
        ans = inf
        x = 1
        for a, b in ab:
            b = min(ans, abs(c - a) + abs(b - d))
            if b != ans:
                ans = b
                an = x
            x += 1
        print(an)
    return

#C
def C():
    return

#D
def D():
    return

#Solve
if __name__ == '__main__':
    B()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b = LI()
    print((a+b)%24)
    return

#B
def B():
    n, m = LI()
    ab = LIR(n)
    for _ in range(m):
        c, d = LI()
        ans = inf
        x = 0
        for a, b in ab:
            b = min(ans, abs(c - a) + abs(b - d))
            if b != ans:
                an = x
            x += 1
        print(an)
    return

#C
def C():
    return

#D
def D():
    return

#Solve
if __name__ == '__main__':
    B()

Submission status: Wrong Answer

Solution code:
def main():
    n, m = map(int, input().split())
    students = [tuple(map(int, input().split())) for i in range(n)]
    check_points = [tuple(map(int, input().split())) for i in range(m)]

    for a, b in students:
        dist = [abs(a - c) + abs(b - d) for c, d in check_points]
        print(min(dist) + 1)

    # for st in students:
    #     min_pt = check_points[0]
    #     for pt in check_points:
    #         if abs(pt[0] - st[0]) + abs(pt[1] - st[1]) < \
    #            abs(min_pt[0] - st[0]) + abs(min_pt[1] - st[1]):
    #             min_pt = pt
    #     print(check_points.index(min_pt) + 1)


if __name__ == "__main__":

    main()

Submission status: Wrong Answer

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

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

# 生徒単位でチェック
for sx,sy in student:
    dist=2*10**8
    pnum=0
    for i, p in enumerate(point):
        px,py=p[0],p[1]
        pdist=abs(sx-px)+abs(sy-py)
        if pdist<dist:
            dist=pdist
            pnum=i+1
    print(pnum)

Submission status: Wrong Answer

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

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

def check(i):
    min_d = 10 * 9
    x = H[i][0]
    y = H[i][1]
    idx = -1
    for i, p in enumerate(P):
        d = abs(x - p[0]) + abs(y - p[1])
        if d < min_d:
            min_d = d
            idx = i
    return idx

for i in range(N):
    near = check(i)
    print(near + 1)

Submission status: Wrong Answer

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

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

def check(i):
    min_d = 1000
    x = H[i][0]
    y = H[i][1]
    idx = -1
    for i, p in enumerate(P):
        d = abs(x - p[0]) + abs(y - p[1])
        if d < min_d:
            min_d = d
            idx = i
    return idx

for i in range(N):
    near = check(i)
    print(near+1)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

N, M = map(int, input().split())
std_li = [list(map(int, input().split())) for i in range(N)]
chk_li = [list(map(int, input().split())) for j in range(M)]
dist = 0

for i in range(N):
    ctr = 0
    min_dist = pow(10,8) * 4 + 1
    for j in range(M):
        dist = abs(std_li[i][0] - chk_li[j][0]) + abs(std_li[i][1] - chk_li[j][1])
        print(dist, min_dist)
        if dist < min_dist:
            min_dist = dist
            ctr = j + 1
    print(ctr)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

N, M = map(int, input().split())
std_li = [list(map(int, input().split())) for i in range(N)]
chk_li = [list(map(int, input().split())) for j in range(M)]
dist = 0

for i in range(N):
    ctr = 0
    min_dist = pow(10,8) * 2 + 1
    for j in range(M):
        dist = abs(std_li[i][0] - chk_li[j][0]) + abs(std_li[i][1] - chk_li[j][1])
        if dist < min_dist:
            min_dist = dist
            ctr = j + 1
    print(ctr)

Submission status: Wrong Answer

Solution code:
n,m = (int(i) for i in 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)]

for a,b in ab:
    ans,distance = 0,float('inf')
    for i,cont in enumerate(cd):
        c,d = cont
        #print(abs(a-c)+abs(b-d))
        if distance > abs(a-c)+abs(b-d):
            ans = i
            distance = abs(a-c)+abs(b-d)
    print(ans+1)
    cd[ans] = [float('inf'),float('inf')]

Submission status: Wrong Answer

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


for i in range(n):
    cnt = 10*9
    num = 0
    for j in range(m):
        c = abs(ab[i][0]-cd[j][0]) + abs(ab[i][1]-cd[j][1])
        if c<cnt:
            cnt = c
            num = j+1
    print(num)

Submission status: Wrong Answer

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


for i in range(n):
    cnt = 10*9
    num = 0
    for j in range(m):
        c = abs(ab[i][0]-cd[j][0]) + abs(ab[i][1]-cd[j][1])
        if c<cnt:
            cnt = c
            num = j+1
print(num)

Submission status: Wrong Answer

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

for i in range(n):
	a, b = map(int, input().split())
	ans = 1
	fdif = abs(a-cd[0][0]) + abs(b-cd[0][1])
	for j in range(m): 
		dif = abs(a - cd[j][0]) + abs(b - cd[j][1])
		if fdif > dif:
			ans = j+1
			break
	print(ans)

Submission status: Wrong Answer

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

for i in range(n):
	a, b = map(int, input().split())
	ans = 0
	fdif = abs(a-cd[0][0]) + abs(b-cd[0][1])
	for j in range(m):
		dif = abs(a - cd[j][0]) + abs(b - cd[j][1])
		if fdif > dif:
			ans = j+1
			break
	print(ans)

Submission status: Wrong Answer

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

for i in range(n):
    cnt = 10*9
    num = 0
    for j in range(m):
        c = abs(ab[i][0]-cd[j][0]) + abs(ab[i][1]-cd[j][1])
        if c<cnt:
            cnt = c
            num = j+1
    print(num)

Submission status: Wrong Answer

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

for i in range(n):
    cnt = 10*9
    num = 0
    for j in range(m):
        c = abs(ab[i][0]-cd[j][0]) + abs(ab[i][1]-cd[j][1])
        if c<cnt:
            cnt = c
            num = j+1
    print(cnt)

Submission status: Wrong Answer

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

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

for aa, bb in zip(a, b):
    l = 2 * 10 ** 8
    num = 0
    for i, (cc, dd) in enumerate(zip(c, d)):
        dis = abs(aa - cc) + abs(bb - dd)
        if dis < l:
            l = dis
            num = i + 1
    print(num)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

for j in range(N):
	for k in range(M - 1, -1, -1):
		ans = "nan"
		diff = float("inf")
		if abs(a[j] - c[k]) + abs(b[j] - d[k]) < diff:
			diff = abs(a[j] - c[k]) + abs(b[j] - d[k])
			ans = k
	print(k + 1)

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)]
ans=[50]*n
for i in range(n):
    tmp=50
    for j in range(m):
        ck=abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
        if tmp>ck:
            tmp=ck
            ans[i]=j+1
print(*ans,sep='\n')

Submission status: Wrong Answer

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

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

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

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

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

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

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

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

Submission status: 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 = [0]*n

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

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

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

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

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

Submission status: Wrong Answer

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

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


for student in students:
    mini = [1000000, -1]
    for i in range(m):
        if dist(student,checkpoints[i]) < mini[0]:
            mini = [dist(student, checkpoints[i]),i]
    print(mini[1]+1)

Submission status: Wrong Answer

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

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

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

for i in range(0,N):
    mnh = 10 ** 8
    point = 100
    h = 0
    for h in range(0,M):
        tmp = abs(cd_a[h][0] - ab_a[i][0]) + abs(cd_a[h][1] - ab_a[i][1])
        if tmp < mnh:
            mnh = tmp
            point = h
    print(point + 1)

Submission status: Wrong Answer

Solution code:
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):
    m_min = 100000000
    i_min = -1
    for j in range(M):
        m = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
        if m < m_min:
            m_min = m 
            i_min = j
    print(i_min+1)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
hoge_x=[]
hoge_y=[]
huga_x=[]
huga_y=[]
for i in range(n):
  a,b=map(int,input().split())
  hoge_x.append(a)
  hoge_y.append(a)
  
for j in range(m):
  a,b=map(int,input().split())
  huga_x.append(a)
  huga_y.append(b)

for i in range(n):
  ans_kyori=-1
  ans_index=-1
  for j in range(m):
    kyori=abs(hoge_x[i]-huga_x[j])+abs(hoge_y[i]-huga_y[j])
    if(kyori<ans_kyori or ans_kyori==-1):
      ans_kyori=kyori
      ans_index=j+1
  print(ans_index)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
a=[list(map(int,input().split()))for i in range(n)]
b=[list(map(int,input().split()))for i in range(m)]
for i in a:
  ans=10**18
  for j in b:
    ans=min(ans,abs(i[0]-j[0])+abs(i[1]-j[1]))
  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)]
b=[list(map(int,input().split()))for i in range(m)]
for i in a:
  ans=10**18
  for j in b:
    ans=min(ans,abs(i[0]-j[0])+abs(i[1]-j[1]))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
a, b, c, d = [],[],[],[]

for i in range(N):
  ai, bi = map(int, input().split())
  a.append(ai)
  b.append(bi)
#  print(a, b)
for j in range(M):
  cj, dj = map(int, input().split())
  c.append(cj)
  d.append(dj)
  
#print(a,b,c,d)
  
for i in range(N):
  dist, min_dist = 0, 10**8+1
  ans = 1
  for j in range(M):
    dist = abs(c[j] - a[i]) + abs(d[j] - b[i])
    if dist < min_dist:
      ans = j+1
      min_dist = dist
#    print("ai:{}, bi:{}, cj:{}, dj:{}, dist:{}, ans:{}".format(a[i], b[i], c[j], d[j], dist, ans))
#    print("i:{}, j:{}, dist:{}, min_dist:{}, ans:{}".format(i, j, dist, min_dist, ans))
#    min_dist = min(dist, min_dist)
  print(ans)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
a, b, c, d = [],[],[],[]

for i in range(N):
  ai, bi = map(int, input().split())
  a.append(ai)
  b.append(bi)
#  print(a, b)
for j in range(M):
  cj, dj = map(int, input().split())
  c.append(cj)
  d.append(dj)
  
#print(a,b,c,d)
  
for i in range(N):
  dist, min_dist = 0, 10**8+1
  ans = 0
  for j in range(M):
    dist = abs(c[j] - a[i]) + abs(d[j] - b[i])
    if dist < min_dist:
      ans = j+1
      min_dist = dist
#    print("ai:{}, bi:{}, cj:{}, dj:{}, dist:{}, ans:{}".format(a[i], b[i], c[j], d[j], dist, ans))
#    print("i:{}, j:{}, dist:{}, min_dist:{}, ans:{}".format(i, j, dist, min_dist, ans))
#    min_dist = min(dist, min_dist)
  print(ans)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
a, b, c, d = [],[],[],[]

for i in range(N):
  ai, bi = map(int, input().split())
  a.append(ai)
  b.append(bi)
#  print(a, b)
for j in range(M):
  cj, dj = map(int, input().split())
  c.append(cj)
  d.append(dj)
  
#print(a,b,c,d)
  
for i in range(N):
  dist, min_dist = 0, 10**8
  ans = 0
  for j in range(M):
    dist = abs(c[j] - a[i]) + abs(d[j] - b[i])
    if dist < min_dist:
      ans = j+1
      min_dist = dist
#    print("ai:{}, bi:{}, cj:{}, dj:{}, dist:{}, ans:{}".format(a[i], b[i], c[j], d[j], dist, ans))
#    print("i:{}, j:{}, dist:{}, min_dist:{}, ans:{}".format(i, j, dist, min_dist, ans))
#    min_dist = min(dist, min_dist)
  print(ans)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
a, b, c, d = [],[],[],[]

for i in range(N):
  ai, bi = map(int, input().split())
  a.append(ai)
  b.append(bi)
#  print(a, b)
for j in range(M):
  cj, dj = map(int, input().split())
  c.append(cj)
  d.append(dj)
  
#print(a,b,c,d)
  
for i in range(N):
  dist, min_dist = 0, 10**8
  ans = 0
  for j in range(M):
    dist = abs(c[j] - a[i]) + abs(d[j] - b[i])
    if dist < min_dist:
      ans = j+1
#    print("ai:{}, bi:{}, cj:{}, dj:{}, dist:{}, ans:{}".format(a[i], b[i], c[j], d[j], dist, ans))
#    print("i:{}, j:{}, dist:{}, min_dist:{}, ans:{}".format(i, j, dist, min_dist, ans))
    min_dist = min(dist, min_dist)
  print(ans)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
a, b, c, d = [],[],[],[]

ans = 0

for i in range(N):
  ai, bi = map(int, input().split())
  a.append(ai)
  b.append(bi)
#  print(a, b)
for j in range(M):
  cj, dj = map(int, input().split())
  c.append(cj)
  d.append(dj)
  
#print(a,b,c,d)
  
for i in range(N):
  dist, min_dist = 0, 10**8
  for j in range(M):
    dist = abs(c[j] - a[i]) + abs(d[j] - b[i])
    if dist < min_dist:
      ans = j+1
#    print("ai:{}, bi:{}, cj:{}, dj:{}, dist:{}, ans:{}".format(a[i], b[i], c[j], d[j], dist, ans))
#    print("i:{}, j:{}, dist:{}, min_dist:{}, ans:{}".format(i, j, dist, min_dist, ans))
    min_dist = min(dist, min_dist)
  print(ans)

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)]
check=[[int(i) for  i in input().split()] for i in range(M)]
for hito in ab:
    curmin=10**8
    goto=0
    for j in range(M):
        if abs(check[j][1]-hito[1])+abs(check[j][0]-hito[0])<curmin:
            curmin=abs(check[j][1]-hito[1])+abs(check[j][0]-hito[0])
            goto=j+1
    print(goto)

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)]
check=[[int(i) for  i in input().split()] for i in range(M)]
for hito in ab:
    curmin=10**8
    goto=0
    for j in range(M):
        dist=abs(check[j][1]-hito[1])+abs(check[j][0]-hito[0])
        if dist<curmin:
            curmin=dist
            goto=j+1
    print(goto)

Submission status: Wrong Answer

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

print(St)
for i in range(N):
    memo = []
    for j in range(M):
        diff = abs(int(St[i][0]) - int(Ch[j][0])) + abs(int(St[i][1]) - int(Ch[j][1]))
        memo.append(diff)
    print(memo.index(min(memo)) + 1)

Submission status: Wrong Answer

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

for i in range(N):
    memo = []
    for j in range(M):
        diff = abs(int(St[i][0]) - int(Ch[j][0])) + abs(int(St[i][1]) - int(Ch[j][1]))
        memo.append(diff)
    print(memo.index(min(memo)))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
student=[]
man=[]
for i in range(n):
  x,y=map(int,input().split())
  student.append([x,y])
for i in range(m):
  x,y=map(int,input().split())
  man.append([x,y])
for i in student:
  ans=[]
  for j in man:
    ans.append(abs(i[0]-j[0])+abs(i[1]-j[1]))
  print(ans.index(max(ans))+1)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
student=[]
man=[]
for i in range(n):
  x,y=map(int,input().split())
  student.append([x,y])
for i in range(m):
  x,y=map(int,input().split())
  man.append([x,y])
for i in student:
  ans=[]
  for j in man:
    ans.append(abs(i[0]-j[0])+abs(i[1]-j[1]))
  print(ans.index(max(ans)))

Submission status: Wrong Answer

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

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

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

mini = [2*10**8]*n
index = [0]*n

for i in range(n):
    for j in range(m):
        dist = abs(stu[i][0]-check[j][0]) + abs(stu[i][1]-check[j][1])
        if dist < mini[i]:
            mini[i] = dist
            index[i] = j+1
    
    
            
for i in index:
    print(i)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
l1=[]
l2=[]
for i in range(n):
  l1.append(list(map(int,input().split())))
for i in range(m):
  l2.append(list(map(int,input().split())))
for i in range(n):
  l=abs(l1[i][0]-l2[0][0])+abs(l1[i][1]-l2[0][1])
  n=0
  for j in range(1,m):
    if l>abs(l1[i][0]-l2[j][0])+abs(l1[i][1]-l2[j][1]):
      l=abs(l1[i][0]-l2[j][0])+abs(l1[i][1]-l2[j][1])
      n=j
    else:
      pass
  print(n)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
l1=[]
l2=[]
for i in range(n):
  l1.append(list(map(int,input().split())))
for i in range(m):
  l2.append(list(map(int,input().split())))
for i in range(n):
  l=abs(l1[i][0]-l2[0][0])+abs(l1[i][1]-l2[0][1])
  for j in range(1,m):
    if l>abs(l1[i][0]-l2[j][0])+abs(l1[i][1]-l2[j][1]):
      l=abs(l1[i][0]-l2[j][0])+abs(l1[i][1]-l2[j][1])
    else:
      pass
  print(l)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
a_b=[list(map(int,input().split())) for _ in range(n)]
c_d=sorted([list(map(int,input().split())) for _ in range(m)])
for i in range(n):
  res=1
  d=abs(a_b[i][0]-c_d[0][0])+abs(a_b[i][1]-c_d[0][1])
  for j in range(m):
    t=abs(a_b[i][0]-c_d[j][0])+abs(a_b[i][1]-c_d[j][1])
    if t<d:
      d=t
      res=j+1
  print(res)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
a,b = [[] for i in range(n)],[[] for i in range(n)]
c,d = [[] for i in range(m)],[[] for i in range(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())

check = [[] for i in range(m)]
for i in range(n):
    for j in range(m):
        check[j] = abs(a[i]-c[j])+abs(b[i]-d[j])
    print(check.index(min(check)))

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
a,b = [[] for i in range(n)],[[] for i in range(n)]
c,d = [[] for i in range(m)],[[] for i in range(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())

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

Submission status: Wrong Answer

Solution code:
a,b = map(int, input().split())
x = []
m =19999999999999
for i in range(a):
    ta , tb = map(int, input().split()) 
    x.append([ta,tb])
for i in range(b):
    ta , tb = map(int, input().split()) 
    for s,y in x:
        m = min(m,abs(s-ta)+abs(y-tb))
    print(m)

Submission status: Wrong Answer

Solution code:
n,m=[int(i) for i in input().split()]
ab=[]
cd=[]
for i in range(n):
    a,b=[int(i) for i in input().split()]
    ab.append((a,b))
for i in range(m):
    c,d=[int(i) for i in input().split()]
    cd.append((c,d))
for i in range(n):
    mini=10000000
    point=0
    for j in range(m):
        dis=abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
        if mini>dis:
            mini=dis
            point=j+1
    print(point)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
N, M = map(int, input().split())
st = [list(map(int, input().split())) for _ in range(N)]
ch = [list(map(int, input().split())) for _ in range(M)]
for i, j in st:
    min = 10 ** 8
    min_num = 0
    for num, xy in enumerate(ch):
        if abs(i - xy[0]) + abs(j - xy[1]) < min:
            min = abs(i - xy[0]) + abs(j - xy[1])
            min_num = num + 1
    print(min_num)

Submission status: Wrong Answer

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

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

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

for a, b in AB:
    dist = 10 ** 12
    for i, cd in enumerate(CD):
        tmp = abs(a - cd[0]) + abs(b - cd[1])
        if tmp < dist:
            dist = tmp
            ans = i + 1
            
print(ans)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
h=[]
p=[]
def man(a,c,b,d):
    s=abs(a-c)+abs(b-d)
    return s
for i in range(n):
    h.append(list(map(int,input().split())))
for j in range(m):
    p.append(list(map(int,input().split())))
for k in range(n):
    l=float("inf")
    for v in range(m):
        x=man(h[k][0],p[v][0],h[k][1],p[v][1])
        if x<l:
            l=x
            m=v+1
    print(m)