Codeforces 1291 Round #616 (Div. 2) C. Mind Control(超级详细)
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(超级详细)的更多相关文章
- Codeforces 1291 Round #616 (Div. 2) B
B. Array Sharpening time limit per test1 second memory limit per test256 megabytes inputstandard inp ...
- Codeforces Round #616 (Div. 2) C. Mind Control
题目链接:http://codeforces.com/contest/1291/problem/C 思路: 我们可以很容易想到,只有前m-1个人才能影响m的选择的大小,后面的人无法影响. 如果所有人都 ...
- Codeforces Beta Round #80 (Div. 2 Only)【ABCD】
Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...
- Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】
Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...
- Codeforces Beta Round #79 (Div. 2 Only)
Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...
- Codeforces Beta Round #77 (Div. 2 Only)
Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...
- Codeforces Beta Round #76 (Div. 2 Only)
Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...
- Codeforces Beta Round #75 (Div. 2 Only)
Codeforces Beta Round #75 (Div. 2 Only) http://codeforces.com/contest/92 A #include<iostream> ...
- Codeforces Beta Round #74 (Div. 2 Only)
Codeforces Beta Round #74 (Div. 2 Only) http://codeforces.com/contest/90 A #include<iostream> ...
随机推荐
- Vulnhub DC-5靶机渗透
信息搜集 老样子,先找到靶机IP和扫描靶机 nmap -sP 192.168.146.0/24 #找靶机ip nmap -sS -Pn -A 192.168.146.141 #扫描端口 这次开的是80 ...
- C语言 文件操作(三)
1.fputs() int fputs(const char *s, FILE *stream); s 代表要输出的字符串的首地址,可以是字符数组名或字符指针变量名. stream 表示向何种流中输出 ...
- boost multi_index简单了解
#include <string> #include <iostream> #include <boost/multi_index_container.hpp> # ...
- Visual C++ 6.0踩坑记录---在Win10下安装Visual C++ 6.0安装成功后点击“打开”按钮闪退问题
前言: 为了更好的学习C及C++,前段时间下载了Microsoft Visual C++ 6.0(以下简称VC6),原因是VC6具有查看反汇编代码.监视内存.寄存器等功能,并且因为本人正在学习滴水逆向 ...
- 002-IDE的使用与数据类型-C语言笔记
002-IDE的使用与数据类型-C语言笔记 学习目标 1.[了解]IDE并熟悉Xcode基本使用技巧 2.[理解]C程序的入口和运行流程 3.[理解]变量的声明赋值和一些细节 4.[理解]变量的命名规 ...
- AJ学IOS(35)UI之Quartz2D仿真支付宝手势解锁_代理获得密码。
AJ分享,必须精品 效果: 实现步骤 其实这个实现起来不难 第一步先放好主要的UI,一张背景图和一个View 第二部就是把9个button放到view中,设置好按钮的默认和选中图片. 注意:创建时候的 ...
- Ant安装与配置
1. 到apache 官网去下载最新版本的ant,http://ant.apache.org/:下载后直接解压缩到电脑上,不需要安装: 2.环境变量配置: 2.1 ->计算机右键->属性- ...
- 【Tool】在Windows系统上,下载和安装当前最新版本的IDEA 2020-4-14
下载 & 安装 IDEA 下载部分: 官网地址:https://www.jetbrains.com/idea/ 直接点击鲜眼的DOWNLOAD 如果仅仅是想简单接触学习下Java语言,社区版的 ...
- Django系列操作
每次用到都去百度找....找的还不行~~得自己改~~耗时耗力虽然不难~~~直接贴代码记录下方便自己用~~~~ Django之分页 定义成一个块,直接引用到对应的位置即可... <div clas ...
- Missing artifact net.sf.json-lib:json-lib:jar:2.2.3
<!-- https://mvnrepository.com/artifact/net.sf.json-lib/json-lib --><dependency> <gro ...