C. Mind Control

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≤m≤n≤3500, 0≤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 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.

Example

inputCopy

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

outputCopy

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 (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.

题目大意:

总共有n个人和n个数字

n个人拍成一队,n个数字也是有顺序的

你排在第m个位置

按照顺序的每个人可以拿走这个序列中的第一个数字或者最后一个数字

你可以在所有人操作开始前说服最多k个人

让他们固定拿这个序列的第一个或者是最后一个数字

问你在所有可能的情况中可以拿到的数字的最大值中的最小值(即,到你取得的时候,首尾两个数字你总是会取最大的那个,问这些数字中的最小值)



AC代码:

#include <bits/stdc++.h>
using namespace std;
const int INF=0x3f3f3f3f;
int a[3510];
int main()
{
int T,n,m,k;
cin>>T;
while(T--)
{
cin>>n>>m>>k;
k=min(k,m-1);
for (int i = 1; i <= n; i++)
cin>>a[i];
int ans = 0;
for (int i = 0; i <= k; i++)
{
int mn = INF;
for (int j = i + 1; j <= m - k + i; j++)
mn = min(mn, max(a[j], a[j + n - m]));
ans = max(ans, mn);
}
cout<<ans<<endl;
}
return 0;
}

Codeforces 1291 Round #616 (Div. 2) C. Mind Control(超级详细)的更多相关文章

  1. Codeforces 1291 Round #616 (Div. 2) B

    B. Array Sharpening time limit per test1 second memory limit per test256 megabytes inputstandard inp ...

  2. Codeforces Round #616 (Div. 2) C. Mind Control

    题目链接:http://codeforces.com/contest/1291/problem/C 思路: 我们可以很容易想到,只有前m-1个人才能影响m的选择的大小,后面的人无法影响. 如果所有人都 ...

  3. Codeforces Beta Round #80 (Div. 2 Only)【ABCD】

    Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...

  4. Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】

    Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...

  5. Codeforces Beta Round #79 (Div. 2 Only)

    Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...

  6. Codeforces Beta Round #77 (Div. 2 Only)

    Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...

  7. Codeforces Beta Round #76 (Div. 2 Only)

    Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...

  8. Codeforces Beta Round #75 (Div. 2 Only)

    Codeforces Beta Round #75 (Div. 2 Only) http://codeforces.com/contest/92 A #include<iostream> ...

  9. Codeforces Beta Round #74 (Div. 2 Only)

    Codeforces Beta Round #74 (Div. 2 Only) http://codeforces.com/contest/90 A #include<iostream> ...

随机推荐

  1. stand up meeting 1/12/2016

    part 组员                工作              工作耗时/h 明日计划 工作耗时/h    UI 冯晓云  UI测试和调整:页面跳转调整    3 查漏补缺,扫除UI b ...

  2. mysql中show status介绍一

    公司产品运用到mysql集群,集群遇到问题时,需要查看集群状态,使用到命令show status,今天趁机将show status中的各个变量的含义研究一下. 状态名 作用域 详细解释 Aborted ...

  3. 22-Java-Hibernate框架(二)

    Hibernate的了解.Hibernate的搭建.Hibernate的基本使用流程等内容请阅读21-Java-Hibernate(一) 五.Hibernate的Query查询接口(重中之重) 1.H ...

  4. 5. iphone 的:active样式

    如果给按钮定义 :hover 样式,在 iPhone 上按钮点击一次是 hover 态,再点击一次 hover 态才会消失,这不是我们想要的,继而想通过定义 :active 样式来实现按钮按下时的效果 ...

  5. 小知识点:session的存放位置

    在php.ini里的配置session.save_path是注释掉的,那么Seesion保存的路径在不同类型操作系统保存在什么位置? Linux: /tmp 或 /var/lib/php/sessio ...

  6. 浅析 CSS 中的边距重叠

    浅析 CSS 中的边距重叠 边距重叠是什么 在说边距重叠之前,先以正常的思维来考虑如果你现在是浏览器引擎遇到这种情况应该怎么办? 现在有两个元素 div1 和 div2 紧挨着,中间没有它元素,它们的 ...

  7. Pycharm 操作数据库

    view--->Tool Buttons,点击Pycharm右侧的Database 1.连接数据库       2.建立一个表,添加数据   通过以上操作把用户名和密码储存到了数据库中  3.连 ...

  8. 负载均衡服务之HAProxy基础配置(四)

    前文我们聊了haproxy的状态页配置,状态页中显示各参数的含义,以及基于cookie做会话保持的配置,回顾请参考https://www.cnblogs.com/qiuhom-1874/p/12776 ...

  9. 2020年必须掌握的硬核技能k8s

    Kubernetes 是一个软件系统,使你在数以万计的电脑节点上运行软件时就像 所有节点是以单个大节点一样, 它将底层基础设施抽象,这样做同时简化了应用开发.部署,以及对开发和运维团队的管理. Kub ...

  10. Mac安装多版本JDK

    0. 配置JDK环境 安装完成之后,配置.bash_profile文件 使用source ./bash_profile激活 2. 如何切换默认的jdk? 使用java -version就可以看默认版本 ...