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())
stu=[]
far=[]
for i in range(n):
    a,b=map(int,input().split())
    stu.append([a,b])
for i in range(m):
    c,d=map(int,input().split())
    far=[]
    ans=0
    for j in range(n):
        far.append(abs(stu[j][0]-c)+abs(stu[j][1]-d))
    print(far.index(min(far))+1)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
man = [[int(x) for x in input().split()] for _ in range(N)]
check = [[int(x) for x in input().split()] for _ in range(M)]

for a, b in man:
    tmp = 1000000000
    ans = 1
    for i, (c, d) in enumerate(check):
        if tmp > (abs(a-c) + abs(b-d)):
            tmp = min(tmp, abs(a-c) + abs(b-d))
    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)]

for i in range(N):
    check = 10**5
    index = 0
    for j in range(M):
        if abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1]) < check:
            index = j+1
            check = min(abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1]), check)
    print(index)

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 range(N):
    check = 10**5
    ans = 51
    for j in range(M):
        if abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1]) < check:
            ans = j+1
            check = min(abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1]), check)
    print(ans)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
Ls = []
Lp = []
for i in range(N):
    a,b = map(int,input().split())
    Ls.append([a,b])
for m in range(M):
    c,d = map(int,input().split())
    Lp.append([c,d])
dis =[]
for i in range(N):
    for m in range(M):
        dis.append(abs(Ls[i][0]-Lp[m][0])+abs(Ls[i][1]-Lp[m][1]))
    print(dis.index(min(dis))+1)

Submission status: Wrong Answer

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 a:
    mn = 10 ** 8
    record = 0
    for j, v in enumerate(c):
        temp = abs(i[0] - v[0]) + abs(i[1] - v[1])
        if temp < mn:
            mn = temp
            record = j + 1
    print(record)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split(" "))
students = [tuple(map(int,input().split(" "))) for _ in range(N)]
checkpoints = [tuple(map(int,input().split(" "))) for _ in range(M)]
Ans = [(0,100)]*N

# print(students)
# print(checkpoints)

i = 0
for n in students:
    j=1
    for m in checkpoints:
        dist = abs(n[0]-m[0])+abs(n[1]-m[1])
        if dist<Ans[i][1]:
            Ans[i] = (j,dist)
        j+=1
        
    i+=1
    
# print(Ans)

for ans in Ans:
    print(ans[0])

Submission status: Wrong Answer

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

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

cs = []
for m in range(M):
  cs.append(list(map(int, input().split())))
  
for n in range(N):
  min_d = 100000
  min_i = -1
  for m in range(M):
    d = abs(st[n][0]-cs[m][0]) + abs(st[n][1]-cs[m][1])
    if d < min_d:
      min_d = d
      min_i = m
  print(min_i+1)

Submission status: Wrong Answer

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

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 = [list(map(int, input().split())) for _ in range(M)]

for i in range(N):
    ans = 0
    a = a_b[i][0]
    b = a_b[i][1]

    c_ans = c_d[ans][0]
    d_ans = c_d[ans][1]

    for j in range(M):
        c = c_d[j][0]
        d = c_d[j][1]
        
        if abs(a-c) + abs(b-d) < abs(a-c_ans) + abs(b-d_ans):
             ans = j
        elif abs(a-c) + abs(b-d) == abs(a-c_ans) + abs(b-d_ans):
            ans = j if j<ans else ans
    print(ans+1)

Submission status: Wrong Answer

Solution code:
def manhattan(u, v):
  return abs(u[0]-v[0])+abs(u[1]-v[1])

N, M = map(int, input().split())
ns = [list(map(int, input().split())) for _ in range(N)]
ms = [list(map(int, input().split())) for _ in range(M)]

for n in ns:
  dmin = 200000005
  num = -1
  for i, m in enumerate(ms):
    d = manhattan(n, m)
    if d < dmin:
      dmin = d
      num = i
  print(num+1)

Submission status: Wrong Answer

Solution code:
def manhattan(u, v):
  return abs(u[0]-v[0])+abs(u[1]-v[1])

N, M = map(int, input().split())
ns = [list(map(int, input().split())) for _ in range(N)]
ms = [list(map(int, input().split())) for _ in range(M)]

