Every year the cows hold an event featuring a peculiar version of hopscotch that involves carefully jumping from rock to R Ock in a river. The excitement takes place in a long, straight river with a rock at the start and another rock at the end, L unit S away from the start (1≤ L ≤1,000,000,000). Along the between the starting and ending rocks, N (0≤ n ≤50,000) more rocks appear Integral distance di from the start (0 < di < L).
To play the game, each cow in turn starts at the starting rock and tries to reach the finish at the ending rock, jumping O Nly from rock to rock. Of course, less agile cows never make it to the final rock, ending up instead in the river.
Farmer John is proud of he cows and watches this event each year. But as time goes by, he tires of watching the timid cows of the other farmers limp across the short distances between rock s placed too closely together. He plans to remove several rocks on order to increase the shortest distance a cow would have the to jump to reach the end. He knows he cannot remove the starting and ending rocks, but he calculates that he had enough resources to remove up to m Rocks (0≤ M ≤ N).
FJ wants to know exactly how much he can increase the shortest distance *before* He starts removing the rocks. Help Farmer John determine the greatest possible shortest distance a cow have to jump after removing the optimal set of m Rocks.
Input
Line 1:three space-separated integers:
L,
N, and
M
Lines 2..
N+1:each line contains a single integer indicating what far some rock was away from the starting rock. No Rocks share the same position.
Output
Line 1: A single integer which is the maximum of the shortest distance A cow have to jump after removing
MRocks
Sample Input
25 5 2214112117
Sample Output
4
Hint
Before removing any rocks, the shortest jump is a jump of 2 from 0 (the start) to 2. After removing the rocks at 2 and, the shortest required jump was a jump of 4 (from-to-or from-25).
/* Minimum maximum */#include <cstdio> #include <cstring> #include <algorithm>using namespace Std;int L, N, M;int Minn;int a[500000 + 100];int min1;bool Check (int x) {int cout = 0; int pos = 0; Min1 = 1e9 + 10; for (int i = 1; I <= N + 1; i++) {if (A[i]-pos < x) {cout++; } else {min1 = min (min1,a[i]-POS); pos = A[i]; }} if (cout <= M) {return true; } return false;} int main () {while (~scanf ("%d%d%d", &l, &n, &m)) {memset (A, 0, sizeof (a)); for (int i = 1; I <= N; i++) scanf ("%d", &a[i]); Sort (A + 1, a + N + 1); A[N+1] = L; Minn = 0; int L = 0, r = 1e9 + 10; int res = 0; while (L <= r) {int mid = (L + r) >> 1; if (check (mid)) {L = mid + 1; Minn = MAX (minn, min1); } else R = mid-1; } printf ("%d\n",Minn); } return 0;}
poj3258--two--river Hopscotch