#P8027. Contiguous Uniform Partitioning
Contiguous Uniform Partitioning
Contiguous Uniform Partitioning
Given a sequence of (n) Christmas lights with specific colors (a_i) and an integer (k), determine whether there exists a contiguous segment of the lights that can be evenly divided into (k) equal parts such that every part is composed of lights of the same color. In other words, if the segment is of length (L) (where (L) is divisible by (k)) and if you divide it into (k) parts each of length (\frac{L}{k}), every part must consist of identical color values. If such a segment is found, output the color of each of the (k) parts in order (separated by spaces); otherwise, output (-1).
inputFormat
The first line contains two integers (n) and (k). The second line contains (n) integers (a_1, a_2, \dots, a_n) representing the colors of the Christmas lights.
outputFormat
If a valid contiguous segment exists, output (k) integers where each integer represents the color of the corresponding uniform part. If no valid segment exists, output (-1).
sample
7 2
1 1 2 2 2 3 3
1 2