Mind Control CodeForces - 1291C(思维)
You and your n?1n?1 friends have found an array of integers a1,a2,…,ana1,a2,…,an. You have decided to share it in the following way: All nn 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 mm-th position in the line. Before the process starts, you may choose up to kk 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 xx 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 xx?
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 tt (1≤t≤10001≤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 nn, mm and kk (1≤m≤n≤35001≤m≤n≤3500, 0≤k≤n?10≤k≤n?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 nn positive integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109) — elements of the array.
It is guaranteed that the sum of nn over all test cases does not exceed 35003500.
Output
For each test case, print the largest integer xx such that you can guarantee to obtain at least xx.
Example
Input
4
6 4 2
2 9 2 3 8 5
4 4 1
2 13 60 4
4 1 3
1 2 2 1
2 2 0
1 2
Output
8
4
1
1
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 (55) 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][2,9,2,3,8];
the second person will take the first element (22) 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][9,2,3,8];
if the third person will choose to take the first element (99), at your turn the remaining array will be [2,3,8][2,3,8] and you will take 88 (the last element);
if the third person will choose to take the last element (88), at your turn the remaining array will be [9,2,3][9,2,3] and you will take 99 (the first element).
Thus, this strategy guarantees to end up with at least 88. We can prove that there is no strategy that guarantees to end up with at least 99. Hence, the answer is 88.
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 44.
很好的一道思維題目!!
題意:一共有n位人,我排在第m位。有n個數字,從第一個人開始拿,每個人拿的時候只能拿第一位或者最后一位的數字。現在我有k次機會去說服別人拿第一位或者最后一位。問我最后拿到的數字,一定能拿到的最大值是多少?(就像第一個樣例,一定會拿到8,有可能會拿到九)
思路:貪心可知,說服的人越多,結果會更優。并且說服的人越靠前,結果會更優。因為越靠前就越可以安排對自己更好的情況發生。一共有k次機會,那么我們就會使用min(m-1,k)次機會。輪到我拿的時候,一定是剩下n-m+1個數字,這種情況一共有m個,我們可以事先預處理出可能的答案(也可以不用預處理)。對于那k個人,這里面有從前面開始拿的,也有從后面開始拿的,這就需要我們遍歷找最優的了。數據量不大,O(n*n)可以接受。
我們假設有i個人從前面開始拿,那么剩下的k-i個人從后面開始拿,但是還有m-k+1個人是不受控制的,所以可以供我選擇的區間是[i+1,i+1+m-k+1]這一段。在這一個區間里面找到有可能的答案,取最小值。為什么取最小值的,因為那m-k+1個人是不受控制的,所以我們要考慮最差情況。但是對于i的那一層循環,是可以受自己控制的,因此我們要取最大值,這是對自己有利的條件。
代碼如下:
努力加油a啊,(o)/~
總結
以上是生活随笔為你收集整理的Mind Control CodeForces - 1291C(思维)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Yet Another Walking
- 下一篇: Array Sharpening Cod