#P11012. 「ALFR Round 4」B 颜料

    ID: 12206 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>树状数组O2优化双指针 two-pointer

「ALFR Round 4」B 颜料

Background

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

Problem Description

Xiaoshan has a total of nn paintings, and each painting has its main paint. Specifically, the main paint type of the ii-th painting is aia_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 ll-th to the rr-th) is i=1Wj=i+1Wmin(ci,cj)\sum_{i=1}^W\sum_{j=i+1}^W\min(c_i,c_j), where cic_i is the number of times paint type ii appears in the exhibition, and WW is the value range of all paint types.

Now Xiaoshan wants to know: to make the exhibition's brilliance at least kk, what is the minimum number of consecutive paintings that must be selected? If there is no exhibition whose brilliance is at least kk, output 1-1.

Input Format

There are two lines.

The first line contains two integers n,kn,k, with meanings as described in the Description.

The second line contains nn integers. The ii-th integer is aia_i, representing the main paint type of the ii-th painting.

Output Format

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

10 6
2 3 4 3 3 4 2 4 9 2
5

Hint

Sample Explanation

Choose paintings 55 to 99 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 i=19j=i+19min(ci,cj)=6\sum_{i=1}^9\sum_{j=i+1}^9\min(c_i,c_j)=6. It is easy to see that 55 is the shortest length of a valid segment.

Constraints

Subtask Points Constraints
00 1010 All ai(1in)a_i(1\le i\le n) are the same
11 2020 n,ai102n,a_i\le10^2
22 7070 -

For 100%100\% of the testdata, 1n,ai2×1061\le n,a_i\le2\times10^6, 1k10151\le k\le 10^{15}.

Translated by ChatGPT 5