Problem:
 Score : 600 points    Problem Statement Takahashi wants to grill N pieces of meat on a grilling net, which can be seen as a two-dimensional plane. The coordinates of the i -th piece of meat are \left(x_i, y_i\right) , and its hardness is c_i .  Takahashi can use one heat source to grill the meat. If he puts the heat source at coordinates \left(X, Y\right) , where X and Y are real numbers, the i -th piece of meat will be ready to eat in c_i \times \sqrt{\left(X - x_i\right)^2 + \left(Y-y_i\right)^2} seconds.  Takahashi wants to eat K pieces of meat. Find the time required to have K or more pieces of meat ready if he put the heat source to minimize this time.      Constraints  All values in input are integers.  1 \leq N \leq 60  1 \leq K \leq N  -1000 \leq x_i , y_i \leq 1000  \left(x_i, y_i\right) \neq \left(x_j, y_j\right) \left(i \neq j \right)  1 \leq c_i \leq 100         Input Input is given from Standard Input in the following format:  N  K  x_1  y_1  c_1  \vdots  x_N  y_N  c_N       Output Print the answer.  It will be considered correct if its absolute or relative error from our answer is at most 10^{-6} .        Sample Input 1 4 3
-1 0 3
0 0 3
1 0 2
1 1 40      Sample Output 1 2.4  If we put the heat source at \left(-0.2, 0\right) , the 1 -st, 2 -nd, and 3 -rd pieces of meat will be ready to eat within 2.4 seconds. This is the optimal place to put the heat source.       Sample Input 2 10 5
-879 981 26
890 -406 81
512 859 97
362 -955 25
128 553 17
-885 763 2
449 310 57
-656 -204 11
-270 76 40
184 170 16      Sample Output 2 7411.2252

Solution (Python):

import sys

sysread = sys.stdin.readline


sys.setrecursionlimit(10**7)
import math
from itertools import combinations

def run():
    N, K = map(int, sysread().split())
    niku = []
    for i in range(N):
        niku.append([i]+list(map(int, sysread().split())))

    high_t = math.sqrt(2000**2 + 2000**2) * 101
    low_t = 0
    current = (high_t + low_t) / 2
    delta = 5e-7
    if K == 1:
        print(0)
        return None

    while high_t - low_t > delta:
        done = False
        c = [(current / ci) ** 2 for _, _, _, ci in niku]
        for i, xi, yi, _ in niku:
            if done:
                break
            K0 = 0
            for k, xk, yk, _ in niku:
                if done:
                    break
                ck = c[k]
                if ((xi - xk) ** 2 + (yi - yk) ** 2) <= ck + delta:
                    K0 += 1
                if K0 >= K:
                    done = True


        for (i, xi, yi, _), (j, xj, yj, _) in combinations(niku, 2):
            if done:
                break
            ci, cj = c[i], c[j]
            xj -= xi
            yj -= yi
            d2 = xj ** 2 + yj ** 2
            d = math.sqrt(d2)

            x = (d2 + ci - cj) / (2 * d)
            e = ci - x ** 2
            if e < 0 or math.sqrt(ci) + math.sqrt(cj) < d:
                continue
            else:
                e = math.sqrt(e)

            vx1, vy1 = xj / d, yj / d
            vx2, vy2 = yj / d, -xj / d

            X1 = vx1 * x + vx2 * e + xi
            X2 = vx1 * x - vx2 * e + xi
            Y1 = vy1 * x + vy2 * e + yi
            Y2 = vy1 * x - vy2 * e + yi

            K1 = 0
            K2 = 0

            for k, xk, yk, _ in niku:
                if done:
                    break
                ck = c[k]
                if ((xk - X1) ** 2 + (yk - Y1) ** 2) <= ck + delta:
                    K1 += 1
                if ((xk - X2) ** 2 + (yk - Y2) ** 2) <= ck + delta:
                    K2 += 1
                if K1 >= K or K2 >= K:
                    done = True


        if done:
            high_t = current
            current = (high_t + low_t) / 2
        else:
            low_t = current
            current = (high_t + low_t) / 2

    print((low_t + high_t) / 2)
    return None

