River Hopscotch (minimum maximum of two points)

Source: Internet
Author: User

River Hopscotch
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 9923 Accepted: 4252

Description

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,&NBSP; L  units away from the Start (1≤&NBSP; L  ≤ 1,000,000,000). Along the river between the starting and ending Rocks,&NBSP; N   (0≤&NBSP; N  ≤50,000) more rocks appear, each at an integral Distance&NBSP; Di  from the start (0 <&NBSP; Di  <&NBSP; 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≤ mN).

FJ wants to know exactly how much he can increase the shortest distance *before* He starts removing the R Ocks.  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 how 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 M Rocks

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 jumping is a jump of 4 (from-to-or from-25): The end of the river There is a stone, and then you give you n stone, the position in the river, to ask the maximum minimum value after removing the M-block stone, the minimum value of the two-minute maximal, the second point is about the inside of the greater than equal to the question of judgment, you can think of when the L,r equal when the last judge of the good, l+1 jump Direct return l-1 is available; code:
#include <iostream> #include <algorithm> #include <cstdio> #include <cstring> #include < Cmath> #include <vector>using namespace std;const int inf=0x3f3f3f3f; #define MEM (x, y) memset (x,y,sizeof (×)) # Define SI (x) scanf ("%d", &x) #define PI (x) printf ("%d", x) #define T_T while (t--) const int Maxn=50010;int ROCK[MAXN]; int N,m;int js (int x) {int cnt=0;int last=rock[0];for (int i=1;i<=n+1;i++) {if (rock[i]-last<x) {cnt++;} else last=rock[i];} return CNT;} int erfen (int l,int r) {int Mid;while (l<=r) {mid= (l+r) >>1;if (JS (mid) >m) r=mid-1;//the equals sign, and the back becomes l-1 .... else l=mid+1;} return L-1;} int main () {int l;while (~scanf ("%d%d%d", &l,&n,&m)) {rock[0]=0;for (int i=1;i<=n;i++) SI (Rock[i]); rock[ N+1]=l;sort (rock,rock+n+2);p rintf ("%d\n", Erfen (0,l));} return 0;}

  

River Hopscotch (minimum maximum of two points)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.