Problem p02764 (python)

Fixed submission:
import cmath,sys
input = sys.stdin.readline


"""
cdist(z1,z2) : z1とz2の距離
cInDiv(z1,z2) : z1とz2をp:qに内分する点
cOutDiv(z1,z2) : z1とz2をp:qに外分する点
"""

# z.real,z.imag
EPS = 0.000000001

def cdist(z1,z2=0):
    return abs(z1-z2)

def cInDiv(z1,z2,p,q):
    return (q*z1+p*z2)/(p+q)

def cOutDiv(z1,z2,p,q):
    return (-q*z1+p*z2)/(p-q)

"""
cInCircle(z,c,r) : 点zは中心c半径rの円の中にあるか(0:円周上,-1:円内,1:円外)
cIntersectionPnt(z1,z2,r1,r2) : 中心z1半径r1,中心z2半径r2の円の交点の数、座標1,座標2
"""

def cInCircle(z,c,r):
    d = abs(z-c)
    if abs(r-d) < EPS:
        return 0
    if r-d > 0:
        return -1
    return 1

def cIntersectionPnt(z1,z2,r1,r2):
    d = abs(z1-z2)

    if d < EPS:
        if abs(r1-r2) < EPS:
            return float("inf"),-1,-1
        else:
            return 0,-1,-1
    
    
    if abs(d - (r1+r2)) < EPS:
        diff = (z2-z1)/d
        return 1,z1+diff*r1,-1
    
    if abs(d - (r1-r2)) < EPS:
        diff = (z2-z1)/d
        return 1,z1+diff*r1,-1
    
    if abs(d - (r2-r1)) < EPS:
        diff = (z1-z2)/d
        return 1,z2+diff*r2,-1

    if d > r1+r2:
        return 0,-1,-1
    if d < abs(r1-r2):
        return 0,-1,-1


    rc = (r1*r1+d*d-r2*r2)/(2*d)
    rs = cmath.sqrt(r1*r1-rc*rc)
    diff = (z2-z1)/d
    return 2,z1+diff*rc+diff*1j*rs,z1+diff*rc+diff*(-1j)*rs


n,k = map(int,input().split())
xy = []
c = []
for i in range(n):
    xx,yy,cc = map(int,input().split())
    xy.append(xx+yy*1j)
    c.append(cc)


def judge(t):
    points = []
    for i in range(n):
        for j in range(i+1,n):
            flag,pt1,pt2 = cIntersectionPnt(xy[i],xy[j],t/c[i],t/c[j])
            if flag == 1:
                points.append(pt1)
            elif flag == 2:
                points.append(pt1)
                points.append(pt2)
    for pc in xy:
        points.append(pc)
    for z in points:
        cnt = 0
        for i in range(n):
            flag = cInCircle(z,xy[i],t/c[i])
            if flag <= 0:
                cnt += 1
        if cnt >= k:
            return True
    return False


ok = 10**10
ng = 0
while abs(ok-ng) > EPS:
    mid = (ok+ng)/2
    if judge(mid):
        ok = mid
    else:
        ng = mid

print(ok)

Buggy submission (verdict: Runtime Error):
import cmath,sys
input = sys.stdin.readline


"""
cdist(z1,z2) : z1とz2の距離
cInDiv(z1,z2) : z1とz2をp:qに内分する点
cOutDiv(z1,z2) : z1とz2をp:qに外分する点
"""

# z.real,z.imag
EPS = 0.00000001

def cdist(z1,z2=0):
    return abs(z1-z2)

def cInDiv(z1,z2,p,q):
    return (q*z1+p*z2)/(p+q)

def cOutDiv(z1,z2,p,q):
    return (-q*z1+p*z2)/(p+q)

"""
cInCircle(z,c,r) : 点zは中心c半径rの円の中にあるか(0:円周上,-1:円内,1:円外)
cIntersectionPnt(z1,z2,r1,r2) : 中心z1半径r1,中心z2半径r2の円の交点の数、座標1,座標2
"""

def cInCircle(z,c,r):
    d = abs(z-c)
    if abs(r-d) < EPS:
        return 0
    if r-d > 0:
        return -1
    return 1

def cIntersectionPnt(z1,z2,r1,r2):
    d = abs(z1-z2)

    if d < EPS:
        if abs(r1-r2) < EPS:
            return float("inf"),-1,-1
        else:
            return 0,-1,-1
    
    if abs(d - (r1+r2)) < EPS:
        diff = (z2-z1)/d
        return 1,z1+diff*r1,-1
    
    if abs(d - (r1-r2)) < EPS:
        diff = (z2-z1)/d
        return 1,z1+diff*r1,-1
    
    if abs(d - (r2-r1)) < EPS:
        diff = (z1-z2)/d
        return 1,z2+diff*r2,-1

    rc = (r1*r1+d*d-r2*r2)/(2*d)
    rs = cmath.sqrt(r1*r1-rc*rc)
    diff = (z2-z1)/d
    return 2,z1+diff*rc+diff*1j**rs,z1+diff*rc+diff*(-1j)*rs


n,k = map(int,input().split())
xy = []
c = []
for i in range(n):
    xx,yy,cc = map(int,input().split())
    xy.append(xx+yy*1j)
    c.append(cc)


def judge(t):
    points = []
    for i in range(n):
        for j in range(i+1,n):
            flag,pt1,pt2 = cIntersectionPnt(xy[i],xy[j],t/c[i],t/c[j])
            if flag == 1:
                points.append(pt1)
            elif flag == 2:
                points.append(pt1)
                points.append(pt2)

    for z in points:
        cnt = 0
        for i in range(n):
            flag = cInCircle(z,xy[i],t/c[i])
            if flag <= 0:
                cnt += 1
        if cnt >= k:
            return True
    return False


ok = 10**10
ng = 0
for __ in range(300):
    mid = (ok+ng)/2
    if judge(mid):
        ok = mid
    else:
        ng = mid

print(ok)