题解 Codeforces Round #616 (Div. 2) (CF1291)
作者:互联网
C:
n个元素,n个人轮流取数,可以取数组头或尾元素,你在第m轮取,并且你可以控制k个人取什么元素,问你能取得最大元素是多少(前面的人不一定都取最大的)
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 4e3; const int inf = 0x3f3f3f3f; int a[maxn]; inline const int read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = (x << 3) + (x << 1) + ch - '0'; ch = getchar(); } return x * f; } inline void write(int x) { if (x < 0) { putchar('-'); x = -x; } if (x > 9) write(x / 10); putchar(x % 10 + '0'); } int main() { #ifdef ONLINE_JUDGE #else freopen("input.txt", "r", stdin); #endif int t = read(); while (t--) { int n = read(), m = read(), k = read(), ans = 0; k = min(k, m - 1); for (int i = 1; i <= n; i++) a[i] = read(); for (int i = 0; i <= k; i++) // 枚举前k个人取左端数目,也就是强制k-i个放在右边 { int mn = inf; for (int j = i + 1; j <= i + m - k; j++) // 枚举后(m-k-1)个人取完后的左端点,不受控制的人从0个到m-k个排在左边 mn = min(mn, max(a[j], a[j + n - m]));///这里就是可取的两端了 ans = max(ans, mn); } write(ans); putchar(10); } return 0; }
D
标签:ch,const,int,题解,元素,616,Codeforces,read,while 来源: https://www.cnblogs.com/hgangang/p/12256759.html