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# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Math;
using System.Text;
using System.Threading;
using System.Globalization;
using System.Runtime.CompilerServices;
using Library;

namespace Program
{
    public static class ABC157F
    {
        static public int numberOfRandomCases = 0;
        static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker)
        {
        }
        static public void Solve()
        {
            double EPS = 1e-12;
            var N = NN;
            var K = NN;
            var xycList = Repeat(0, N).Select(_ => new { x = ND, y = ND, c = ND }).ToArray();
            var ans = double.MaxValue;
            for (var i = 0; i < N; i++)
            {
                var posX = xycList[i].x;
                var posY = xycList[i].y;
                var kouho = xycList.Select((x, idx) => new { time = x.c * Sqrt((x.x - posX) * (x.x - posX) + (x.y - posY) * (x.y - posY)), idx = idx }).OrderBy(e => e.time).Take((int)K).ToArray();
                var xvlist = new double[K];
                Func<double, double> fun = fixX =>
                {
                    // X繧貞崋螳壹＠縺溘→縺肴怙蟆上→縺ｪ繧句､繧定ｿ斐☆
                    double leftY = -1000;
                    double rightY = 1000;
                    while (rightY - leftY > EPS)
                    {
                        var t1Y = (2 * leftY + rightY) / 3;
                        var t2Y = (leftY + rightY * 2) / 3;
                        for (var k = 0; k < K; k++)
                        {
                            xvlist[k] = xycList[kouho[k].idx].x - fixX;
                            xvlist[k] *= xvlist[k];
                        }
                        double ans1 = 0;
                        double ans2 = 0;
                        for (var k = 0; k < K; k++)
                        {
                            var v = xycList[kouho[k].idx];
                            ans1 = Max(ans1, v.c * Sqrt(xvlist[k] + (v.y - t1Y) * (v.y - t1Y)));
                            ans2 = Max(ans2, v.c * Sqrt(xvlist[k] + (v.y - t2Y) * (v.y - t2Y)));
                        }
                        if (ans1 - EPS < ans2) rightY = t2Y;
                        else leftY = t1Y;
                    }
                    double ret = 0;
                    for (var k = 0; k < K; k++)
                    {
                        var v = xycList[kouho[k].idx];
                        ret = Max(ret, v.c * Sqrt(xvlist[k] + (v.y - leftY) * (v.y - leftY)));
                    }
                    return ret;
                };
                double leftX = -1000;
                double rightX = 1000;
                while (rightX - leftX > EPS)
                {
                    var t1X = (2 * leftX + rightX) / 3;
                    var t2X = (leftX + rightX * 2) / 3;
                    var ans1 = fun(t1X);
                    var ans2 = fun(t2X);
                    if (ans1 - EPS < ans2) rightX = t2X;
                    else leftX = t1X;
                }
                ans = Min(ans, fun(leftX));
            }
            Console.WriteLine(ans);
        }
        static class Console_
        {
            static Queue<string> param = new Queue<string>();
            public static string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); }
        }
        class Printer : StreamWriter
        {
            public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
            public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { base.AutoFlush = false; }
            public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { base.AutoFlush = false; }
        }
        static public void Main(string[] args) { if (args.Length == 0) { Console.SetOut(new Printer(Console.OpenStandardOutput())); } var t = new Thread(Solve, 134217728); t.Start(); t.Join(); Console.Out.Flush(); }
        static long NN => long.Parse(Console_.NextString());
        static double ND => double.Parse(Console_.NextString());
        static string NS => Console_.NextString();
        static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray();
        static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray();
        static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray();
        static IEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => xorshift);
        static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred);
        static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n);
        static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c);
        static IEnumerable<string> OrderBy(this IEnumerable<string> x) => x.OrderBy(e => e, StringComparer.OrdinalIgnoreCase);
        static IEnumerable<T> OrderBy<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderBy(selector, StringComparer.OrdinalIgnoreCase);
        static IEnumerable<string> OrderByDescending(this IEnumerable<string> x) => x.OrderByDescending(e => e, StringComparer.OrdinalIgnoreCase);
        static IEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByDescending(selector, StringComparer.OrdinalIgnoreCase);
        static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } }
        static IEnumerator<uint> _xsi = _xsc();
        static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } }
    }
}
namespace Library {
}