Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations

def main():
    EPS = 1e-8

    N, K, *XYC = map(int, open(0).read().split())
    PC = [(complex(x, y), c) for x, y, c in zip(*[iter(XYC)] * 3)]


    def intersection(A, r, B, s):
        D = B - A
        d = abs(D)

        cos_t = (d * d + r * r - s * s) / (2 * d * r)
        sin_t = max(1 - cos_t * cos_t, 0.0) ** 0.5

        R = r * complex(cos_t, sin_t)
        D /= d

        return (
            A + D * R,
            A + D * R.conjugate(),
        )


    def is_ok(T):
        for (p1, c1), (p2, c2) in combinations(PC, 2):
            q1, q2 = intersection(p1, T / c1, p2, T / c2)
            if K <= sum(1 for p, c in PC if c * abs(q1 - p) < T + EPS):
                return True
            if K <= sum(1 for p, c in PC if c * abs(q2 - p) < T + EPS):
                return True

        return any(K <= sum(1 for p, c in PC if c * abs(a - p) < T + EPS) for a, _ in PC)

    ng, ok = 0, 1000000
    for _ in range(100):
        md = (ng + ok) / 2
        if is_ok(md):
            ok = md
        else:
            ng = md

    print(ok)

main()

Fixed submission:
from math import hypot
from collections import deque

N, K, *XYC = map(int, open(0).read().split())
XYC = list(zip(*[iter(XYC)] * 3))

Q = deque([(0, 0, 1000.0)])

ans = float("inf")
while Q:
    X, Y, r = Q.popleft()
    if ans * 0.9999995 > sorted(c * hypot(max(abs(X - x) - r, 0), max(abs(Y - y) - r, 0)) for x, y, c in XYC)[K - 1]:
        ans = min(ans, sorted(c * hypot(X - x, Y - y) for x, y, c in XYC)[K - 1])
        for dx, dy in [(-0.5, -0.5), (-0.5, 0.5), (0.5, -0.5), (0.5, 0.5)]:
            Q.append((X + dx * r, Y + dy * r, r / 2))

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations

def main():
    EPS = 1e-8

    N, K, *XYC = map(int, open(0).read().split())
    PC = [(complex(x, y), c) for x, y, c in zip(*[iter(XYC)] * 3)]


    def intersection(A, r, B, s):
        D = B - A
        d = abs(D)

        cos_t = (d * d + r * r - s * s) / (2 * d * r)
        sin_t = max(1 - cos_t * cos_t, 0.0) ** 0.5

        R = r * complex(cos_t, sin_t)
        D /= d

        return (
            A + D * R,
            A + D * R.conjugate(),
        )


    def is_ok(T):
        if any(K <= sum(1 for p, c in PC if c * abs(a - p) < T + EPS) for a, _ in PC):
            return True

        for (p1, c1), (p2, c2) in combinations(PC, 2):
            q1, q2 = intersection(p1, T / c1, p2, T / c2)
            if K <= sum(1 for p, c in PC if c * abs(q1 - p) < T + EPS):
                return True
            if K <= sum(1 for p, c in PC if c * abs(q2 - p) < T + EPS):
                return True

        return False

    ng, ok = 0, 1000000
    for _ in range(100):
        md = (ng + ok) / 2
        if is_ok(md):
            ok = md
        else:
            ng = md

    print(ok)

main()

Fixed submission:
from math import hypot
from collections import deque

N, K, *XYC = map(int, open(0).read().split())
XYC = list(zip(*[iter(XYC)] * 3))

Q = deque([(0, 0, 1000.0)])

ans = float("inf")
while Q:
    X, Y, r = Q.popleft()
    if ans * 0.9999995 > sorted(c * hypot(max(abs(X - x) - r, 0), max(abs(Y - y) - r, 0)) for x, y, c in XYC)[K - 1]:
        ans = min(ans, sorted(c * hypot(X - x, Y - y) for x, y, c in XYC)[K - 1])
        for dx, dy in [(-0.5, -0.5), (-0.5, 0.5), (0.5, -0.5), (0.5, 0.5)]:
            Q.append((X + dx * r, Y + dy * r, r / 2))

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations

def main():
    EPS = 1e-8

    N, K, *XYC = map(int, open(0).read().split())
    PC = [(complex(x, y), c) for x, y, c in zip(*[iter(XYC)] * 3)]


    def intersection(A, r, B, s):
        D = B - A
        d = abs(D)

        cos_t = (d * d + r * r - s * s) / (2 * d * r)
        sin_t = max(1 - cos_t * cos_t, 0.0) ** 0.5

        R = r * complex(cos_t, sin_t)
        D /= d

        return (
            A + D * R,
            A + D * R.conjugate(),
        )


    def is_ok(T):
        A = [p for p, _ in PC]
        for (p1, c1), (p2, c2) in combinations(PC, 2):
            A += intersection(p1, T / c1, p2, T / c2)

        return any(K <= sum(1 for p, c in PC if c * abs(a - p) < T + EPS) for a in A)


    ng, ok = 0, 1000000
    for _ in range(100):
        md = (ng + ok) / 2
        if is_ok(md):
            ok = md
        else:
            ng = md

    print(ok)

main()

Fixed submission:
from math import hypot
from collections import deque

N, K, *XYC = map(int, open(0).read().split())
XYC = list(zip(*[iter(XYC)] * 3))

Q = deque([(0, 0, 1000.0)])

ans = float("inf")
while Q:
    X, Y, r = Q.popleft()
    if ans * 0.9999995 > sorted(c * hypot(max(abs(X - x) - r, 0), max(abs(Y - y) - r, 0)) for x, y, c in XYC)[K - 1]:
        ans = min(ans, sorted(c * hypot(X - x, Y - y) for x, y, c in XYC)[K - 1])
        for dx, dy in [(-0.5, -0.5), (-0.5, 0.5), (0.5, -0.5), (0.5, 0.5)]:
            Q.append((X + dx * r, Y + dy * r, r / 2))

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations

EPS = 1e-8

N, K, *XYC = map(int, open(0).read().split())
PC = [(complex(x, y), c) for x, y, c in zip(*[iter(XYC)] * 3)]


def intersection(A, r, B, s):
    D = B - A
    d = abs(D)

    cos_t = (d * d + r * r - s * s) / (2 * d * r)
    sin_t = max(1 - cos_t * cos_t, 0.0) ** 0.5

    R = r * complex(cos_t, sin_t)
    D /= d

    return (
        A + D * R,
        A + D * R.conjugate(),
    )


def is_ok(T):
    A = [p for p, _ in PC]
    for (p1, c1), (p2, c2) in combinations(PC, 2):
        A += intersection(p1, T / c1, p2, T / c2)

    return any(K <= sum(1 for p, c in PC if c * abs(a - p) < T + EPS) for a in A)


ng, ok = 0, 1000000
for _ in range(100):
    md = (ng + ok) / 2
    if is_ok(md):
        ok = md
    else:
        ng = md

print(ok)

Fixed submission:
from math import hypot
from collections import deque

N, K, *XYC = map(int, open(0).read().split())
XYC = list(zip(*[iter(XYC)] * 3))

Q = deque([(0, 0, 1000.0)])

ans = float("inf")
while Q:
    X, Y, r = Q.popleft()
    if ans * 0.9999995 > sorted(c * hypot(max(abs(X - x) - r, 0), max(abs(Y - y) - r, 0)) for x, y, c in XYC)[K - 1]:
        ans = min(ans, sorted(c * hypot(X - x, Y - y) for x, y, c in XYC)[K - 1])
        for dx, dy in [(-0.5, -0.5), (-0.5, 0.5), (0.5, -0.5), (0.5, 0.5)]:
            Q.append((X + dx * r, Y + dy * r, r / 2))

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations

EPS = 1e-8

N, K, *XYC = map(int, open(0).read().split())
PC = [(complex(x, y), c) for x, y, c in zip(*[iter(XYC)] * 3)]


def intersection(A, r, B, s):
    D = B - A
    d = abs(D)

    cos_t = (d * d + r * r - s * s) / (2 * d * r)
    sin_t = max(1 - cos_t * cos_t, 0.0) ** 0.5

    R = r * complex(cos_t, sin_t)
    D /= d

    return (
        A + D * R,
        A + D * R.conjugate(),
    )