if __name__ == "__main__":
    run()

Solution (Python):
EPS = 10**(-7)
N,K = map(int,input().split())
xyc = [list(map(int,input().split())) for _ in range(N)]

def possible(t):
    res = False
    cand = []
    for i in range(N):
        cand.append(xyc[i][:2])
        x1,y1,c1 = xyc[i]
        r1 = t/c1
        for j in range(i+1,N):
            x2,y2,c2 = xyc[j]
            r2 = t/c2
            d = ((x2-x1)**2+(y2-y1)**2)**0.5
            if abs(r1-r2)+EPS<d<r1+r2-EPS:
                mx = x1+(x2-x1)*(r1**2-r2**2+d**2)/(2*d**2)
                my = y1+(y2-y1)*(r1**2-r2**2+d**2)/(2*d**2)
                l = abs((r1**2-(mx-x1)**2-(my-y1)**2)**0.5)
                nx = (y2-y1)/d
                ny = -(x2-x1)/d
                cand.append([mx+nx*l,my+ny*l])
                cand.append([mx-nx*l,my-ny*l])


    for X,Y in cand:
        n = 0
        for i in range(N):
            x,y,c = xyc[i]
            if c*((X-x)**2+(Y-y)**2)**0.5<t+EPS:
                n += 1
        if n>=K:
            res = True

    return res

ng = 0
ok = 10**6
m = (ng+ok)/2
for i in range(100):
    if possible(m):
        ok = m
    else:
        ng = m
    m = (ok+ng)/2
print(m)

Solution (Python):
EPS = 1e-7
N, K = map(int, input().split())
pts = []
Cs = []
for _ in range(N):
    x, y, c = map(int, input().split())
    pts.append(x + y * 1j)
    Cs.append(c)

Rs = [0] * N


def cands():
    for i in range(N):
        yield pts[i]
        for j in range(i + 1, N):
            pt = pts[j] - pts[i]
            ab = -2 * pt
            l = ab * ab.conjugate()
            c = pt * pt.conjugate() + Rs[i] - Rs[j]
            d = Rs[i] - c * c / l
            if d.real < 0:
                continue
            m = (d / l) ** 0.5
            off = m * (ab.imag - ab.real * 1j)
            yield -ab * c / l + off + pts[i]
            yield -ab * c / l - off + pts[i]


def ok(secs):
    for i in range(N):
        Rs[i] = secs * secs / Cs[i] / Cs[i]
    for cand in cands():
        count = 0
        for pt, r in zip(pts, Rs):
            xy = pt - cand
            if (xy * xy.conjugate()).real < r + EPS:
                count += 1
                if count == K:
                    return True
    return False


lo = 0
hi = 1e10
for _ in range(100):
    mid = (lo + hi) / 2
    if ok(mid):
        hi = mid
    else:
        lo = mid
print(hi)

Solution (Python):
import sys
import math
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

EPS = 1e-9


class Vector:
    x = 0
    y = 0

    def __init__(self, x=0, y=0):
        self.x = x
        self.y = y

    def __add__(self, other):
        return self.__class__(self.x+other.x, self.y+other.y)

    def __sub__(self, other):
        return self.__class__(self.x-other.x, self.y-other.y)

    def __mul__(self, other):
        return self.__class__(self.x*other, self.y*other)

    def sqrtNorm(self):
        return self.x*self.x+self.y*self.y

    def norm(self):
        return math.sqrt(self.sqrtNorm())


class Circle:
    v = Vector()
    r = 0

    def __init__(self, v, r):
        self.v = v
        self.r = r

    def get_intersections(self, c):
        v = c.v-self.v
        l = v.norm()
        
        if equal(l, 0):
            return []
        
        if equal(l+self.r+c.r, max(l, self.r, c.r)*2):
            if equal(l+self.r, c.r):
                return [self.v - v*(self.r/l)]
            else:
                return [self.v + v*(self.r/l)]
        
        if l+self.r+c.r < max(l, self.r, c.r)*2:
            return []

        x = (l*l + self.r*self.r - c.r*c.r) / (2*l)
        y = math.sqrt(self.r*self.r - x*x)
        mid = self.v + v * (x/l)
        rv = Vector(v.y, -v.x)
        return [mid+rv*(y/l), mid-rv*(y/l)]

    def is_inside(self, v):
        return (v-self.v).norm() < self.r+EPS