for n in ns:
  dmin = 100000005
  num = -1
  for i, m in enumerate(ms):
    d = manhattan(n, m)
    if d < dmin:
      dmin = d
      num = i
  print(num+1)

Submission status: Wrong Answer

Solution code:
#abc064 b
n,m=map(int,input().split())
student=[]
checkpoint=[]
for i in range(n):
    x=list(map(int,input().split()))
    student.append(x)
for i in range(m):
    x=list(map(int,input().split()))
    checkpoint.append(x)

for p in student:
    distance=100100100
    i=1
    ans=0
    for c in checkpoint:
        d=abs(p[0]-c[0])+abs(p[1]-c[1])
        if distance>d:
            distance=d
            ans=i
        i+=1
    print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import sys
from io import StringIO
import unittest

doTest=1

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline
    n,m=list(map(int, readline().strip().split()))
    a=[0]*n
    b=[0]*n
    c=[0]*m
    d=[0]*m

    for i in range(n):
        a[i],b[i]=list(map(int, readline().strip().split()))
    for i in range(m):
        c[i],d[i]=list(map(int, readline().strip().split()))

    for i in range(n):
        minDiff=999999999
        minpnt=9999999
        for j in range(m):
            diff=abs(a[i]-c[j])+abs(b[i]-d[j])
            if diff < minDiff:
                minDiff = diff
                minpnt=j
        print(minpnt+1)
    return

if doTest==0:
    resolve()
    sys.exit()

### ----------------
### ここまでコピぺえ 
### ----------------

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
now=[tuple(map(int,input().split())) for i in range(n)]
p=[tuple(map(int,input().split())) for i in range(m)]
for a in now:
  ans=10**10
  for c in p:
    ans=min(ans,abs(c[0]-a[0])+abs(c[1]-a[1]))
  print(ans)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
p=[tuple(map(int,input().split())) for i in range(n)]
for i in range(m):
  c,d=map(int,input().split())
  ans=10**10
  for j,k in p:
    ans=min(ans,abs(c-j)+abs(d-k))
  print(ans)

Submission status: Wrong Answer

Solution code:
[n,m]=list(map(int,input().split()))
ab=[]
for i in range(n):
    ab.append(list(map(int,input().split())))
cd=[]
for i in range(m):
    cd.append(list(map(int,input().split())))
ans=[]
for i in range(n):
    kyorimin=10**9
    for j in range(m):
        kyori=abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
        if kyorimin>kyori:
            goal=j+1
    ans.append(goal)
for i in range(len(ans)):
    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)]
for i in range(n):
  mn=100000000
  ans=0
  for j in range(m):
    d=abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
    if d<mn:
      mn=d
      ans=j+1
  print(ans)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
a=[[int(i) for i in input().split()] for l in range(n)]
b=[[int(i) for i in input().split()] for l in range(m)]
for A in a:
    c=1
    r=0
    m=100000000
    for B in b:
        k=abs(A[0]-B[0])+abs(A[1]-B[1])
        if m>k:
            m=k
            r=c
        c+=1
    print(r)

Submission status: Wrong Answer

Solution code:
import numpy as np
N, M = map(int, input().split(' '))

Ns = [list(map(int, input().split())) for i in range(N)]
Ms = [list(map(int, input().split())) for i in range(M)]
print(Ms)
for a, b in Ns:
	dists = []
	for c, d in Ms:
		dists.append(abs(a - c) + abs(b - d))
	print(np.argmin(dists) + 1)

Submission status: Wrong Answer

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

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

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

ansl = [0 for _ in range(n)]
for i, ab in enumerate(abl):
    ans = 10**8
    for j, cd in enumerate(cdl):
        if abs(ab[0]-cd[0]) + abs(ab[1]-cd[1]) < ans:
            ansl[i] = j
            ans = abs(ab[0]-cd[0]) + abs(ab[1]-cd[1])

for ans in ansl:
    print(ans+1)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
list_student = []
list_ckeckpoint = []
for x in range(n):
    a, b = map(int, input().split())
    list_student.append([a, b])
for y in range(m):
    c, d = map(int, input().split())
    list_ckeckpoint.append([c, d])
    
def distance(lista, listb):
    return abs(lista[0] - listb[0]) + abs(lista[1] - listb[1])

