Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
# %%
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import itertools
from math import acos, cos, sin

# %%
N, K = map(int, readline().split())
m = map(int, read().split())
XYC = zip(m, m, m)
X, Y, C = zip(*XYC)
Z = [complex(x, y) for x, y in zip(X, Y)]


# %%
def cross_pts(x1, r1, x2, r2):
    D = abs(x1 - x2)
    if r1 + r2 <= D:
        return
    if abs(r1 - r2) >= D:
        return
    theta = acos((r1 * r1 + D * D - r2 * r2) / (2 * r1 * D))
    z = complex(cos(theta), sin(theta)) * r1 / D
    yield x1 + (x2 - x1) * z
    yield x1 + (x2 - x1) * z.conjugate()


# %%
def test(cost):
    R = [cost / c for c in C]

    def gen_y():
        for i in range(N):
            yield Y[i] - R[i]
            yield Y[i] + R[i]
        for i, j in itertools.combinations(range(N), 2):
            for x in cross_pts(Z[i], R[i], Z[j], R[j]):
                yield x.imag
    ys = sorted(gen_y())
    for y1, y2 in zip(ys, ys[1:]):
        y = (y1 + y2) / 2
        event = []
        for i in range(N):
            if R[i] < abs(Y[i] - y):
                continue
            dx = (R[i] ** 2 - (Y[i] - y) ** 2) ** .5
            event.append((X[i] - dx, 1))
            event.append((X[i] + dx, -1))
        event.sort()
        n = 0
        best_n = 0
        for _, dn in event:
            n += dn
            if n > best_n:
                best_n = n
        if best_n >= K:
            return True
    return False


# %%
left = 0
right = 150000
for _ in range(50):
    x = (left + right) / 2
    if test(x):
        right = x
    else:
        left = x
print(right)


Fixed submission:
import sys
from cmath import rect
import numpy as np
import numba
from numba import njit
i8 = numba.int64

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

eps = 1e-9

@njit((numba.complex128, numba.float64) * 2, cache=True)
def cross_circles(c1, r1, c2, r2):
    d = abs(c1 - c2)
    if d <= abs(r1 - r2) or r1 + r2 <= d:
        return None
    cos_theta = (r1 * r1 + d * d - r2 * r2) / (2 * r1 * d)
    theta = np.arccos(cos_theta)
    z1 = (c2 - c1) * rect(r1 / d, theta)
    z2 = (c2 - c1) * rect(r1 / d, -theta)
    return (c1 + z1, c1 + z2)

@njit
def test(Z, C, t):
    R = t / C
    cand = list(Z)
    for j in range(len(Z)):
        for i in range(j):
            points = cross_circles(Z[i], R[i], Z[j], R[j])
            if points is not None:
                for p in points:
                    cand.append(p)
    cand = np.array(cand)
    cnt = np.zeros(len(cand), np.int64)
    for i in range(len(Z)):
        cnt += np.abs(cand - Z[i]) <= R[i] + eps
    return np.any(cnt >= K)

N, K = map(int, readline().split())
nums = np.array(read().split(), np.float64)

Z = nums[::3] + 1j * nums[1::3]
C = nums[2::3]

l = 0
r = 10**9
for _ in range(100):
    m = (l + r) / 2
    if test(Z, C, m):
        r = m
    else:
        l = m

print(r)

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
# %%
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import itertools
from math import acos, cos, sin

# %%
N, K = map(int, readline().split())
m = map(int, read().split())
XYC = zip(m, m, m)
X, Y, C = zip(*XYC)
X = [complex(x, y) for x, y in zip(X, Y)]


# %%
def cross_pts(x1, r1, x2, r2):
    D = abs(x1 - x2)
    if r1 + r2 <= D:
        return
    if abs(r1 - r2) >= D:
        return
    theta = acos((r1 * r1 + D * D - r2 * r2) / (2 * r1 * D))
    z = complex(cos(theta), sin(theta)) * r1 / D
    yield x1 + (x2 - x1) * z
    yield x1 + (x2 - x1) * z.conjugate()


# %%
def test(cost):
    R = [cost / c for c in C]

    def gen_y():
        for i in range(N):
            yield X[i].imag - R[i]
            yield X[i].imag + R[i]
        for i, j in itertools.combinations(range(N), 2):
            for x in cross_pts(X[i], R[i], X[j], R[j]):
                yield x.imag
    Y = sorted(gen_y())
    for y1, y2 in zip(Y, Y[1:]):
        y = (y1 + y2) / 2
        event = []
        for i in range(N):
            if R[i] < abs(X[i].imag - y):
                continue
            dx = (R[i] ** 2 - (X[i].imag - y) ** 2) ** .5
            event.append((X[i].real - dx, 1))
            event.append((X[i].real + dx, -1))
        event.sort()
        n = 0
        best_n = 0
        for _, dn in event:
            n += dn
            if n > best_n:
                best_n = n
        if best_n >= K:
            return True
    return False


# %%
left = 0
right = 150000
for _ in range(50):
    x = (left + right) / 2
    if test(x):
        right = x
    else:
        left = x
