BZOJ1650: Jumping stones

Source: Internet
Author: User

1650: [Usaco2006 dec]river Hopscotch jumping stone time limit:5 Sec Memory limit:64 MB
submit:345 solved:230
[Submit] [Status] [Discuss] 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 fr Om the start (1 <= L <= 1,000,000,000). Along the between the starting and ending Rocks, N (0 <= N <= 50,000) more rocks appear, each at a integral D Istance 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'll has 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 R Ocks.

There are n stones on the axis, the coordinates of the first I stone are Di, and now I want to jump from 0 to L, each time the bar jumps from one stone to the next. Now FJ allows you to remove the M-stone and ask how much the minimum value of the distance from the adjacent two stones will be when the M-stone is removed.

Input

* Line 1:three space-separated integers:l, N, and M * Lines 2..n+1:each line contains a ' integer indicating how F Ar some rock is 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 Input25 5 2
2
14
11
21st
17

5 rocks at distances 2, one, +, +, and 21. Starting rock at position
0, finishing rock at position 25.Sample Output4hint

Before removal, the shortest distance is between the stone and the starting point of position 2, and the shortest distance becomes 21 between 17 and 21 or 25 and 4 after removing position 2 and position 142 stones.

Source

Silver

Or a two-point answer.

D--------------------------------------------------------------------------------

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <deque>
using namespace Std;
const int nmax=50005;
int A[nmax];
int N,m,k,ans;
int PD (int x) {
int tmp=0;
int cur=0;
for (int i=1;i<=n;i++) {
if (a[i]-a[cur]<x) {
tmp++;
if (tmp>k) return 0;
}
Else
Cur=i;
}
return 1;
}
int main () {
scanf ("%d%d%d", &m,&n,&k);
for (int i=1;i<=n;i++) {
scanf ("%d", &a[i]);
}
Sort (a+1,a+n+1);
a[0]=0;
A[++n]=m;
int L=0;int r=m;
while (l<=r) {
int m= (L+R)/2;
if (PD (m)) {
Ans=m;
l=m+1;
}
Else
R=m-1;
}
printf ("%d\n", ans);
return 0;
}

---------------------------------------------------------------------------------

BZOJ1650: Jumping stones

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.