def equal(a, b):
    return abs(a-b) < EPS


def main():
    n, k = map(int, input().split())

    if k == 1:
        print(0)
        return

    cs = [None]*n
    rs = [0]*n
    for i in range(n):
        x, y, c = map(int, input().split())
        cs[i] = Circle(Vector(x, y), c)
        rs[i] = c
    l = 0
    r = 400000
    for z in range(100):
        x = (l+r)/2
        ps = [None]*n
        for i in range(n):
            ps[i] = cs[i].v

        for i in range(n):
            a = cs[i]
            a.r = x/rs[i]
            for j in range(i+1, n):
                b = cs[j]
                b.r = x/rs[j]
                ps += a.get_intersections(b)
        is_ok = False
        for p in ps:
            cnt = 0
            for i in range(n):
                nc = cs[i]
                nc.r = x/rs[i]
                if nc.is_inside(p):
                    cnt += 1
            if cnt >= k:
                is_ok = True
                break
        if is_ok:
            r = x
        else:
            l = x
    print(r)


main()

Solution (Python):
from math import sqrt
def crosscircle(c1, c2):
    (x1, y1, r1) = c1
    (x2, y2, r2) = c2
    if (x1-x2)**2 + (y1-y2)**2 > (r1+r2)**2:
        return ()
    elif x1 == x2 and y1 == y2:
        return ()
    elif (x1-x2)**2 + (y1-y2)**2 == (r1+r2)**2:
        x = (x1*r2+x2*r1)/(r1+r2)
        y = (y1*r2+y2*r1)/(r1+r2)
        return ((x, y),)
    elif y1 == y2:
        x = (r1**2-r2**2-x1**2+x2**2)/(2*(x2-x1))
        if y1**2-(y1**2-r1**2+(x-x1)**2) >= 0:
            yans1 = y1+sqrt(y1**2-(y1**2-r1**2+(x-x1)**2))
            yans2 = y1-sqrt(y1**2-(y1**2-r1**2+(x-x1)**2))
            return ((x, yans1), (x, yans2))
        else:
            return ()
    elif x1 == x2:
        y = (r1**2-r2**2-y1**2+y2**2)/(2*(y2-y1))
        if x1**2-(x1**2-r1**2+(y-y1)**2) >= 0:
            xans1 = x1+sqrt(x1**2-(x1**2-r1**2+(y-y1)**2))
            xans2 = x1-sqrt(x1**2-(x1**2-r1**2+(y-y1)**2))
            return ((xans1, y), (xans2, y))
        else:
            return ()
    else:
        A = ((x1-x2)/(y1-y2))**2 + 1
        B = (x1-x2)*(r1**2-r2**2-x1**2+x2**2+(y1-y2)**2)/(y1-y2)**2 - 2*x1
        C = ((r1**2-r2**2-x1**2+x2**2+(y1-y2)**2)/(2*(y1-y2)))**2 + x1**2 - r1**2
        if B**2 - 4*A*C >= 0:
            xans1 = (-B+sqrt(B**2-4*A*C))/(2*A)
            xans2 = (-B-sqrt(B**2-4*A*C))/(2*A)
            yans1 = -((r1**2-r2**2-x1**2+x2**2-y1**2+y2**2))/(2*(y1-y2))-xans1*(x1-x2)/(y1-y2)
            yans2 = -((r1**2-r2**2-x1**2+x2**2-y1**2+y2**2))/(2*(y1-y2))-xans2*(x1-x2)/(y1-y2)
            return ((xans1, yans1), (xans2, yans2))
        else:
            return ()

