import Control.Monad
import Data.List

main = do
   [n,k] <- map read . words <$> getLine
   xyc <- replicateM n $ map read . words <$> getLine
   putStrLn $ show $ minimum $ minimum $ map (\x -> map (\y-> sum $ take k $ sort $ map (\i -> let xyci = xyc !! i in (xyci !! 2) * (sqrt ((xyci !! 1 - y)^2+(xyci !! 0 -x)^2))) [0..n-1]) [-1000..1000]) [-1000..1000]
   