Mind Controltime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

You and your n−1 friends have found an array of integers a1,a2,…,an. You have decided to share it in the following way: All n

of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for himself. He then gets out of line, and the next person in line continues the process.

You are standing in the m-th position in the line. Before the process starts, you may choose up to k

different people in the line, and persuade them to always take either the first or the last element in the array on their turn (for each person his own choice, not necessarily equal for all people), no matter what the elements themselves are. Once the process starts, you cannot persuade any more people, and you cannot change the choices for the people you already persuaded.

Suppose that you’re doing your choices optimally. What is the greatest integer x such that, no matter what are the choices of the friends you didn’t choose to control, the element you will take from the array will be greater than or equal to x

?

Please note that the friends you don’t control may do their choice arbitrarily, and they will not necessarily take the biggest element available.Input

The input consists of multiple test cases. The first line contains a single integer t (1≤t≤1000

)  — the number of test cases. The description of the test cases follows.

The first line of each test case contains three space-separated integers n, m and k (1≤mn≤3500, 0≤kn−1

)  — the number of elements in the array, your position in line and the number of people whose choices you can fix.

The second line of each test case contains n positive integers a1,a2,…,an (1≤ai≤109

)  — elements of the array.

It is guaranteed that the sum of n over all test cases does not exceed 3500

.Output

For each test case, print the largest integer x such that you can guarantee to obtain at least x

.ExampleInputCopy

OutputCopy

Note

In the first test case, an optimal strategy is to force the first person to take the last element and the second person to take the first element.

  • the first person will take the last element (5

) because he or she was forced by you to take the last element. After this turn the remaining array will be [2,9,2,3,8]; the second person will take the first element (2) because he or she was forced by you to take the first element. After this turn the remaining array will be [9,2,3,8]; if the third person will choose to take the first element (9), at your turn the remaining array will be [2,3,8] and you will take 8 (the last element); if the third person will choose to take the last element (8), at your turn the remaining array will be [9,2,3] and you will take 9

  • (the first element).

Thus, this strategy guarantees to end up with at least 8. We can prove that there is no strategy that guarantees to end up with at least 9. Hence, the answer is 8

.

In the second test case, an optimal strategy is to force the first person to take the first element. Then, in the worst case, both the second and the third person will take the first element: you will end up with 4.

官方题解

People behind you are useless, ignore them. Let’s assume that km−1

. It’s always optimal to control as many people as possible.

Your strategy can be summarized by a single integer x, the number of people you force to take the first element (among the k

you control).

Similarly, the strategy of your opponents can be summarized by a single integer integer y

, the number of non-controlled friends who choose to take the first element.

When it will be your turn, the array will contain exactly nm+1 elements. You will be able to take the biggest element among the first element a1+x+y and the last element a1+x+y+(nm)

.

These observations lead to an obvious O(n2) solution (iterate over all strategies x and for each strategy, iterate over all cases y

), which was sufficient to pass the tests.

However, the second iteration can be easily optimized with a data structure.

Let’s note bi=max(a1+i,a1+i+(nm)). The final answer is maxx∈[0;k][miny∈[0;m−1−k]bx+y]

.

Note that it can be rewritten as maxx∈[0;k][miny′∈[x;x+m−1−k]by′]

.

It can be computed in O(nlogn) using segment tree or in O(n) using monotonic deque.

我只先搞了一个o(n)的做法

最后修改日期:2020年2月12日

作者

留言

撰写回覆或留言

发布留言必须填写的电子邮件地址不会公开。