for no in range(n):
    minValue = 10**8
    minid = 1
    for id in range(m):
        dis = distance(list_student[no], list_ckeckpoint[id])
        if minValue > dis: minid = id + 1
        minValue = min([minValue, dis])
    print(minid)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
list_student = []
list_ckeckpoint = []
for x in range(n):
    a, b = map(int, input().split())
    list_student.append([a, b])
for y in range(m):
    c, d = map(int, input().split())
    list_ckeckpoint.append([c, d])
    
def distance(lista, listb):
    return abs(lista[0] - listb[0]) + abs(lista[1] - listb[1])

for no in range(n):
    minValue = 10**8
    minid = 0
    for id in range(m):
        dis = distance(list_student[no], list_ckeckpoint[id])
        if minValue > dis: minid = id + 1
        minValue = min([minValue, dis])
    print(minid)

Submission status: Wrong Answer

Solution code:
def ac(n,m,a,c):
    ans = []
    for i in range(n):
        min = 100000000
        bang = 0
        for w in range(m):
            if abs(a[i][0] - c[w][0]) + abs(a[i][1] - c[w][1]) < min:
                min = abs(a[i][0] - c[w][0]) + abs(a[i][1] - c[w][1])
                bang = w + 1
        ans.append(bang)
    return ans

def main():
    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)]
    ans = ac(n , m , a , c)
    for i in range(len(ans)):
        print(ans[i])

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def ac(n,m,a,c):
    ans = []
    for i in range(n):
        min = 100000000
        bang = 0
        for w in range(m):
            if abs(a[i][0] - c[w][0]) + abs(a[i][1] - c[w][1]) < min:
                min = (a[i][0] - c[w][0]) + (a[i][1] - c[w][1])
                bang = w + 1
        ans.append(bang)
    return ans

def main():
    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)]
    ans = ac(n , m , a , c)
    for i in range(len(ans)):
        print(ans[i])

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
gakusei = []
for i in range(N):
    a,b = map(int,input().split())
    gakusei.append((a,b))
check = []
for i in range(1,M+1):
    c,d = map(int,input().split())
    check.append((c,d))
for i in range(N):
    a,b = gakusei[i]
    z = 10**9
    m = 0
    for j in range(1,M+1):
        c,d = check[j-1]
        x = max(a-c,c-a) + max(b-d,d-b)
        if x < z:
            m = j
            z = x
    print(z)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
x = []
y = []
for _ in range(n):
    a,b = map(int,input().split())
    x.append([a,b])
for _ in range(m):
    c,d = map(int,input().split())
    y.append([c,d])
for i in range(n):
    t = 10**8*2
    ans = 0
    for j in range(m):
        if t > abs(y[j][0]-x[i][0])+abs(y[j][1]-x[i][1]):
            ans = j+1
            t = abs(y[j][0]-x[i][0])+abs(y[j][1]-x[i][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)]
chkpoints = [list(map(int, input().split())) for _ in range(m)]
dist = 0
ans = 0
for student in students:
  min_dist = 100000000
  for i in range(m):
    dist = abs(student[0]-chkpoints[i][0])+abs(student[1]-chkpoints[i][1])
    if dist < min_dist:
      min_dist = dist
      ans = i+1
  print(ans)

Submission status: Wrong Answer

Solution code:
# N人
# M個のチェックポイント
N, M = map(int, input().split())

student = []
for _ in range(N):
    student.append(list(map(int, input().split())))
    
cp = []
for _ in range(M):
    cp.append(list(map(int, input().split())))
    
goal = [10000000 for _ in range(N)]
ans = [0 for _ in range(N)]
for n in range(N):
    for m in range(M):
        x = abs(student[n][0] - cp[m][0])
        y = abs(student[n][1] - cp[m][1])
        #print(student[n], cp[m])
        #print("abs(x-y)", x, y, x+y)
        if goal[n] > x+y:
            goal[n] = x+y
            ans[n] = m +1
            #print(goal[n], ans[n])


for n in range(N):
    print(ans[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)]

result = []
for a, b in ab:
    tmp = []
    for c, d in cd:
        tmp.append(abs(a-c) + abs(c-d))
    result.append(tmp.index(min(tmp)) +1)
for ans in result:
    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):
    dim, num = 10*10, -1
    for j in range(m):
        if abs(a[i][0] - c[j][0]) + abs(a[i][1] - c[j][1]) < dim:
            dim = abs(a[i][0] - c[j][0]) + abs(a[i][1] - c[j][1])
            num = j
    print(num+1)

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

