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 in Go (1.14.1) (judge verdict: Accepted)

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n, k := scanInt(), scanInt()
	x, y, c := make([]float64, n), make([]float64, n), make([]float64, n)
	for i := 0; i < n; i++ {
		x[i], y[i], c[i] = scanFloat64(), scanFloat64(), scanFloat64()
	}

	t1, t2 := 0., 1e6
	for t := 0; t < 100; t++ {
		m := (t1 + t2) / 2
		f := false
		ps := []point{}
		for i := 0; i < n; i++ {
			ps = append(ps, point{x[i], y[i]})
			c1 := circle{x[i], y[i], m / c[i]}
			for j := 0; j < n; j++ {
				c2 := circle{x[j], y[j], m / c[j]}
				ps = append(ps, ccIntersection(c1, c2)...)
			}
		}
		for _, p := range ps {
			cnt := 0
			for i := 0; i < n; i++ {
				if dist(p, point{x[i], y[i]}) <= m/c[i]+eps {
					cnt++
				}
			}
			if cnt >= k {
				f = true
				break
			}
		}
		if f {
			t2 = m
		} else {
			t1 = m
		}
	}
	fmt.Fprintln(wr, t2)
}

const eps = 1e-8

type point struct{ x, y float64 }
type circle struct{ x, y, r float64 }

func dist(p1, p2 point) float64 {
	return math.Sqrt((p1.x-p2.x)*(p1.x-p2.x) + (p1.y-p2.y)*(p1.y-p2.y))
}

func circumcenter(a, b, c point) point {
	square := func(p1, p2 point) float64 {
		return (p1.x-p2.x)*(p1.x-p2.x) + (p1.y-p2.y)*(p1.y-p2.y)
	}
	aa := square(b, c)
	bb := square(c, a)
	cc := square(a, b)
	d := aa*(bb+cc-aa) + bb*(cc+aa-bb) + cc*(aa+bb-cc)
	x := (aa*(bb+cc-aa)*a.x + bb*(cc+aa-bb)*b.x + cc*(aa+bb-cc)*c.x) / d
	y := (aa*(bb+cc-aa)*a.y + bb*(cc+aa-bb)*b.y + cc*(aa+bb-cc)*c.y) / d

	return point{x, y}
}

func isStraight(a, b, c point) bool {
	square := func(p1, p2 point) float64 {
		return (p1.x-p2.x)*(p1.x-p2.x) + (p1.y-p2.y)*(p1.y-p2.y)
	}
	aa := square(b, c)
	bb := square(c, a)
	cc := square(a, b)
	if aa*(bb+cc-aa)+bb*(cc+aa-bb)+cc*(aa+bb-cc) < eps {
		return true
	}
	return false
}

func ccIntersection(c1, c2 circle) []point {
	res := []point{}
	d := math.Sqrt((c1.x-c2.x)*(c1.x-c2.x) + (c1.y-c2.y)*(c1.y-c2.y))
	if d < eps || c1.r+c2.r+eps < d || math.Abs(c1.r-c2.r) > d+eps {
		return []point{}
	}
	rc := (c1.r*c1.r + d*d - c2.r*c2.r) / (2 * d)
	rs := math.Sqrt(c1.r*c1.r - rc*rc)
	e := point{(c2.x - c1.x) / d, (c2.y - c1.y) / d}
	p1 := point{c1.x + e.x*rc - e.y*rs, c1.y + e.x*rs + e.y*rc}
	p2 := point{c1.x + e.x*rc + e.y*rs, c1.y - e.x*rs + e.y*rc}
	res = append(res, p1)
	if dist(p1, p2) >= eps {
		res = append(res, p2)
	}
	return res
}