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 #488 (Div. 2) 总结

    [Codeforces]Round #488 (Div. 2) 总结 比较僵硬的一场,还是手速不够,但是作为正式成为竞赛生的第一场比赛还是比较圆满的,起码没有FST,A掉ABCD,总排82,怒涨rat ...

  3. Codeforces Beta Round #75 (Div. 1 Only) B. Queue 线段树。单点更新

    http://codeforces.com/problemset/problem/91/B 题意: 给你n个数,求得i 到n中小于a[i]的最右边的a[j],然后求a[i]到a[j]之间包含了多少个数 ...

  4. Codeforces Beta Round #22 (Div. 2 Only) E. Scheme(DFS+强连通)

    题目大意 给了 n(2<=n<=105) 个点,从每个点 u 出发连向了一个点 v(共 n 条边) 现在要求添加最少的边使得整个图是一个强连通图 做法分析 这道题千万不要一般化:先求强连通 ...

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

    Codeforces Beta Round #4 (Div. 2 Only) A 水题 1 #include<bits/stdc++.h> 2 using namespace std; 3 ...

  6. Codeforces Round #616 (Div. 2)B. Array Sharpening

    B. Array Sharpening 题目链接-Array Sharpening 题目大意 给你一个序列a[],要求你找出k(1<k<n)使得k位置之前数字是严格单调递增,k之后是严格单 ...

  7. Codeforces Round #616 (Div. 2)(题解)

    写在前面: 疫情严重,希望武汉与中国一起加油. 这次就做出两题,第三题没读完,实在是比较慢. A. Even But Not Even time limit per test1 second memo ...

  8. 【Codeforces】Round #375 (Div. 2)

    Position:http://codeforces.com/contest/723 我的情况 啊哈哈,这次raiting肯定要涨,接受过上次的教训,先用小号送肉,大号都是一发切,重回蓝咯 结果... ...

  9. Codeforces Beta Round #92 (Div. 1 Only) A. Prime Permutation 暴力

    A. Prime Permutation 题目连接: http://www.codeforces.com/contest/123/problem/A Description You are given ...

最新文章

  1. POJ1564 Sum It Up(DFS)
  2. 丢掉uVision2吧,uVision早就有了
  3. 高清SDI编码器|上海视涛科技
  4. 进程通信学习笔记(管道)
  5. Oracle递归操作
  6. webstorm两个文件比对_webstorm/phpstorm配置连接ftp快速进行文件比较(上传下载/同步)操作...
  7. python websocket库 安装_Python WebSocket
  8. linux下时间同步的两种方法分享
  9. iOS vs. Android,应用设计该如何对症下药?
  10. Apollo进阶课程㉙丨Apollo控制技术详解——控制器的类型
  11. win8消费者预览版Chrome无法设置默认浏览器
  12. 求链式线性表的倒数第K项 (20 分)
  13. SVN服务器的本地搭建和使用
  14. hdu 4336 Card Collector 容斥原理 多校联合赛(四) 第六题
  15. access设置 dolby_Dolby Access免费版
  16. 《推荐系统实践》(一)好的推荐系统
  17. 2022年四方系统/四方支付系统部署实战,以及细节讨论,Gitee版本
  18. 把已有项目转换成Visual Studio的解决方案
  19. Songtaste,酷到不行的音乐网站
  20. Embedded Browser WindowsPC内嵌网页

热门文章

  1. Failed to capture snapshot of output files for task ' :packagePreDebug' property ''outputDirectory'
  2. c语言 程序循环,C语言程序设计-循环例子
  3. PADS Layout VX.2.3 制作PCB封装(Decal)时,导入DXF文件
  4. mac ntfs读写插件的双十一活动已经开始啦
  5. 企业“数据压力锅”即将爆炸,CIO该如何防止爆锅?
  6. ftp列表错误,flashfxp列表错误,ftp无法列目录的解决方法
  7. 前端学PHP之面向对象系列第六篇——简单图形面积计算器实现
  8. [2]-使用busybox-1.17.2制作文件系统
  9. 阻尼衰减曲线用python_高阻尼隔震橡胶支座结构及防震效果
  10. 解决 Windows 系统使用 Homestead 运行 Laravel 本地项目响应缓慢问题