N, K = map(int, input().split())
li = [tuple(map(int, input().split())) for i in range(N)]
eps = 1e-6
U = 2e05
L = 0
while U - L > 1e-6:
    T = (U+L)/2
    points = []
    for i in range(N-1):
        for j in range(i+1, N):
            c1 = (li[i][0],li[i][1],T/li[i][2])
            c2 = (li[j][0],li[j][1],T/li[j][2])
            p = crosscircle(c1,c2)
            if p == ():
                continue
            for a in p:
                points.append(a)
    for i in range(N):
        points.append((li[i][0], li[i][1]))
    Max = 0
    for p in points:
        cnt = 0
        for i in range(N):
            x,y,r = li[i][0],li[i][1],T/li[i][2]
            if (p[0]-x)**2+(p[1]-y)**2<= (r+eps)**2:
                cnt += 1
        Max = max(Max, cnt)
    if Max < K:
        L = T
    else:
        U = T
print(T)

Solution (Python):
def main():
    import sys
    from math import sqrt, hypot
    input = sys.stdin.readline

    def dist(p1, p2):
        return hypot(p1[0]-p2[0], p1[1]-p2[1])

    def CP(x1, y1, r1, x2, y2, r2):
        rr0 = (x2 - x1) ** 2 + (y2 - y1) ** 2
        xd = x2 - x1
        yd = y2 - y1
        rr1 = r1 ** 2
        rr2 = r2 ** 2
        cv = (rr0 + rr1 - rr2)
        if 4 * rr0 * rr1 - cv ** 2 >= 0:
            sv = sqrt(4 * rr0 * rr1 - cv ** 2)
            return (
                (x1 + (cv * xd - sv * yd) / (2. * rr0), y1 + (cv * yd + sv * xd) / (2. * rr0)),
                (x1 + (cv * xd + sv * yd) / (2. * rr0), y1 + (cv * yd - sv * xd) / (2. * rr0)),
            )
        else:
            return (x1, y1), (x2, y2)

    N, K = map(int, input().split())

    if N == 1:
        print(0)
        exit()

    info = []
    for _ in range(N):
        info.append(tuple(map(int, input().split())))

    eps = 10**-8
    ok = 150000.
    ng = -eps
    mid = (ok+ng)/2
    while ok - ng > 10**-7:
        cp_list = []
        flg = 0
        fin = 0
        for i in range(N):
            x1, y1, c1 = info[i]
            p1 = (x1, y1)
            r1 = mid / c1
            for j in range(i+1, N):
                x2, y2, c2 = info[j]
                p2 = (x2, y2)
                r2 = mid / c2
                pa, pb = CP(x1, y1, r1, x2, y2, r2)
                cp_list.append(pa)
                cp_list.append(pb)

        flg = 0
        for p0 in cp_list:
            tmp = 0
            for x, y, c in info:
                p = (x, y)
                r = mid / c
                if dist(p0, p) < r + eps:
                    tmp += 1
            if tmp >= K:
                flg = 1
                break

        if flg:
            ok = mid
        else:
            ng = mid
        mid = (ok+ng)/2
    print(ok)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
readline = sys.stdin.buffer.readline
EPS = 1e-7
class Circle:
    def __init__(self, cx, cy, r):
        self.center = (cx, cy)
        self.radius = r
    def cross(self, C2):
        x1, y1 = self.center
        x2, y2 = C2.center
        R1 = self.radius
        R2 = C2.radius
        
        if (R2-R1)**2 + EPS <= (x2-x1)**2 + (y2-y1)**2 <= (R2+R1)**2 - EPS:
            dx, dy = x2-x1, y2-y1
            a = (R2**2 - R1**2 + x1**2 - x2**2 + y1**2 - y2**2)/2
            if abs(dy) > EPS:     
                
                D = dx**2 + dy**2
                bx = a*dx+dx*dy*y1-x1*dy**2
                cx = dy**2*(x1**2-R1**2) + (a+dy*y1)**2
                cx1 = (-bx + (bx**2-D*cx)**0.5)/D
                cx2 = (-bx - (bx**2-D*cx)**0.5)/D
                cy1 = -(dx*cx1+a)/dy
                cy2 = -(dx*cx2+a)/dy
            else:
                k = (R1**2-R2**2+dx**2)/2/dx
                cx1 = cx2 = x1+k
                cy1 = y1 + (R1**2-k**2)**0.5
                cy2 = y1 - (R1**2-k**2)**0.5
                
                
                
                
            return [(cx1, cy1), (cx2, cy2)]
        else:
            return []
    
    def isinside(self, x, y):
        x1, y1 = self.center
        return (x1-x)**2 + (y1-y)**2 - EPS < self.radius**2

            
