P11012 "ALFR Round 4" B Paint

Background

In Xiaoshan's view, an art exhibition is brilliant because of different colors.

Description

Xiaoshan has a total of $n$ paintings, and each painting has its main paint. Specifically, the main paint type of the $i$-th painting is $a_i$. Xiaoshan can choose a segment of paintings with **consecutive indices** to form an exhibition. The brilliance of the exhibition (suppose it consists of paintings from the $l$-th to the $r$-th) is $\sum_{i=1}^W\sum_{j=i+1}^W\min(c_i,c_j)$, where $c_i$ is the number of times paint type $i$ appears in the exhibition, and $W$ is the value range of all paint types. Now Xiaoshan wants to know: to make the exhibition's brilliance at least $k$, what is the minimum number of consecutive paintings that must be selected? If there is no exhibition whose brilliance is at least $k$, output $-1$.

Input Format

There are two lines. The first line contains two integers $n,k$, with meanings as described in the **Description**. The second line contains $n$ integers. The $i$-th integer is $a_i$, representing the main paint type of the $i$-th painting.

Output Format

Output one integer in a single line, which is the answer.

Explanation/Hint

### Sample Explanation Choose paintings $5$ to $9$ to form an exhibition. Then $c_1=0,c_2=1,c_3=1,c_4=2,c_5=0,c_6=0,c_7=0,c_8=0,c_9=1$, and $\sum_{i=1}^9\sum_{j=i+1}^9\min(c_i,c_j)=6$. It is easy to see that $5$ is the shortest length of a valid segment. ### Constraints | Subtask | Points | Constraints | | :----------: | :----------: | :----------: | | $0$ | $10$ | All $a_i(1\le i\le n)$ are the same | | $1$ | $20$ | $n,a_i\le10^2$ | | $2$ | $70$ | - | For $100\%$ of the testdata, $1\le n,a_i\le2\times10^6$, $1\le k\le 10^{15}$. Translated by ChatGPT 5