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的那一层循环,是可以受自己控制的,因此我们要取最大值,这是对自己有利的条件。
代码如下:

#include<bits/stdc++.h>
#define ll long long
using namespace std;

const int maxx=4e3+100;
int a[maxx];
int n,m,k;

int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d%d%d",&n,&m,&k);
		memset(a,0,sizeof(a));
		for(int i=1;i<=n;i++) cin>>a[i];
		int ans=0;
		k=min(k,m-1);
		for(int i=0;i<=k;i++)//枚举可以控制的人中取左端的人数 
		{
			int ans1=1e9+100;
			for(int j=i+1;j<=i+m-k;j++)
			{
				ans1=min(ans1,max(a[j],a[j+n-m]));
			}
			ans=max(ans1,ans);
		}
		cout<<ans<<endl;
	}
	return 0;
}

努力加油a啊,(o)/~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

starlet_kiss

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值