# |BZOJ 1650|二分|贪心|[Usaco2006 Dec]River Hopscotch 跳石子

BZOJ 1650
Luogu 2855
from: USACO 2006 Dec Sliver(USACO刷题第9题)

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stack>
#include<vector>
#define ms(i, j) memset(i, j, sizeof i)
#define LL long long
using namespace std;

const int MAXN = 50000 + 5;

int L, n, m, st[MAXN];

int check(int x) {
int tot = 0, l = 0, r = 1;
while (l<n) {
while (r<n&&st[r]-st[l]<x) r++;
tot += r - l - 1;
l = r;
}
}
void clear() {}
void init() {
clear();
for (int i=1;i<=n;i++) scanf("%d", &st[i]);
sort(st+1, st+1+n);
st[0] = 0, st[++n] = L;
}
void solve() {
int ans = 0, l = 0, r = L + 1;
while (l<r) {
int mid = (l+r)>>1;
if (check(mid)) {
ans = mid;
l = mid + 1;
} else r = mid;
}
printf("%d\n", ans);
}
int main() {
#ifndef ONLINE_JUDGE
freopen("1.in", "r", stdin);freopen("1.out", "w", stdout);
#endif
while (scanf("%d%d%d", &L, &n, &m)==3) init(), solve();
return 0;
}

10-26 377
12-18 94
08-23 2817
09-07 70
11-25 6470
05-29 294
05-30 615
05-02 645