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 <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef double T;
typedef pair<T,T> P;

// difference
P operator-(const P& lhs, const P& rhs)
{
	return P(lhs.first-rhs.first,lhs.second-rhs.second);
}

P operator+(const P& lhs, const P& rhs)
{
	return P(lhs.first+rhs.first, lhs.second+rhs.second);
}

// scalar product
P operator*(T t, P p){
	return P(t*p.first,t*p.second);
}

P operator/(P p, T t){
	return P(p.first/t,p.second/t);
}

P rot(P p){
	return P(-p.second,p.first);
}

// cross product
T Cross(const P& lhs, const P& rhs)
{
	return lhs.first*rhs.second-lhs.second*rhs.first;
}

// inner product 
T Dot(const P& lhs, const P& rhs)
{
	return lhs.first*rhs.first+lhs.second*rhs.second;
}

// square of distance
T Dist2(const P& lhs, const P& rhs){
	return Dot(lhs-rhs,lhs-rhs);
}

// b is on segment a c
bool onSegment(P a, P b, P c){
	P v=c-a;
	P w=b-a;
	return Cross(v,w)==0 && 0<=Dot(v,w)&&Dot(v,w)<=Dot(v,v);
}


// intersection of segments
bool Intersects(P s0, P e0, P s1, P e1)
{
	P a=s1-s0;
	P v=e0-s0;
	P w=s1-e1;
	T det=Cross(v,w);
	T t0=w.second*a.first-w.first*a.second;
	T t1=-v.second*a.first+v.first*a.second;
	if (det<0){
		if (det <= t0 && det <= t1 && t0 <= 0 && t1 <= 0){
			return true;
		}
	}
	else if (det > 0)
	{
		if (0 <= t0 && 0 <= t1 && t0 <= det && t1 <= det){
			return true;
		}
	}
	return onSegment(s0,s1,e0) ||
		onSegment(s0,e1,e0)||
		onSegment(s1,s0,e1)||
		onSegment(s1,e0,e1);
}

// intersection of line
bool IntersectLineParam(P s0, P e0, P s1, P e1, T& t0, T& t1)
{
	P a=s1-s0;
	P v=e0-s0;
	P w=s1-e1;
	T det=Cross(v,w);
	if(det == 0){
		return false;
	}
	t0=Cross(a,w)/det;
	t1=Cross(v,a)/det;
	return true;
}


P Interpolate(P s, P e, T t)
{
	return (1-t)*s+t*e;
}

bool IntersectLine(P s0, P e0, P s1, P e1, P& result)
{
	T t0,t1;
	if(IntersectLineParam(s0,e0,s1,e1,t0,t1)){
		result=Interpolate(s0,e0,t0);
		return true;
	}
	return false;
}

// intersection of polygons
bool Intersects(vector<P>& lhs, vector<P>& rhs)
{
	for(int i=1;i<lhs.size();i++){
		for (int j=1;j<rhs.size();j++){
			if (Intersects(lhs[i],lhs[i-1],rhs[j],rhs[j-1])){
				return true;
			}
		}
	}
	return false;
}

bool IsInside(vector<P>& ps, P p)
{
	int count=0;
	for(int i=0;i<ps.size();i++){
		P a=ps[i];
		P b=ps[(i+1)%ps.size()];
		if(min(a.first,b.first)<=p.first&&p.first<max(a.first,b.first))
		{
			T c=Cross(p-a,b-a);
			if(c==0){
				return true;
			}
			if(c<0){
				count--;
			}
			else
			{
				count++;
			}
		}
		else if (a.first==p.first&&b.first==p.first)
		{
			if(min(a.second,b.second)<=p.second&&p.second<=max(a.second,b.second))
			{
				return true;
			}
		}
	}
	return count!=0;
}

T area(vector<P> ps){
	T sum=0;
	for(int i=0;i<ps.size();i++){
		sum+=Cross(ps[i],ps[(i+1)%ps.size()]);
	}
	return abs(sum)/2;
}

