Problem list
Log in
#coci00225 · COCI 2011/2012 Contest 6

Pastele

Platinum III 5.0 s 256 MB

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^{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^{th} and the j^{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

The first line of input contains integers N and K ($2 \le K \le N \le 100,000$). The i^{th} of the folowing N lines contains three integers R_{i}, G_{i} and B_{i} ($0 \le R_{i}$, G_{i}, $B_{i} \le 255$).

Output

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.

Constraints

In test cases worth 50% of total points, $0 \le R_{i}$, G_{i}, $B_{i} \le 20$ will hold. In test cases worth additional 30% of total points, $0 \le R_{i}$, G_{i}, $B_{i} \le 50$ will hold.

Example 1

Input
2 2
1 3 2
2 6 4
Output
3
1 3 2
2 6 4

Example 2

Input
3 2
3 3 4
1 6 4
1 1 2
Output
2
3 3 4
1 1 2

Example 3

Input
5 3
6 6 4
6 2 7
3 1 3
4 1 5
6 2 6
Output
2
6 2 7
4 1 5
6 2 6
Source
COCI 2011/2012 Contest 6
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code