print(right)


Fixed submission:
import sys
from cmath import rect
import numpy as np
import numba
from numba import njit
i8 = numba.int64

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

eps = 1e-9

@njit((numba.complex128, numba.float64) * 2, cache=True)
def cross_circles(c1, r1, c2, r2):
    d = abs(c1 - c2)
    if d <= abs(r1 - r2) or r1 + r2 <= d:
        return None
    cos_theta = (r1 * r1 + d * d - r2 * r2) / (2 * r1 * d)
    theta = np.arccos(cos_theta)
    z1 = (c2 - c1) * rect(r1 / d, theta)
    z2 = (c2 - c1) * rect(r1 / d, -theta)
    return (c1 + z1, c1 + z2)

@njit
def test(Z, C, t):
    R = t / C
    cand = list(Z)
    for j in range(len(Z)):
        for i in range(j):
            points = cross_circles(Z[i], R[i], Z[j], R[j])
            if points is not None:
                for p in points:
                    cand.append(p)
    cand = np.array(cand)
    cnt = np.zeros(len(cand), np.int64)
    for i in range(len(Z)):
        cnt += np.abs(cand - Z[i]) <= R[i] + eps
    return np.any(cnt >= K)

N, K = map(int, readline().split())
nums = np.array(read().split(), np.float64)

Z = nums[::3] + 1j * nums[1::3]
C = nums[2::3]

l = 0
r = 10**9
for _ in range(100):
    m = (l + r) / 2
    if test(Z, C, m):
        r = m
    else:
        l = m

print(r)

Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
# %%
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import itertools
from math import acos, cos, sin

# %%
N, K = map(int, readline().split())
m = map(int, read().split())
XYC = zip(m, m, m)
X, Y, C = zip(*XYC)
X = [complex(x, y) for x, y in zip(X, Y)]


# %%
def cross_pts(x1, r1, x2, r2):
    D = abs(x1 - x2)
    if r1 + r2 <= D:
        return
    if abs(r1 - r2) >= D:
        return
    theta = acos((r1 * r1 + D * D - r2 * r2) / (2 * r1 * D))
    z = complex(cos(theta), sin(theta)) * r1 / D
    yield x1 + (x2 - x1) * z
    yield x1 + (x2 - x1) * z.conjugate()


# %%
def test(cost):
    R = [cost / c for c in C]

    def gen_y():
        for i in range(N):
            yield X[i].imag - R[i]
            yield X[i].imag + R[i]
        for i, j in itertools.combinations(range(N), 2):
            for x in cross_pts(X[i], R[i], X[j], R[j]):
                yield x.imag
    Y = sorted(gen_y())
    for y1, y2 in zip(Y, Y[1:]):
        y = (y1 + y2) / 2
        event = []
        for i in range(N):
            if R[i] < abs(X[i].imag - y):
                continue
            dx = (R[i] ** 2 - (X[i].imag - y) ** 2) ** .5
            event.append((X[i].real - dx, 1))
            event.append((X[i].real + dx, -1))
        event.sort()
        n = 0
        best_n = 0
        for _, dn in event:
            n += dn
            if n > best_n:
                best_n = n
        if best_n >= K:
            return True
    return False


# %%
left = 0
right = 10 ** 7
for _ in range(100):
    x = (left + right) / 2
    if test(x):
        right = x
    else:
        left = x
print(right)


Fixed submission:
import sys
from cmath import rect
import numpy as np
import numba
from numba import njit
i8 = numba.int64

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

eps = 1e-9

@njit((numba.complex128, numba.float64) * 2, cache=True)
def cross_circles(c1, r1, c2, r2):
    d = abs(c1 - c2)
    if d <= abs(r1 - r2) or r1 + r2 <= d:
        return None
    cos_theta = (r1 * r1 + d * d - r2 * r2) / (2 * r1 * d)
    theta = np.arccos(cos_theta)
    z1 = (c2 - c1) * rect(r1 / d, theta)
    z2 = (c2 - c1) * rect(r1 / d, -theta)
    return (c1 + z1, c1 + z2)

@njit
def test(Z, C, t):
    R = t / C
    cand = list(Z)
    for j in range(len(Z)):
        for i in range(j):
            points = cross_circles(Z[i], R[i], Z[j], R[j])
            if points is not None:
                for p in points:
                    cand.append(p)
    cand = np.array(cand)
    cnt = np.zeros(len(cand), np.int64)
    for i in range(len(Z)):
        cnt += np.abs(cand - Z[i]) <= R[i] + eps
    return np.any(cnt >= K)

N, K = map(int, readline().split())
nums = np.array(read().split(), np.float64)

Z = nums[::3] + 1j * nums[1::3]
C = nums[2::3]

l = 0
r = 10**9
for _ in range(100):
    m = (l + r) / 2
    if test(Z, C, m):
        r = m
    else:
        l = m

print(r)

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
# %%
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


# %%
import numpy as np
from scipy.optimize import fmin