Submission status: Wrong Answer

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

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

for n in range(N):
    ans = []
    a, b = ab[n]
    for m in range(M):
        c, d = cd[m]
        distance = abs(a - c) + abs(b - d)
        ans.append(distance)
    print(ans.index(min(ans)))

Submission status: Wrong Answer

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

students = []
for i in range(N):
    students.append(input().split())

checkpoints = []
for i in range(M):
    checkpoints.append(input().split())

for x1, y1 in students:
    result = 10**8 * 10 **8
    index = 1
    for x2, y2 in checkpoints:
        val = abs(int(x1) - int(x2)) + abs(int(y1) - int(y2))
        if result > val:
            ans = index
        result = val
        index += 1
    print(ans)

Submission status: Wrong Answer

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

students = []
for i in range(N):
    students.append(input().split())

checkpoints = []
for i in range(M):
    checkpoints.append(input().split())

for x1, y1 in students:
    result = 999999999
    index = 1
    for x2, y2 in checkpoints:
        val = abs(int(x1) - int(x2)) + abs(int(y1) - int(y2))
        if result > val:
            ans = index
        result = val
        index += 1
    print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin

n,m = [int(x) for x in stdin.readline().rstrip().split()]
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(n)]
lc = [list(map(int,stdin.readline().rstrip().split())) for _ in range(m)]

for i in range(n):
    kyo = []
    for j in range(m):
        kyo.append(abs(li[i][0]-lc[j][0])+abs(li[i][0]-lc[j][1]))
    print(kyo.index(min(kyo))+1)

Submission status: Wrong Answer

Solution code:
def dis(XY1, XY2):
    return abs(XY1[0]-XY2[0]) + abs(XY1[1]-XY2[1])

N, M = map(int,input().split())
AB = [0 for _ in range(N)]
CD = [0 for _ in range(M)]
for i in range(N):
    a,b = map(int,input().split())
    AB[i] = [a,b]
for i in range(M):
    c,d = map(int,input().split())
    CD[i] = [c,d]

for ab in AB:
    mini = 2*(10**8)+1
    id = 0
    for cd in CD:
        if mini > dis(ab,cd):
            mini = dis(ab,cd)
            id = CD.index(cd)+1
    print(id)

Submission status: Wrong Answer

Solution code:
def dis(XY1, XY2):
    return abs(XY1[0]-XY2[0]) + abs(XY1[1]-XY2[1])

N, M = map(int,input().split())
AB = [0 for _ in range(N)]
CD = [0 for _ in range(M)]
for i in range(N):
    a,b = map(int,input().split())
    AB[i] = [a,b]
for i in range(M):
    c,d = map(int,input().split())
    CD[i] = [c,d]

for ab in AB:
    mini = 2*(10**8)
    id = 0
    for cd in CD:
        if mini > dis(ab,cd):
            mini = dis(ab,cd)
            id = CD.index(cd)+1
    print(id)

Submission status: Wrong Answer

Solution code:
# ABC 057: B – Checkpoints
n, m = [int(s) for s in input().split()]

a = []
b = []

for i in range(n):
    tmp = [int(s) for s in input().split()]
    a.append(tmp[0])
    b.append(tmp[1])

c = []
d = []

for j in range(m):
    tmp = [int(s) for s in input().split()]
    c.append(tmp[0])
    d.append(tmp[1])

for i in range(n):
    checkpoint = 0
    distance = 9999
    
    for j in range(m):
        if distance > abs(c[j] - a[i]) + abs(d[j] - b[i]):
            distance = abs(c[j] - a[i]) + abs(d[j] - b[i])
            checkpoint = j
    
    print(checkpoint + 1)

Submission status: Wrong Answer

Solution code:
a,b = map(int,input().split())
S = [list(map(int,input().split())) for i in range(a)]
CP = [list(map(int,input().split())) for i in range(b)]
for s in S:
  count = 0
  ab = 10**8
  p = 10**8
  for cp in CP:
    total = abs(s[0]-cp[0]) + abs(s[1]-cp[1])
    count +=1
    if ab > total:
      ab = total
      p = count
      
  print(p)

Submission status: Wrong Answer

