#P10059. Choose

    ID: 9068 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>贪心二分单调队列洛谷原创O2优化前缀和st表洛谷月赛

Choose

Description

Given a sequence aa of length nn.

You need to select kk different contiguous subsequences of aa, all with length LL (1Lnk+1)(1\le L\le n-k+1): $C(a,l_1,l_1+L-1),C(a,l_2,l_2+L-1),\dots,C(a,l_k,l_k+L-1)$, where 1l1<l2<<lknL+11\le l_1<l_2< \dots< l_k\le n-L+1.

Let the minimum range among these kk subsequences be XX. You need to find the maximum possible value of XX. Also, when XX is maximized, you need to find the minimum possible value of LL.

Input Format

This problem contains multiple test cases.

The first line contains an integer TT, the number of test cases.

For each test case:

  • The first line contains two integers n,kn,k.
  • The second line contains nn integers a1,a2,,ana_1,a_2,\dots,a_n.

Output Format

For each test case:

  • Output one line with two integers X,LX,L, representing the required range and the subsequence length.
3
5 1
1 2 3 4 5
5 2
1 2 3 4 5
5 3
1 2 3 4 5
4 5
3 4
2 3
2
5 1
1 2 2 2 3
5 2
1 2 2 2 3
2 5
1 2

Hint

[Sample 1 Explanation]

  • When k=1k=1, the maximum possible range is at most 44. One shortest valid choice is [1,2,3,4,5][1,2,3,4,5].
  • When k=2k=2, the maximum possible range is at most 33. One shortest valid choice is [1,2,3,4][1,2,3,4] and [2,3,4,5][2,3,4,5].
  • When k=3k=3, the maximum possible range is at most 22. One shortest valid choice is [1,2,3][1,2,3], [2,3,4][2,3,4], and [3,4,5][3,4,5].

[Constraints and Notes]

This problem uses bundled testdata.

Subtask Score nn\le kk\le Special Property
11 55 10510^5 nn All aia_i are equal
22 11 Testdata is randomly generated
33 1010 100100 nn The required XX is at most 10310^3
44 2020 None
55 10410^4
66 4040 10510^5

For 100%100\% of the testdata, 1T101\le T\le 10, 1n1051\le n\le 10^5, 1kn1\le k\le n, 109ai109-10^9\le a_i\le 10^9.

Translated by ChatGPT 5