Under construction

Still being built. Things may change

Washer

Time limit1sMemory limit512 MB

Summary
Partition up to 100 points in 3D into at most k groups (k <= 2) to minimize the sum of squared distances to each group's centroid.
Level

Hard8 of 10

Topics
Geometry, Divide and conquer, Brute force, Math
Solved
No attempts yet

Problem

You have nn clothes and a washer. The washer is large enough to wash all the clothes at once. However, you have to worry about color transfer: if you put clothes of different colors in the washer, the dye from one may stain another. Precisely, let rir_i, gig_i, bib_i denote the amount of red, green, blue color of the ii-th clothes. When nn clothes are washed together, the color transfer cc is defined by

c=∑i=1n(ri−r)2+(gi−g)2+(bi−b)2c = \sum_{i=1}^{n}{(r_i - r)^2 + (g_i - g)^2 + (b_i - b)^2}

where rr, gg, and bb are the averages of rir_i, gig_i, bib_i, respectively. The ii-th clothes with rir_i, gig_i, and bib_i is defined as a point (ri,gi,bi)(r_i, g_i, b_i) in 3-dimensional RGB space. You can assume that no three points (clothes) are on a same line and no four points (clothes) are on a same plane in RGB space.

The washer consumes a lot of electricity, and you have to partition nn clothes into at most kk groups, and run the washer for each group. The total color transfer is the sum of color transfers from each run. Given the color information of nn clothes and kk, write a program to calculate the minimum total color transfer.

Input

Your program is to read from standard input. The first line contains two integers nn (1 ≤ nn ≤ 100) and kk (1 ≤ kk ≤ 2). In the following nn lines, the ii-th line contains three integers rir_i, gig_i, bib_i (0 ≤ rir_i, gig_i, bib_i ≤ 1,000).

Output

Your program is to write to standard output. Print exactly one line containing the minimum total color transfer, rounded to the sixth decimal point.

Examples3

  1. Example 1

    Input
    2 1
    36 16 85
    74 87 38
    
    Expected output
    4347.000000
    
  2. Example 2

    Input
    1 2
    12 26 90
    
    Expected output
    0.000000
    
  3. Example 3

    Input
    3 2
    93 50 26
    40 0 77
    99 10 29
    
    Expected output
    822.500000