Solution code:
a,b = map(int,input().split())
S = [list(map(int,input().split())) for i in range(a)]
CP = [list(map(int,input().split())) for i in range(b)]
for s in S:
  count = 0
  ab = 10**8
  p = 10**8
  for cp in CP:
    total = abs(s[0]-cp[0]) + abs(s[1]-cp[1])
    count +=1
    print(cp)
    if ab > total:
      ab = total
      p = count
      
  print(p)

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
student = dict()
checkpoint = dict()
distance = dict()

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

for i in range(m):
    checkpoint[i] = list(map(int, input().split()))
    
for key in student:
    x1,y1 = student[key]
    minD = 100000000
    minP = 100000000
    for p in checkpoint:
        x2, y2 = checkpoint[p]
        d =  abs(x1 - x2) + abs(y1 - y2)
        if d < minD:
            minP = p
            minD = d
    print(minP+1)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
s = []
for i in range(0, N):
  x, y = map(int, input().split())
  s.append([x, y])
c = []
for i in range(0, M):
  x, y = map(int, input().split())
  s.append([x, y])
  
for x,y in s:
  dist_min = 10000000000
  min_n = 0
  n = 0
  for c, d in c:
    n += 1
    dist = abs(x-c)+ abs(y-d)
    if dist_min > dist:
      dist_min = dist
      min_n = n
  print(min_n)

Submission status: Wrong Answer

Solution code:
# ABC057 B - Checkpoints
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
n,m = nm()

AB = []
CD = []
ans = 10**10
for i in range(n):
    a,b = nm()
    AB.append(a)
    AB.append(b)

for i in range(m):
    c,d = nm()
    CD.append(c)
    CD.append(d)

for i in range(n):
    for j in range(m):
        ans = min(ans,abs(AB[0]-CD[0])+abs(AB[1]-CD[1]))
    print(ans)

Submission status: Wrong Answer

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

ab = []
for i in range(n):
    temp = map(int, input().split())
    ab.append(tuple(temp))

cd = []
for j in range(m):
    temp = map(int, input().split())
    cd.append(tuple(temp))

d = [False for i in range(m)]


for i in ab:
    temp_ind = -1
    temp = 10 ** 17
    for ind, j in enumerate(cd):
        md = abs(i[0]-j[0])+abs(i[1]-j[1])
        if md < temp:
            if d[ind] == False:
                temp_ind = ind
                temp = abs(i[0]-j[0])+abs(i[1]-j[1])
    d[temp_ind] = True
    print(temp_ind+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())
c = [0] * M
d = [0] * M
for i in range(M):
    c[i], d[i] = map(int, input().split())


for i in range(N):
    distance = abs(a[0] - c[0]) + abs(b[0] - d[0])
    check_point = 1
    for j in range(M):
        temp = abs(a[i] - c[j]) + abs(b[i] - d[j])
        if distance > temp:
            distance = temp
            check_point = j + 1
    print(check_point)

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 student in students:
    nearst_index = 0
    _min = 10**8
    for point_index in range(len(checkpoints)):
        diff = abs(student[0] - checkpoints[point_index][0])+abs(student[1] - checkpoints[point_index][1])
        if diff < _min:
            _min = diff
            nearst_index = point_index+1
    print(nearst_index)

Submission status: Wrong Answer

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

for i in range(N):
  min=abs(li[0][0]-check[0][0])+abs(li[0][1]-check[0][1])
  minindex=0
  for j in range(M):
    dis=abs(li[i][0]-check[j][0])+abs(li[i][1]-check[j][1])
    if dis<min:
      min=dis
      minindex=j
  print(minindex+1)

Submission status: Wrong Answer

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

for i in range(N):
  min=100
  minindex=0
  for j in range(M):
    dis=abs(li[i][0]-check[j][0])+abs(li[i][1]-check[j][1])
    if dis<min:
      min=dis
      minindex=j
  print(minindex+1)

Submission status: Wrong Answer

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

for i in range(n):
    for j in range(m):
        num = []
        num.append(abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1]))
    else:
        mini = min(num)
        print(num.index(mini)+1)
        num = []

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

