Under construction

Still being built. Things may change

Dome Construction

Interview

Time limit2sMemory limit512 MB

Summary
Given n points in 3D with non-negative y, find the minimum radius of a dome (hemisphere on the xz-plane) that contains at least k of them.
Level

Medium4 of 10

Topics
Binary search, Geometry, Sorting, Math
Solved
No attempts yet

Problem

The world's largest indoor water park sits inside a hemispherical dome that was once used as an aircraft hangar. The park draws more than 10 000 visitors a day and is large enough to have its own tropical micro-climate, with clouds forming inside.

Management wants to expand by opening another branch in the dome of your local cathedral. The micro-climate is a key selling point, so to make full use of the cathedral they have asked you to expand the dome's radius until it contains at least a given number of clouds. A cloud is contained if its centre lies on or inside the boundary of the dome.

You are a cloud engineer by trade, and therefore a competent meteorologist. You have already identified several potential clouds nearby and plotted them in three dimensions relative to the centre of the current structure. How large do you need to make the radius of the dome in order to capture enough of them?

Input

  • The first line contains the number of clouds you found, n, and the number that must be contained, k (1 ≤ k ≤ n ≤ 105).
  • The next n lines each contain three real numbers xi, yi, zi, the coordinates of the ith cloud relative to the centre of the dome (0 ≤ |xi|, |yi|, |zi| ≤ 106). Every cloud has a non-negative y-coordinate.

Output

Output the minimum radius of the dome required to enclose at least k points. Your answer must be accurate to an absolute or relative error of 10−6.

Examples1

  1. Example 1

    Input
    5 3
    -4 2 1
    2.1 3 5
    1.2 1 -1
    -2.2 3 2
    1 0 2.1
    
    Expected output
    4.22374242