POJ 3258 River Hopscotch (the largest of the two min.)

Source: Internet
Author: User

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,L units 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 Ntegral distancedi 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≤ MN).

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


The main idea: Remove the M-Block stone (without the starting and ending stones) in the N-Block stone and find the maximum distance from the minimum distance in the topic.

Train of thought: two points problem.


 #include <iostream> #include <algorithm> #include <cstdio> #include <cstring> #include <cmath> #include <math.h> #define LL long long#define inf 0x3f3f3f3fusing namespace    Std;int A[50010];int Main () {int n,m,j,k,l;        while (~SCANF ("%d%d%d", &l,&n,&m)) {for (int i=1;i<=n;i++) scanf ("%d", &a[i]);        Sort (a+1,a+n+1);        a[0]=0;//will begin and end with the stone also added.        A[n+1]=l;        int low=0,high=l;        int pos,sum;        int ans;            while (High>=low) {sum=0;            int mid= (High+low) >>1;            pos=0;                The for (int i=1;i<=n+1;i++) if (a[i]-a[pos]<mid)//is smaller than the assumed minimum value when deleting sum++;            else pos=i;            if (sum>m) high=mid-1;                else {low=mid+1;            Ans=mid;    }} printf ("%d\n", ans); }}



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

POJ 3258 River Hopscotch (the largest of the two min.)

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.