N, K = map(int, readline().split())
Points = [tuple(map(int, readline().split())) for _ in range(N)]

ok = 1e6
ng = 0
candidate = [(x, y) for x, y, _ in Points]
for _ in range(40):
    med = (ok+ng)/2
    Cs = [Circle(x, y, med/c) for x, y, c in Points]
    candidate2 = candidate[:]
    for i in range(N):
        for j in range(i):
            candidate2.extend(Cs[i].cross(Cs[j]))
    for px, py in candidate2:
        res = 0
        for C in Cs:
            if C.isinside(px, py):
                res += 1
        if res >= K:
            ok = med
            break
    else:
        ng = med


print(ok)

Solution (Python):
import sys
from math import sqrt
from itertools import combinations
def resolve():
    eps = 1e-7
    N, K, *xyc = map(int, sys.stdin.read().split())
    x = xyc[::3]
    y = xyc[1::3]
    ci = list(zip(x, y))
    _r = xyc[2::3]
    l = 0
    r = 10 ** 6
    while l + eps < r:
        T = (l + r) / 2
        rad = [(T/_r[i])**2 for i in range(N)]
        ans = 0
        xys = []
        for i, j in combinations(range(N), 2):
            cx1, cy1 = ci[i]
            cx2, cy2 = ci[j]
            xt = cx2-cx1
            yt = cy2-cy1
            XY = xt**2+yt**2
            a = (XY+rad[i]-rad[j])/2
            d = XY*rad[i]-a**2
            if d < eps:
                continue
            x1 = (a*xt+yt*sqrt(d))/XY+cx1
            y1 = (a*yt-xt*sqrt(d))/XY+cy1
            x2 = (a*xt-yt*sqrt(d))/XY+cx1
            y2 = (a*yt+xt*sqrt(d))/XY+cy1
            xys.append([x1, y1])
            xys.append([x2, y2])
        xys.extend(ci)
        for X, Y in xys:
            tmp = 0
            for (x, y), k in zip(ci, rad):
                if (x-X)**2+(y-Y)**2 < k+eps:
                    tmp += 1
            ans = max(ans, tmp)
            if ans >= K:
                break
        if ans >= K:
            r = T
        else:
            l = T
    print(r)
resolve()

Solution (Python):
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)

Solution (Python):
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:
        if K <= sum(1 for p, c in PC if c * abs(a - 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)

Solution (Python):
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, 1000000
for _ in range(100):
    md = (ng + ok) / 2
    if is_ok(md):
        ok = md
    else:
        ng = md

print(ok)

Solution (Python):
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])
        r /= 2
        Q += [
            (X + r, Y + r, r),
            (X - r, Y + r, r),
            (X + r, Y - r, r),
            (X - r, Y - r, r),
        ]

print(ans)

Solution (Python):
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)

Solution (Python):
import sys
import math

eps = 10**(-9)

