专栏首页CSDN旧文Codeforces 1291 Round #616 (Div. 2) C. Mind Control(超级详细)

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

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

我来说两句

0 条评论
登录 后参与评论

相关文章

  • CodeForces - 140A New Year Table (几何题)当时没想出来-----补题

    A. New Year Table time limit per test2 seconds memory limit per test256 megaby...

    风骨散人Chiam
  • ZOJ 3623 Battle Ships

    Battle Ships Time Limit: 2 Seconds Memory Limit: 65536 KB Battle Ships is a ne...

    风骨散人Chiam
  • Codeforces Round #622 (Div. 2) 1313 C1

    C1. Skyscrapers (easy version) time limit per test1 second memory limit per te...

    风骨散人Chiam
  • 什么是SAP物料主数据里的Batch

    Materials are produced and theoretically have the same properties. Nevertheless ...

    Jerry Wang
  • POJ-1953 World Cup Noise(线性动规)

    World Cup Noise Time Limit: 1000MS Memory Limit: 30000K Total Submissio...

    ShenduCC
  • How to find “hidden” remote jobs using Google Search.

    By using a special search operator with Google search, you can find remote jobs ...

    仇诺伊
  • ABAP如何在调试查看EXPORT/IMPORT 内存数据

    These memory IDs can be accessed in the debugger, but the option isn't accessibl...

    matinal
  • 使用SAP Transaction Launcher将ABAP Webdynpro嵌入到WebClient UI中

    THINK twice why you want to include an ABAP webdynpro component into CRM UI, as ...

    Jerry Wang
  • 使用SAP Transaction Launcher将ABAP Webdynpro嵌入到WebClient UI中

    THINK twice why you want to include an ABAP webdynpro component into CRM UI, as ...

    Jerry Wang
  • ZOJ 3623 Battle Ships

    Battle Ships Time Limit: 2 Seconds Memory Limit: 65536 KB Battle Ships is a ne...

    风骨散人Chiam

扫码关注云+社区

领取腾讯云代金券