def is_ok(T):
    A = [p for p, _ in PC]
    for (p1, c1), (p2, c2) in combinations(PC, 2):
        A += intersection(p1, T / c1, p2, T / c2)

    return any(K <= sum(1 for p, c in PC if c * abs(a - p) < T + EPS) for a in A)


ng, ok = 0, 100000
for _ in range(80):
    md = (ng + ok) / 2
    if is_ok(md):
        ok = md
    else:
        ng = md

print(ok)

Fixed submission:
from math import hypot
from collections import deque

N, K, *XYC = map(int, open(0).read().split())
XYC = list(zip(*[iter(XYC)] * 3))

Q = deque([(0, 0, 1000.0)])

ans = float("inf")
while Q:
    X, Y, r = Q.popleft()
    if ans * 0.9999995 > sorted(c * hypot(max(abs(X - x) - r, 0), max(abs(Y - y) - r, 0)) for x, y, c in XYC)[K - 1]:
        ans = min(ans, sorted(c * hypot(X - x, Y - y) for x, y, c in XYC)[K - 1])
        for dx, dy in [(-0.5, -0.5), (-0.5, 0.5), (0.5, -0.5), (0.5, 0.5)]:
            Q.append((X + dx * r, Y + dy * r, r / 2))

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# https://atcoder.jp/contests/abc157/tasks/abc157_f

from itertools import combinations

EPS = 1e-8

N, K, *XYC = map(int, open(0).read().split())
PC = [(complex(x, y), c) for x, y, c in zip(*[iter(XYC)] * 3)]


def intersection(A, r, B, s):
    D = B - A
    d = abs(D)

    cos_t = (d * d + r * r - s * s) / (2 * d * r)
    sin_t = max(1 - cos_t * cos_t, 0.0) ** 0.5

    R = r * complex(cos_t, sin_t)
    D /= d

    return (
        A + D * R,
        A + D * R.conjugate(),
    )


def is_ok(T):
    A = [p for p, _ in PC]
    for (p1, c1), (p2, c2) in combinations(PC, 2):
        A += intersection(p1, T / c1, p2, T / c2)

    return any(K <= sum(1 for p, c in PC if c * abs(a - p) < T + EPS) for a in A)


ng, ok = 0, 1000000
for _ in range(80):
    md = (ng + ok) / 2
    if is_ok(md):
        ok = md
    else:
        ng = md

print(ok)

Fixed submission:
from math import hypot
from collections import deque

N, K, *XYC = map(int, open(0).read().split())
XYC = list(zip(*[iter(XYC)] * 3))

Q = deque([(0, 0, 1000.0)])

ans = float("inf")
while Q:
    X, Y, r = Q.popleft()
    if ans * 0.9999995 > sorted(c * hypot(max(abs(X - x) - r, 0), max(abs(Y - y) - r, 0)) for x, y, c in XYC)[K - 1]:
        ans = min(ans, sorted(c * hypot(X - x, Y - y) for x, y, c in XYC)[K - 1])
        for dx, dy in [(-0.5, -0.5), (-0.5, 0.5), (0.5, -0.5), (0.5, 0.5)]:
            Q.append((X + dx * r, Y + dy * r, r / 2))

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):

from itertools import combinations

EPS = 1e-8

N, K, *XYC = map(int, open(0).read().split())
PC = [(complex(x, y), c) for x, y, c in zip(*[iter(XYC)] * 3)]


def intersection(A, r, B, s):
    D = B - A
    d = abs(D)

    cos_t = (d * d + r * r - s * s) / (2 * d * r)
    sin_t = max(1 - cos_t * cos_t, 0.0) ** 0.5

    R = r * complex(cos_t, sin_t)
    D /= d

    return (
        A + D * R,
        A + D * R.conjugate(),
    )


def is_ok(T):
    A = [p for p, _ in PC]
    for (p1, c1), (p2, c2) in combinations(PC, 2):
        A += intersection(p1, T / c1, p2, T / c2)

    return any(K <= sum(1 for p, c in PC if c * abs(a - p) < T + EPS) for a in A)


ng, ok = 0, 1000000
for _ in range(100):
    md = (ng + ok) / 2
    if is_ok(md):
        ok = md
    else:
        ng = md

print(ok)

Fixed submission:
from math import hypot
from collections import deque