// convex full
void full(vector<P>& in, vector<P>& out)
{
	sort(in.begin(),in.end());
	for(int i=0;i<in.size();i++){
		while(out.size()>=2){
			P v=out[out.size()-1]-out[out.size()-2];
			P w=in[i]-out[out.size()-1];
			if(Cross(v,w)>=0){
				out.pop_back();
			}
			else
			{
				break;
			}
		}
		out.push_back(in[i]);
	}
	for(int i=in.size()-2,k=max((int)out.size(),1);i>=0;i--){
		while(out.size()>k){
			P v=out[out.size()-1]-out[out.size()-2];
			P w=in[i]-out[out.size()-1];
			if(Cross(v,w)>=0){
				out.pop_back();
			}
			else
			{
				break;
			}
		}
		out.push_back(in[i]);
	}
}

// 円と直線の交点
void IntersectCircleLine(P c, T r, P s, P v, vector<P>& result){
	P w=c-s;
	T v2=Dot(v,v);
	P a=Dot(v,w)*v/v2+s;
	T d2=Dist2(c,a);
	if(d2>r*r){
		return;
	}else if(d2==r*r)
	{
		result.push_back(a);
	}

	P e=v/sqrt(v2);
	T len=sqrt(r*r-d2);
	result.push_back(len*e+a);
	result.push_back((-len)*e+a);
}

// 円と円の交点
void IntersectCircleCircle(P c0, T a, P c1, T b, vector<P>& result){
	T d2=Dist2(c0,c1);
	if(d2>(a+b)*(a+b)){
		return;
	}

	P s=Interpolate(c0,c1,((a*a-b*b)/d2+1)/2);
	P d=c0-c1;
	IntersectCircleLine(c0,a,s,P(d.second,-d.first),result);
}

// 距離の比率が a:b の円を求める
void RatioConstantCircle(P c0, T a, P c1, T b, P& c, T& r){
	if(a>b){
		swap(c0,c1);
		swap(a,b);
	}
	P p=Interpolate(c0,c1,a/(a+b));
	P q=Interpolate(c0,c1,-a/(b-a));
	c=(p+q)/2;
	r=sqrt(Dist2(c,p));
}

// 三円が交差するか？
bool Intersect3Circles(P c0, T r0, P c1, T r1, P c2, T r2){
	vector<P> result;
	for(int i=0;i<3;i++){
		result.clear();
		IntersectCircleCircle(c0,r0,c1,r1,result);
		for(auto p:result){
			if(Dist2(p,c2)<=r2*r2){
				return true;
			}
		}
		if(Dist2(c0,c1)<=r1*r1&&Dist2(c0,c2)<=r2*r2){
			return true;
		}
		swap(c0,c1);
		swap(c1,c2);
		swap(r0,r1);
		swap(r1,r2);
	}
	return false;
}

std::vector<P> ps;
std::vector<double> c;
long long N;
long long K;

double f(P p){
	vector<double> t;
	for(int i=0;i<N;i++){
		t.push_back(c[i]*c[i]*Dist2(ps[i],p));
	}
	nth_element(t.begin(),t.begin()+K-1,t.end());
	return sqrt(t[K-1]);
}

void solve(){
	double ret=DBL_MAX;
	for(int i=0;i<N;i++){
		ret=min(ret,f(ps[i]));
		for(int j=i+1;j<N;j++){
			P c0=(c[i]*ps[i]+c[j]*ps[j])/(c[i]+c[j]);
			ret=min(ret,f(c0));
			P cij;
			double rij;
			RatioConstantCircle(ps[i],c[j],ps[j],c[i],cij,rij);
			for(int k=j+1;k<N;k++){
				P cik;
				double rik;
				RatioConstantCircle(ps[i],c[k],ps[k],c[i],cik,rik);
				vector<P> rs;
				IntersectCircleCircle(cij,rij,cik,rik,rs);
				for(auto c1:rs){
					ret=min(ret,f(c1));
				}
			}
		}
	}
	cout.precision(17);
	cout << ret << endl;
}

int main(){
    scanf("%lld",&N);
    scanf("%lld",&K);

	ps.resize(N);
	c.resize(N);
    for(int i = 0 ; i < N ; i++){
		double x,y;
        scanf("%lf",&x);
        scanf("%lf",&y);
        scanf("%lf",&c[i]);
		ps[i]=P(x,y);
    }
    solve();
    return 0;
}