River hopscotch (noiopenjudge, noip2015)

description

The cows each year hold various special version of hopscotch game, including a jump from one rock to another rock in the river. This exciting activities in a long straight river, at the start and far from the starting point of L (1 ≤ L≤ 1,000,000,000) are at the end of a rock. Between the start and end, there are N (0 ≤ N ≤ 50,000) a rock, the rock and the distance of each origin are Di (0 <Di <L).

During the race, the cow turns from the starting point, try to reach the end of each step can only jump from one rock to another rock. Of course, the strength of bad cows is no way to accomplish their goals.

Farmer John is proud of his cows every year and watched the game. But over time, watching the timid cows to other farmers in the close proximity between the rocks slowly forward, he felt very tired. He plans to remove some rocks, so that from the beginning to the end of the course, the shortest distance the longest jump. He may be removed in addition to at most M of the start and end points (0 ≤ M ≤ N) th rock.

Please help John to remove these rocks is determined, the longest possible distance is the shortest jump How much?

Entry

The first line contains three integers L, N, M, separated by a single space between the adjacent two integers.

Next N rows, each row an integer that represents the start point of the distance of each rock. Rock press and given distance from the starting point near to, and do not have two rocks appear in the same position.

Export

An integer longest jump the shortest possible distance.

Sample input

25 5 2
2
11
14
17
21

Sample Output

4

prompt

After removal of the rock 2 and 14 located between the two shortest hop distance is 4 (from 17 to 21 or from 21 to 25).

Restrictions and conventions

Time limit: 1s

Space limitations: 128MB

#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn = 50000 + 10 ;
int dis[maxn];
int main()
{
//    freopen("stone.in","r",stdin);
//    freopen("stone.out","w",stdout);
    int L,n,m;
    cin>>L>>n>>m;
    for(int i=1;i<=n;i++)
        scanf("%d",&dis[i]);
    int l=1,r=L;
    sort(dis+1,dis+n+1);
    while(l<r)
    {
        int i,mid = ( l + r + 1 ) >> 1,pos(0),temp(0);
        for(i=1;i<=n;i++)
        {
            if(dis[i]+mid>L) break;
            if(dis[i]-pos<mid) temp++;
            else pos = dis[i];
        }
        temp+=n-i+1;
        if(temp<=m) l=mid;
        else r=mid-1;
    }
    cout<<l<<endl;
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/hfang/p/11239892.html