# %%
N, K = map(int, readline().split())
XYZ = np.array(read().split(), np.int64)
X = XYZ[::3]
Y = XYZ[1::3]
Z = XYZ[2::3]

# %%


def f(pt):
    x, y = pt
    cost = Z * ((x - X) ** 2 + (y - Y) ** 2) ** .5
    cost.sort()
    return cost[K - 1]


def calc(x0):
    opt_pt = fmin(f, x0, disp=False, ftol=1e-7)
    return f(opt_pt)


# %%
answer = 10 ** 18
for x, y, z in zip(X, Y, Z):
    f_value = calc([x, y])
    if answer > f_value:
        answer = f_value
    for n in np.random.randint(0, N, 2):
        x1, y1, z1 = X[n], Y[n], Z[n]
        f_value = calc([(x * z1 + x1 * z) / (z + z1), (y * z1 + y1 * z) / (z + z1)])
        if answer > f_value:
            answer = f_value

# %%
print(answer)


# %%


Fixed submission:
import sys
from cmath import rect
import numpy as np
import numba
from numba import njit
i8 = numba.int64

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

eps = 1e-9

@njit((numba.complex128, numba.float64) * 2, cache=True)
def cross_circles(c1, r1, c2, r2):
    d = abs(c1 - c2)
    if d <= abs(r1 - r2) or r1 + r2 <= d:
        return None
    cos_theta = (r1 * r1 + d * d - r2 * r2) / (2 * r1 * d)
    theta = np.arccos(cos_theta)
    z1 = (c2 - c1) * rect(r1 / d, theta)
    z2 = (c2 - c1) * rect(r1 / d, -theta)
    return (c1 + z1, c1 + z2)

@njit
def test(Z, C, t):
    R = t / C
    cand = list(Z)
    for j in range(len(Z)):
        for i in range(j):
            points = cross_circles(Z[i], R[i], Z[j], R[j])
            if points is not None:
                for p in points:
                    cand.append(p)
    cand = np.array(cand)
    cnt = np.zeros(len(cand), np.int64)
    for i in range(len(Z)):
        cnt += np.abs(cand - Z[i]) <= R[i] + eps
    return np.any(cnt >= K)

N, K = map(int, readline().split())
nums = np.array(read().split(), np.float64)

Z = nums[::3] + 1j * nums[1::3]
C = nums[2::3]

l = 0
r = 10**9
for _ in range(100):
    m = (l + r) / 2
    if test(Z, C, m):
        r = m
    else:
        l = m

print(r)

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
# %%
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


# %%
import numpy as np
from scipy.optimize import fmin


# %%
N, K = map(int, readline().split())
XYZ = np.array(read().split(), np.int64)
X = XYZ[::3]
Y = XYZ[1::3]
Z = XYZ[2::3]

# %%


def f(pt):
    x, y = pt
    cost = Z * ((x - X) ** 2 + (y - Y) ** 2) ** .5
    cost.sort()
    return cost[K - 1]


def calc(x0):
    opt_pt = fmin(f, x0, disp=False, ftol=1e-7)
    return f(opt_pt)


# %%
answer = 10 ** 18
for x, y, z in zip(X, Y, Z):
    f_value = calc([x, y])
    if answer > f_value:
        answer = f_value
    for n in np.random.randint(0, N, 3):
        x1, y1, z1 = X[n], Y[n], Z[n]
        f_value = calc([(x * z1 + x1 * z) / (z + z1), (y * z1 + y1 * z) / (z + z1)])
        if answer > f_value:
            answer = f_value

# %%
print(answer)


# %%


Fixed submission:
import sys
from cmath import rect
import numpy as np
import numba
from numba import njit
i8 = numba.int64

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

eps = 1e-9

@njit((numba.complex128, numba.float64) * 2, cache=True)
def cross_circles(c1, r1, c2, r2):
    d = abs(c1 - c2)
    if d <= abs(r1 - r2) or r1 + r2 <= d:
        return None
    cos_theta = (r1 * r1 + d * d - r2 * r2) / (2 * r1 * d)
    theta = np.arccos(cos_theta)
    z1 = (c2 - c1) * rect(r1 / d, theta)
    z2 = (c2 - c1) * rect(r1 / d, -theta)
    return (c1 + z1, c1 + z2)

@njit
def test(Z, C, t):
    R = t / C
    cand = list(Z)
    for j in range(len(Z)):
        for i in range(j):
            points = cross_circles(Z[i], R[i], Z[j], R[j])
            if points is not None:
                for p in points:
                    cand.append(p)
    cand = np.array(cand)
    cnt = np.zeros(len(cand), np.int64)
    for i in range(len(Z)):
        cnt += np.abs(cand - Z[i]) <= R[i] + eps
    return np.any(cnt >= K)

N, K = map(int, readline().split())
nums = np.array(read().split(), np.float64)

Z = nums[::3] + 1j * nums[1::3]
C = nums[2::3]

l = 0
r = 10**9
for _ in range(100):
    m = (l + r) / 2
    if test(Z, C, m):
        r = m
    else:
        l = m

print(r)