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 distance 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 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 across 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 up to 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 has to jump after removing the optimal set of M rocks.

Input

Line 1: Three space-separated integers: LN, 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 M rocks

Sample Input

25 5 2
2
14
11
21
17

Sample Output

4

Hint

Before removing any rocks, the shortest jump was a jump of 2 from 0 (the start) to 2. After removing the rocks at 2 and 14, the shortest required jump is a jump of 4 (from 17 to 21 or from 21 to 25).
 
#include<iostream>
#include<algorithm>
using namespace std;
int pos[];
int l,n,m; bool C(int d){
int last=;
for(int i=;i<n-m;i++){
int cur=last+;
while(cur<n&&pos[cur]-pos[last]<d)
cur++;
if(cur==n)
return false;
last=cur;
}
return true;
} int main(){
cin>>l>>n>>m;
for(int i=;i<n;i++){
cin>>pos[i];
}
pos[n++]=;
pos[n++]=l;
sort(pos,pos+n);
int lb=,ub=l+;
while(ub-lb>){
int mid=(ub+lb)/;
if(C(mid))
lb=mid;
else
ub=mid;
}
cout<<lb<<endl;
return ;
}

POJ3258--River Hopscotch(Binary Search similar to POJ2456)的更多相关文章

  1. POJ--3258 River Hopscotch (最小值最大化C++)

    River Hopscotch Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 15273   Accepted: 6465 ...

  2. POJ3258 River Hopscotch 2017-05-11 17:58 36人阅读 评论(0) 收藏

    River Hopscotch Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 13598   Accepted: 5791 ...

  3. POJ3258 River Hopscotch —— 二分

    题目链接:http://poj.org/problem?id=3258 River Hopscotch Time Limit: 2000MS   Memory Limit: 65536K Total ...

  4. poj3258 River Hopscotch(二分最小值,好题)

    https://vjudge.net/problem/POJ-3258 二分最小值,判断需要删去的点的个数,如果大于给定,则直接return 0,则说明该数需要再小. 最后注意,起点是0终点是l,起点 ...

  5. POJ3258 River Hopscotch

    地址 别人的代码,自己边界总是控制不好,还不知道哪里错了!思维!这种问题代码越简洁反而越不容易错吧.. #include<stdio.h> #include<algorithm> ...

  6. POJ3258 River Hopscotch(二分最大化最小值)

    题目链接:http://poj.org/problem?id=3258 题意:给n个石头,起点和终点也是两个石头,去掉这石头中的m个,使得石头间距的最小值最大. 思路:二分石头间的最短距离,每次贪心地 ...

  7. Algo: Binary search

    二分查找的基本写法: #include <vector> #include <iostream> int binarySearch(std::vector<int> ...

  8. River Hopscotch(二分POJ3258)

    River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9263 Accepted: 3994 Descr ...

  9. 96. Unique Binary Search Trees

    题目: Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For e ...

随机推荐

  1. log4net引用了Mysql.Data.dll,但是就是不能写到mysql数据库的解决办法

    这两天遇到log4net写日志到mysql数据库中,有时候在A项目中可以,有时候B项目就有问题,有时候测试环境没问题,到正式部署环境又出问题,经过两天的煎熬,终于理清楚了其中的头绪. 1.配置现状 c ...

  2. Vue 1.0 和 2.0 执行顺序

    // Vue 生命周期 // Vue 1.0 // 执行步骤:选项/生命周期钩子 // 1 init // 2 created // 3 beforeCompile // 4 compiled // ...

  3. C# oracle 日期型字段,使用参数传值时,遇到ORA-01810: format code appears twice错误

    C#操作oracle数据库时,发现使用to_date('2014-01-03 18:00:00','yyyy-mm-dd hh:MM:ss')时,会出现ORA-01810: format code a ...

  4. 将文件中的内容读取到map中,并排除不需要的关键字然后输出

  5. L1-033 出生年(15)(STL-set代码)

    L1-033 出生年(15 分) 以上是新浪微博中一奇葩贴:"我出生于1988年,直到25岁才遇到4个数字都不相同的年份."也就是说,直到2013年才达到"4个数字都不相 ...

  6. PAT 1027 打印沙漏(20)(思路)

    1027 打印沙漏(20)(20 分) 本题要求你写个程序把给定的符号打印成沙漏的形状.例如给定17个"*",要求按下列格式打印 ***** *** * *** ***** 所谓& ...

  7. Eclipse.Error.gen already exists but is not a source folder.

    在Eclipse ADT来开发Android App时会遇到以下问题:"myproject/gen already exists but is not a source folder. Co ...

  8. UI设计教程分享:设计一个高质量的logo要从哪方面入手呢?

    有的人觉得logo只是一个简单的图形,对品牌影响无关紧要:但有的人却觉得logo对品牌有较大的影响.其实logo承载着一个公司的品牌形象.公司背景.公司理念等.就像Landor往往给一个企业做logo ...

  9. Spring IOC(一)体系结构

    Spring IOC(一)体系结构 Spring 系列目录(https://www.cnblogs.com/binarylei/p/10198698.html) BeanFactory 是Spring ...

  10. [linux]Linux如何查看文件中的中间部分内容

    最基本的是cat.more和less. 1. 如果你只想看文件的前5行,可以使用head命令,如: head -5 /etc/passwd 2. 如果你想查看文件的后10行,可以使用tail命令,如: ...