Problem D for Train 2
Задачу добавил: elena
Успешно сдано решений: 14
Problem D. Distinct colors
Author: A. Klenin
Input file: input.txt Time limit: 2 sec
Output file: output.txt Memory limit: 64 Mb
Statement
Colors on computer screen are represented by (r, g, b) triplets, where r, g, b are integer intensities of red, green and blue components.
Two colors (r1, g1, b1) and (r2, g2, b2) are distinct if min(|r1 - r2|, |g1 - g2|, |b1 - b2|) >= D.
Your program will be given N (not necessarily distinct) colors. It must either calculate K new colors that are distinct from each other and from all initial colors, or determine that it is impossible.
Input file format
Input file contains numbers N K D followed by N triplets ri gi bi, representing initial colors.
Output file format
Output file must contain K triplets rj gj bj, representing resulting distinct colors. If there is no solution, output must contain a single number -1. If there is more than one solution, output any of them.
Constraints
0 <= ri, gi, bi <= 255 for both input and output colors,
0 <= N <= 256, 1 <= D, K <= 256
Sample tests
Sample input 1
2 1 10
255 100 100
100 100 255
Sample output 1
110 110 110
Sample input 2
2 1 200
255 100 100
100 100 255
Sample output 2
-1