Problem p02764 (python)

Fixed submission:
import sys
from itertools import combinations
from math import sqrt

read = sys.stdin.read
readline = sys.stdin.readline


def main():
    N, K, *xyc = map(int, read().split())
    x = xyc[::3]
    y = xyc[1::3]
    xy = list(zip(x, y))
    c = xyc[2::3]
    left = 0
    right = 10 ** 6
    delta = 0.1 ** 7
    while right - left > delta:
        mid = (left + right) / 2
        intersections = []
        r = [(mid / i) ** 2 for i in c]
        for i, j in combinations(range(N), 2):
            x1, y1 = xy[i]
            x2, y2 = xy[j]
            X = x2 - x1
            Y = y2 - y1
            XY = X ** 2 + Y ** 2
            r1 = r[i]
            r2 = r[j]

            a = (XY + r1 - r2) / 2
            b = XY * r1 - a ** 2
            if b < delta:
                continue
            b = sqrt(b)
            xi1 = (a * X + Y * b) / XY + x1
            yi1 = (a * Y - X * b) / XY + y1
            xi2 = (a * X - Y * b) / XY + x1
            yi2 = (a * Y + X * b) / XY + y1
            intersections.append((xi1, yi1))
            intersections.append((xi2, yi2))

        intersections.extend(xy)
        cnt = 0
        for X, Y in intersections:
            tmp = 0
            for (i, j), k in zip(xy, r):
                XY = (X - i) ** 2 + (Y - j) ** 2
                if XY < k + delta:
                    tmp += 1
            cnt = max(tmp, cnt)
            if cnt >= K:
                break
        if cnt >= K:
            right = mid
        else:
            left = mid

    print(right)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
from itertools import combinations
from math import sqrt
import numpy as np

read = sys.stdin.read
readline = sys.stdin.readline


def main():
    N, K, *xyc = map(int, read().split())
    x = xyc[::3]
    y = xyc[1::3]
    xy = list(zip(x, y))
    c = xyc[2::3]
    left = 0
    right = 10 ** 6
    delta = 0.1 ** 7
    while right - left > delta:
        mid = (left + right) / 2
        intersections = []
        r = [(mid / i) ** 2 for i in c]
        for i, j in combinations(range(N), 2):
            x1, y1 = xy[i]
            x2, y2 = xy[j]
            X = x2 - x1
            Y = y2 - y1
            XY = X ** 2 + Y ** 2
            r1 = r[i]
            r2 = r[j]

            a = (XY + r1 - r2) / 2
            b = XY * r1 - a ** 2
            if b < delta:
                continue
            b = sqrt(b)
            xi1 = (a * X + Y * b) / XY + x1
            yi1 = (a * Y - X * b) / XY + y1
            xi2 = (a * X - Y * b) / XY + x1
            yi2 = (a * Y + X * b) / XY + y1
            intersections.append((xi1, yi1))
            intersections.append((xi2, yi2))

        intersections.extend(xy)
        intersections = np.array(intersections, np.float)
        cnt = np.zeros(len(intersections), np.int64)

        for (i, j), k in zip(xy, r):
            XY = (intersections[:, 0] - i) ** 2 + (intersections[:, 1] - j) ** 2
            cnt[XY < k + delta] += 1

        if np.any(cnt >= K):
            right = mid
        else:
            left = mid

    print(right)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np

read = sys.stdin.read
readline = sys.stdin.readline

N, K, *xyc = map(int, read().split())
x = np.array(xyc[::3], np.float)
y = np.array(xyc[1::3], np.float)
c = np.array(xyc[2::3], np.float)

left = x.min()
right = x.max()


def y_solve(X):
    left_y = -1000
    right_y = 1000

    x_tmp = x - X
    while right_y - left_y > 0.1 ** 7:
        mid1 = (right_y + left_y * 2) / 3
        mid2 = (right_y * 2 + left_y) / 3
        t1 = np.hypot(x_tmp, y - mid1) * c
        t1.sort()
        t2 = np.hypot(x_tmp, y - mid2) * c
        t2.sort()
        time1 = t1[K - 1]
        time2 = t2[K - 1]
        if time1 < time2:
            right_y = mid2
        else:
            left_y = mid1
    return left_y


while right - left > 0.1 ** 7:
    mid1 = (right + left * 2) / 3
    mid2 = (right * 2 + left) / 3

    y_tmp1 = y_solve(mid1)
    t1 = np.hypot(x - mid1, y - y_tmp1) * c
    t1.sort()
    y_tmp2 = y_solve(mid2)
    t2 = np.hypot(x - mid2, y - y_tmp2) * c
    t2.sort()
    time1 = t1[K - 1]
    time2 = t2[K - 1]
    if time1 < time2:
        right = mid2
    else:
        left = mid1

x -= left
y -= y_tmp1

answer = np.hypot(x, y) * c
answer.sort()
print(answer[K - 1])