COCI '11 Contest 6 #5 Pastele

View as PDF

Submit solution


Points: 12 (partial)
Time limit: 5.0s
Memory limit: 256M

Problem types

Mirko recently got N crayons as a gift. The color of each crayon is a combination of three primary colors: red, green and blue. The color of the i^\text{th} crayon is represented with three integers: R_i for the red, G_i for the green and B_i for the blue component.

The difference between the i^\text{th} and the j^\text{th} crayon is \max(|R_i - R_j|, |G_i - G_j|, |B_i - B_j|). The colorfulness of a subsequence of crayons is equal to the largest difference between any two crayons in the subsequence.

Mirko needs a subsequence with K crayons with the smallest colorfulness for his drawing. The subsequence does not have to be consecutive. Find it!

Input Specification

The first line of input contains integers N and K (2 \leq K \leq N \leq 100\,000).

The i^\text{th} of the following N lines contains three integers R_i, G_i and B_i (0 \leq R_i, G_i, B_i \leq 255).

Output Specification

The first line of output should contain the smallest colorfulness of a subsequence with K crayons.

The following K lines should contain the R, G and B values of the colors of the crayons in the subsequence, in any order. Any subsequence that yields the smallest colorfulness will be accepted.

Scoring

In test cases worth 50\% of total points, 0 \leq R_i, G_i, B_i \leq 20 will hold.

In test cases worth additional 30\% of total points, 0 \leq R_i, G_i, B_i \leq 50 will hold.

Sample Input 1

2 2
1 3 2
2 6 4

Sample Output 1

3
1 3 2
2 6 4

Sample Input 2

3 2
3 3 4
1 6 4
1 1 2

Sample Output 2

2
3 3 4
1 1 2

Sample Input 3

5 3
6 6 4
6 2 7
3 1 3
4 1 5
6 2 6

Sample Output 3

2
6 2 7
4 1 5
6 2 6

Comments

There are no comments at the moment.