oing 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.
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
Out:
8
4
1
1
代码:
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 3510;
int a[N];
const int mod = 1e9 + 7;
signed main()
{
int t; cin >> t;
while(t--){
int n,m,k; cin >> n >> m >> k;
for(int i = 1;i <= n;i++) cin >> a[i];
k = min(m-1,k);
int ans = 0;
for(int i = 0;i <= k;i++){//枚举控制选取左端的数量。
int L = i+1,R = n-k+i;//当选取左边数为i,则不能控制区间就在L,到R。我们取L到R中最小的即可
int c = 1e9;
for(int j = 0;j <= m - k - 1;j++){// 在控制别人选之后,自己选之前,还有m-k-1个人要选择。
//但是他们选择是不可控制的,所以取所有左右段最大值的最小值。
c = min(c,max(a[L + j] , a[R - (m-k-1) + j]));
}
//
ans = max(c,ans);
}
cout << ans <<endl;
}
return 0;
}