#P11012. Exhibition Brilliance
Exhibition Brilliance
Exhibition Brilliance
You are given n paintings arranged in a row. The i-th painting has a main pigment type denoted by ai. You can select a contiguous segment of these paintings to form an exhibition. Let the chosen segment be from index l to r, and for each pigment type i (with i=1,2,...,W where W is the total number of possible pigment types), let ci denote the number of paintings in the segment whose pigment is type i.
The brilliance of the exhibition is defined as
Your task is to determine the minimum length of a contiguous segment such that its brilliance is at least k
. If no such segment exists, output -1
.
Note: If a pigment type does not appear in the segment, then its count is zero.
inputFormat
The first line contains two integers n
and k
(1 ≤ n ≤ 105, 0 ≤ k ≤ 1012), representing the number of paintings and the required minimum brilliance, respectively.
The second line contains n
integers a1, a2, ..., an
(1 ≤ ai ≤ 109), where ai
denotes the pigment type of the i-th painting.
outputFormat
Output a single integer representing the minimum number of consecutive paintings required for an exhibition with brilliance at least k
. If no valid exhibition exists, output -1
.
sample
5 4
1 2 2 1 3
5