# 【二分枚举】修补木桶

### 样例说明

8 2 3
8 1 9 2 3 4 7 5

7

//
//  Created by TaoSama on 2016-08-21
//
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <vector>

using namespace std;
#define pr(x) cout << #x << " = " << x << "  "
#define prln(x) cout << #x << " = " << x << endl
const int N = 1e3 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;

int n, m, L;
int a[N];

bool check(int x) {
vector<int> b(a, a + n);
for(int t = 0; t < n; ++t) {
int bk = b.back(); b.pop_back();
b.insert(b.begin(), bk);

int lft = m, ok = 1;
for(int i = 0; i < n && ok;) {
if(b[i] >= x) ++i;
else {
i += L;
if(--lft < 0) ok = 0;
}
}
if(ok) return true;
}
return false;
}

int main() {
#ifdef LOCAL
freopen("C:\\Users\\TaoSama\\Desktop\\in.txt", "r", stdin);
//  freopen("C:\\Users\\TaoSama\\Desktop\\out.txt","w",stdout);
#endif
ios_base::sync_with_stdio(0);

scanf("%d%d%d", &n, &m, &L);
for(int i = 0; i < n; ++i) scanf("%d", &a[i]);

int l = 1, r = 1e9 + 10, ans = -1;
while(l <= r) {
int m = l + r >> 1;
if(check(m)) ans = m, l = m + 1;
else r = m - 1;
}
printf("%d\n", ans);

return 0;
}


#### hihocoder #1362 : 修补木桶（二分）

2016-08-26 00:26:19

#### hiho 修补木桶(二分)

2018-03-14 21:52:52

#### hihocoder 1362 修补木桶

2016-08-21 14:39:09

#### 算法原理系列：木桶排序

2017-05-31 23:57:37

#### hihocoder 修补木桶

2016-11-03 21:22:01

#### Hihocoder #1362 : 修补木桶 (二分)

2016-08-21 19:44:25

#### HihoCoder 1362-修补木桶(二分)

2018-05-10 16:53:09

#### 二分和枚举（主要是二分思想）

2016-03-15 12:50:57

#### 每日一题之 hiho193 修补木桶

2018-05-26 15:07:56

#### hihocoder #1362 : 修补木桶(二分+dp)

2016-09-01 17:06:24