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 C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <bits/stdc++.h>
using namespace std;
const int maxn = 100;
const double eps = 1e-7;
struct Point
{
	double x, y, c, r;
}p[maxn];
vector<Point> inter;
int n, k;
bool double_equals(const double & a, const double & b) { return fabs(a - b) < eps;}
double sqr(const double & x) { return x * x;}
double getdissqr(const Point & a, const Point & b)
{
	return sqr(a.x - b.x) + sqr(a.y - b.y);
}
double getdis(const Point & a, const Point & b)
{
	return sqrt(sqr(a.x - b.x) + sqr(a.y - b.y));
}
void getinter(const Point & A, const Point & B)
{
	double d, a, b, c, p, q, r;
    double cos_value[2], sin_value[2];
    Point points[2];
    if (double_equals(A.x, B.x)
        && double_equals(A.y, B.y)
        && double_equals(A.r, B.r)) {
        return;
    }
 
    d = getdis(A, B);
    if (d > A.r + B.r) return;
    if (d < fabs(A.r - B.r)) {
    	if(A.r < B.r) inter.push_back(A);
    	else inter.push_back(B);
        return;
    }
 
    a = 2.0 * A.r * (A.x - B.x);
    b = 2.0 * A.r * (A.y - B.y);
    c = B.r * B.r - A.r * A.r
        - getdissqr(A, B);
    p = a * a + b * b;
    q = -2.0 * a * c;
    if (double_equals(d, A.r + B.r)
        || double_equals(d, fabs(A.r - B.r))) {
        cos_value[0] = min(1.0, -q / p / 2.0);
        sin_value[0] = sqrt(1 - cos_value[0] * cos_value[0]);
 
        points[0].x = A.r * cos_value[0] + A.x;
        points[0].y = A.r * sin_value[0] + A.y;
 
        if (!double_equals(getdissqr(points[0], B),
                           B.r * B.r)) {
            points[0].y = A.y - A.r * sin_value[0];
        }
        inter.push_back(points[0]);
        return;
    }

    r = c * c - b * b;
    cos_value[0] = min(1.0, (sqrt(q * q - 4.0 * p * r) - q) / p / 2.0);
    cos_value[1] = min(1.0, (-sqrt(q * q - 4.0 * p * r) - q) / p / 2.0);
    sin_value[0] = sqrt(1 - cos_value[0] * cos_value[0]);
    sin_value[1] = sqrt(1 - cos_value[1] * cos_value[1]);
 
    points[0].x = A.r * cos_value[0] + A.x;
    points[1].x = A.r * cos_value[1] + A.x;
    points[0].y = A.r * sin_value[0] + A.y;
    points[1].y = A.r * sin_value[1] + A.y;
 
    if (!double_equals(getdissqr(points[0], B),
                       B.r * B.r)) {
        points[0].y = A.y - A.r * sin_value[0];
    }
    if (!double_equals(getdissqr(points[1], B),
                       B.r * B.r)) {
        points[1].y = A.y - A.r * sin_value[1];
    }
    if (double_equals(points[0].y, points[1].y)
        && double_equals(points[0].x, points[1].x)) {
        if (points[0].y > 0) {
            points[1].y = -points[1].y;
        } else {
            points[0].y = -points[0].y;
        }
    }
    inter.push_back(points[0]);
    inter.push_back(points[1]);
    return;
} 	
bool solve(const Point & v)
{
	int tot = 0;
	for(int i = 1; i <= n; ++i)
		if(getdis(v, p[i]) <= p[i].r + eps)
			++tot;
	return tot >= k;
}
bool check(double x)
{
	for(int i = 1; i <= n; ++i) p[i].r = x / p[i].c;
	inter.clear();
	for(int i = 1; i <= n; ++i)
		for(int j = i + 1; j <= n; ++j)
			getinter(p[i], p[j]);
	for(auto v : inter)
	{
		if(solve(v))
			return true;
	}
	return false;
}
int main()
{
	cin >> n >> k;
	for(int i = 1; i <= n; ++i)
		cin >> p[i].x >> p[i].y >> p[i].c;
	double l = 0, r = 2e5;
	while(r - l >= eps)
	{
		double mid = (l + r) / 2;
		if(check(mid)) r = mid;
		else l = mid;
	}
	printf("%.10f\n", l);
	return 0;
}
/*
2 2
0 0 1
1 0 1
*/