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 Rust (1.15.1) (judge verdict: Wrong Answer)

//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn sq(x: f64) -> f64 {
    x * x
}

fn main() {
    let (N, K) = read!(usize, usize);
    let meets = read![f64, f64, f64; N];

    let mut l = 0.0;
    let mut r = 1e9;
    let mut points = vec![];

    for _ in 0..100 {
        let T = (l + r) / 2.0;
        debug!((l, r, T));

        points.clear();
        for i in 0..N {
            for j in i + 1..N {
                for &s in &[1.0, -1.0] {
                    let (x1, y1, c1) = meets[i];
                    let (x2, y2, c2) = meets[j];

                    points.push((
                        (c2 * x1 + c1 * x2) / (c1 + c2),
                        (c2 * y1 + c1 * y2) / (c1 + c2),
                    ));

                    // 平行移動
                    let (x1, y1) = (x1 - x2, y1 - y2);

                    // (x1, y1) と (0, 0) を中心とする半径 r2, r1 の円の交点を求める。
                    let r2 = T / c1;
                    let r1 = T / c2;
                    let v = sq(x1) + sq(y1);
                    let a = (v + sq(r1) - sq(r2)) / 2.0;
                    let u = (v * sq(r1) - sq(a)).sqrt();
                    let X = (a * x1 + s * y1 * u) / v;
                    let Y = (a * y1 - s * x1 * u) / v;

                    let (X, Y) = (X + x2, Y + y2);

                    points.push((X, Y));
                }
            }
        }

        let mut ok = false;
        'a: for (X, Y) in points.drain(..) {
            let mut count = 0;
            for i in 0..N {
                let (x, y, c) = meets[i];
                if sq(c) * (sq(x - X) + sq(y - Y)) <= sq(T) + 1e-7 {
                    count += 1;
                    if count >= K {
                        debug!((T, X, Y));
                        ok = true;
                        break 'a;
                    }
                }
            }
        }

        if ok {
            r = T;
        } else {
            l = T;
        }
    }

    println!("{}", l)
}