Mind Control (思维)

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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值