def main():
    input = sys.stdin.readline
    N, K = map(int, input().split())
    circles = []
    C = []
    for _ in range(N):
        x, y, c = map(int, input().split())
        circles.append(Circle(Vector(x, y), c))
        C.append(c)

    def calc_meet(t):
        '''t秒後に焼ける肉の数の最大値を求める。
        '''
        
        candidates = []
        for i in range(N):
            candidates.append(circles[i].c)
            circles[i].r = t/C[i]
            for j in range(i+1, N):
                circles[j].r = t/C[j]
                candidates += circles[i].cp(circles[j])

        
        m = 0
        for c in candidates:
            count = 0
            for i, meet in enumerate(circles):
                if (c - meet.c).length() * C[i] <= t + eps: count += 1
            m = max(m, count)

        return m

    under = 0
    r = 10**6
    while r-under>10**(-6):
        m = (r + under) / 2
        if calc_meet(m) >= K: r = m
        else: under = m
    print(r)
    
class Circle:
    def __init__(self, c, r):
        self.c, self.r = c, r
    
    def cp(self, other):
        v = other.c - self.c
        d = v.length()
        equal = lambda x,y: abs(x-y) < eps
        if equal(d, 0): return []
        if equal(sum([d, self.r, other.r]), 2 * max(d, self.r, other.r)):
            return [self.c + v*(self.r/d)]
        if sum([d, self.r, other.r]) < 2 * max(d, self.r, other.r): return [] 
        x = (d*d + self.r*self.r - other.r*other.r) / (2*d)
        h = math.sqrt(self.r*self.r - x*x)
        m = self.c + v*(x/d)
        return [m + v.rotate90()*(h/d), m - v.rotate90()*(h/d)]

class Vector:
    def __init__(self, x, y):
        self.x, self.y = x, y

    def length(self): return math.sqrt(self.x*self.x + self.y*self.y)
    def rotate90(self): return Vector(self.y, -self.x)

    def __iadd__(self, other):
        self.x += other.x
        self.y += other.y
        return self
    def __add__(self, other):
        new_obj = Vector(self.x, self.y)
        new_obj += other
        return new_obj
    __radd__ = __add__

    def __isub__(self, other):
        self.x -= other.x
        self.y -= other.y
        return self
    def __sub__(self, other):
        new_obj = Vector(self.x, self.y)
        new_obj -= other
        return new_obj

    def __imul__(self, other_scalar):
        self.x *= other_scalar
        self.y *= other_scalar
        return self
    def __mul__(self, other_scalar):
        new_obj = Vector(self.x, self.y)
        new_obj *= other_scalar
        return new_obj

if __name__ == '__main__':
    main()

Solution (Python):
import sys
input = sys.stdin.readline
from math import sqrt

N,K=map(int,input().split())
M=[tuple(map(int,input().split())) for i in range(N)]

def cross_coor(x0,y0,c0,x1,y1,c1): 
    if (c1-c0)**2<=(x1-x0)**2+(y1-y0)**2<=(c0+c1)**2:
        x2,y2=x1-x0,y1-y0
        a=(x2**2+y2**2+c0**2-c1**2)/2

        xa=(a*x2+y2*sqrt((x2**2+y2**2)*(c0**2)-a**2))/(x2**2+y2**2)+x0
        ya=(a*y2-x2*sqrt((x2**2+y2**2)*(c0**2)-a**2))/(x2**2+y2**2)+y0

        xb=(a*x2-y2*sqrt((x2**2+y2**2)*(c0**2)-a**2))/(x2**2+y2**2)+x0
        yb=(a*y2+x2*sqrt((x2**2+y2**2)*(c0**2)-a**2))/(x2**2+y2**2)+y0

        return [(xa,ya),(xb,yb)]
    else:
        return False

OK=1<<31
NG=0

while OK-NG>10**(-8):
    mid=(OK+NG)/2
    
    CANDI=[]
    for i in range(N):
        x0,y0,c0=M[i]
        CANDI.append((x0,y0))
        for j in range(i+1,N):
            x1,y1,c1=M[j]
            CR=cross_coor(x0,y0,mid/c0,x1,y1,mid/c1)
            if CR:
                CANDI.extend(CR)

    for z,w in CANDI:
        count=0
        for x,y,c in M:
            if (c**2)*((x-z)**2+(y-w)**2)<=(mid+10**(-8))**2:
                count+=1
            
        if count>=K:
            OK=mid
            break
    else:
        NG=mid

print((OK+NG)/2)