Description
Every year the cows hold an event featuring a peculiar version of hopscotch that involves carefully jumping from rock to rock in a river. the excitement takes place on a long, straight river with a rock at the start and another rock at the end,LUnits away from the start (1 ≤L≤ 1,000,000,000). Along the river between the starting and ending rocks,N(0 ≤N≤ 50,000) More rocks appear, each at an integral distanceDiFrom 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 only 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 his cows and watches this event each year. but as time goes by, he tires of watching the timid cows of the other farmers limp compression ss the short distances between rocks placed too closely together. he plans to remove several rocks in order to increase the shortest distance a cow will have to jump to reach the end. he knows he cannot remove the starting and ending rocks, but he calculates that he has enough resources to remove upMRocks (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 has to jump after removing the optimal setMRocks.
Input
Line 1: three space-separated integers:
L,
N, And
M
Lines 2 ..
N+ 1: each line contains a single integer indicating how far some rock is away from the starting rock. No two rocks share the same position.
Output
Line 1: A single integer that is the maximum of the shortest distance a cow has to jump after removing
MRocks
Sample Input
25 5 2214112117
Sample output
4
The shortest distance and the shortest distance after the stone is removed must be
Then we can divide the results into two parts in this interval to see if the shortest distance between the two parts can meet the solution for removing M stones.
# Include <stdio. h> # include <string. h >#include <algorithm> using namespace STD; # define up (I, x, y) for (I = x; I <= y; I ++) # define down (I, x, y) for (I = x; I> = y; I --) # define MEM (a, B) memset (A, B, sizeof (A) # define W (a) While (a) # define ll long longint A [50005]; int main () {int L, n, m, I, j, K, Minn, maxn, mid, sum, CNT; W (~ Scanf ("% d", & L, & N, & M) {Minn = 1000000005; maxn = L; A [0] = 0, A [n + 1] = L; up (I, 1, n) scanf ("% d", & A [I]); N ++; sort (, A + n); up (I, 1, n) Minn = min (Minn, a [I]-A [I-1]); W (Minn <= maxn) {mid = (maxn + Minn)> 1; CNT = sum = 0; up (I, 1, n) {If (sum + = A [I]-A [I-1]) <= mid) CNT ++; else // several consecutive stone distances and greater than mid, then clear the continuous distance from 0 and reenumerate sum = 0;} If (CNT <= m) Minn = Mid + 1; else maxn = mid-1 ;} printf ("% d \ n", Minn);} return 0 ;}