第三天 C. Mind Control

11 篇文章 0 订阅
10 篇文章 0 订阅

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

思路如下:我一开始想的是贪心,发现写不出来。后来发现是枚举+暴力。枚举所有出现的情况,数据量也不大,以此取所有情况中,每一次选前面和选后面的最大值中的最小值即可
代码如下:

int T = 1;
    cin >> T;
    while(T --){
        cin >> n >> m >> k;
        rep(i, 1, n) {
            cin >> q[i];
        }
        int len = n - m + 1;
        for(int i = 1; i <= n - len + 1; i++) {
            Ma[i] = max(q[i], q[i + len - 1]);
        }
        k = min(m - 1, k);
        int res = 0;
        rep(l, 0, k) {
            int disr = k - l, ans = 0x3f3f3f3f;
            int r = n - disr - (len - 1);
            for(int i = l + 1; i <= r; i++) ans = min(ans, Ma[i]);
            res = max(res, ans);
        }
        printf("%d\n", res);
    }
    return 0;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值