N, K, *XYC = map(int, open(0).read().split())
XYC = list(zip(*[iter(XYC)] * 3))

Q = deque([(0, 0, 1000.0)])

ans = float("inf")
while Q:
    X, Y, r = Q.popleft()
    if ans * 0.9999995 > sorted(c * hypot(max(abs(X - x) - r, 0), max(abs(Y - y) - r, 0)) for x, y, c in XYC)[K - 1]:
        ans = min(ans, sorted(c * hypot(X - x, Y - y) for x, y, c in XYC)[K - 1])
        for dx, dy in [(-0.5, -0.5), (-0.5, 0.5), (0.5, -0.5), (0.5, 0.5)]:
            Q.append((X + dx * r, Y + dy * r, r / 2))

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations

EPS = 1e-8

N, K, *XYC = map(int, open(0).read().split())
PC = [(complex(x, y), c) for x, y, c in zip(*[iter(XYC)] * 3)]


def intersection(A, r, B, s):
    D = B - A
    d = abs(D)

    cos_t = (d * d + r * r - s * s) / (2 * d * r)
    sin_t = max(1 - cos_t * cos_t, 0.0) ** 0.5

    R = r * complex(cos_t, sin_t)
    D /= d

    return (
        A + D * R,
        A + D * R.conjugate(),
    )


def is_ok(T):
    A = [p for p, _ in PC]
    for (p1, c1), (p2, c2) in combinations(PC, 2):
        A += intersection(p1, T / c1, p2, T / c2)

    for a in A:
        cnt = 0
        for p, c in PC:
            if c * abs(a - p) <= T + EPS:
                cnt += 1
        if K <= cnt:
            return True
    return False


ng, ok = 0, 10000000
for _ in range(100):
    md = (ng + ok) / 2
    if is_ok(md):
        ok = md
    else:
        ng = md

print(ok)

Fixed submission:
from math import hypot
from collections import deque

N, K, *XYC = map(int, open(0).read().split())
XYC = list(zip(*[iter(XYC)] * 3))

Q = deque([(0, 0, 1000.0)])

ans = float("inf")
while Q:
    X, Y, r = Q.popleft()
    if ans * 0.9999995 > sorted(c * hypot(max(abs(X - x) - r, 0), max(abs(Y - y) - r, 0)) for x, y, c in XYC)[K - 1]:
        ans = min(ans, sorted(c * hypot(X - x, Y - y) for x, y, c in XYC)[K - 1])
        for dx, dy in [(-0.5, -0.5), (-0.5, 0.5), (0.5, -0.5), (0.5, 0.5)]:
            Q.append((X + dx * r, Y + dy * r, r / 2))

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from math import hypot
from collections import deque

N, K, *XYC = map(int, open(0).read().split())
XYC = list(zip(*[iter(XYC)] * 3))

Q = deque([(0, 0, 1000.0)])

ans = float("inf")
while Q:
    X, Y, r = Q.popleft()
    if ans * 0.9999999 > sorted(c * hypot(max(abs(X - x) - r, 0), max(abs(Y - y) - r, 0)) for x, y, c in XYC)[K - 1]:
        ans = min(ans, sorted(c * hypot(X - x, Y - y) for x, y, c in XYC)[K - 1])
        for dx, dy in [(-0.5, -0.5), (-0.5, 0.5), (0.5, -0.5), (0.5, 0.5)]:
            Q.append((X + dx * r, Y + dy * r, r / 2))

print(ans)

Fixed submission:
from math import hypot
from collections import deque

N, K, *XYC = map(int, open(0).read().split())
XYC = list(zip(*[iter(XYC)] * 3))

Q = deque([(0, 0, 1000.0)])

ans = float("inf")
while Q:
    X, Y, r = Q.popleft()
    if ans * 0.9999995 > sorted(c * hypot(max(abs(X - x) - r, 0), max(abs(Y - y) - r, 0)) for x, y, c in XYC)[K - 1]:
        ans = min(ans, sorted(c * hypot(X - x, Y - y) for x, y, c in XYC)[K - 1])
        for dx, dy in [(-0.5, -0.5), (-0.5, 0.5), (0.5, -0.5), (0.5, 0.5)]:
            Q.append((X + dx * r, Y + dy * r, r / 2))

print(ans)