s = [0]*N
index = [0]*N
for i in range(N):
    s[i] = abs(a[0]-c[0]) + abs(b[0]-d[0])
    for j in range(M):
        if abs(a[i]-c[j]) + abs(b[i]-d[j]) < s[i]:
            s[i] = abs(a[i]-c[j]) + abs(b[i]-d[j])
            index[i] = j + 1

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
ab = [[int(x) for x in input().split()]for i in range(N)]
for i in range(M):
  c,d = map(int,input().split())
  ans = [10**9,-1]
  for j in range(N):
    if ans[0] > abs(ab[j][0]-c)+abs(ab[j][1]-d):
      ans = [abs(ab[j][0]-c)+abs(ab[j][1]-d),j+1]
  print(ans[1])

Submission status: Wrong Answer

Solution code:
# B - Checkpoints
N, M = list(map(int, input().split()))
P = [list(map(int, input().split())) for i in range(N)]
C = [list(map(int, input().split())) for i in range(M)]

ans = [1]*N
for i in range(N): # i番目の人
    D = [10 ** 10] * M
    for j in range(M): # jのチェックポイント
        D[j] = abs(P[i][0]-C[j][0]) + abs(P[i][1]-C[j][1])
        if D[j] <= min(D):
            if ans[i] >= j+1:
                pass
            else:
                ans[i] = j+1
        else:
            pass

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

Submission status: Wrong Answer

Solution code:
# B - Checkpoints
N, M = list(map(int, input().split()))
P = [list(map(int, input().split())) for i in range(N)]
C = [list(map(int, input().split())) for i in range(M)]

ans = [1]*N
for i in range(N): # i番目の人
    D = [10 ** 10] * M
    for j in range(M): # jのチェックポイント
        D[j] = abs(P[i][0]-C[j][0]) + abs(P[i][1]-C[j][1])
        if D[j] < D[j-1]:
            if ans[i] == j+1:
                pass
            else:
                ans[i] = j+1
        else:
            pass

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

Submission status: Wrong Answer

Solution code:
# B - Checkpoints
N, M = list(map(int, input().split()))
P = [list(map(int, input().split())) for i in range(N)]
C = [list(map(int, input().split())) for i in range(M)]

ans = [1]*N
for i in range(N): # i番目の人
    D = [10 ** 9] * M
    for j in range(M): # jのチェックポイント
        D[j]= abs(P[i][0]-C[j][0]) + abs(P[i][1]-C[j][1])
        if D[j] < D[j-1]:
            ans[i] = j+1
        else:
            pass

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

Submission status: Wrong Answer

Solution code:
n, m = map(int,input().split())
student_list = [list(map(int,input().split())) for _ in range(n)]
print(student_list)
check_list = [list(map(int,input().split())) for _ in range(m)]
print(check_list)
for s in student_list:
    tmp = []
    for c in check_list:
        tmp.append(abs(s[0]-c[0]) + abs(s[1]-c[1]))
    print(tmp.index(min(tmp))+1)

Submission status: Wrong Answer

Solution code:
n, m = map(int,input().split())
student_list = [list(map(int,input().split())) for _ in range(n)]
check_list = [list(map(int,input().split())) for _ in range(m)]
for s in student_list:
    tmp = []
    for c in check_list:
        tmp.append((s[0]-c[0])**2 + (s[1]-c[1])**2)
    print(tmp.index(min(tmp))+1)

Submission status: Wrong Answer

Solution code:
a, b = map(int, input().split())
c = [list(map(int, input().split()))for _ in range(a)]
d = [list(map(int, input().split()))for _ in range(b)]
e = []
for i in range(a):
    f = 10 * 9
    g = 0
    for j in range(b):
        if f > abs(c[i][0] - d[j][0]) + abs(c[i][1] - d[j][1]):
            f = abs(c[i][0] - d[j][0]) + abs(c[i][1] - d[j][1])
            g = j+1
    e.append(g)
for i in range(len(e)):
    print(e[i])

Submission status: Wrong Answer

Solution code:
a, b = map(int, input().split())
c = [list(map(int, input().split()))for _ in range(a)]
d = [list(map(int, input().split()))for _ in range(b)]
e = []

for i in range(a):
    f = 10 * 9
    g = 0
    for j in range(b):
        if f > abs(c[i][0] - d[j][0]) + abs(c[i][1] - d[j][1]):
            f = abs(c[i][0] - d[j][0]) + abs(c[i][1] - d[j][1])
            g = j
    e.append([g+1, f])
for i in range(len(e)):
    print(e[i][0])