Washer
Time limit1sMemory limit512 MB
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 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 , , denote the amount of red, green, blue color of the -th clothes. When clothes are washed together, the color transfer is defined by
where , , and are the averages of , , , respectively. The -th clothes with , , and is defined as a point 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 clothes into at most 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 clothes and , 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 (1 ≤ ≤ 100) and (1 ≤ ≤ 2). In the following lines, the -th line contains three integers , , (0 ≤ , , ≤ 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.