题目描述

这项比赛将在一条笔直的河道中进行,河道中分布着一些巨大岩石。组委会已经选择好了两块岩石作为比赛起点和终点。在起点和终点之间,有 NN 块岩石(不含起点和终点的岩石)。在比赛过程中,选手们将从起点出发,每一步跳向相邻的岩石,直至到达终点。

为了提高比赛难度,组委会计划移走一些岩石,使得选手们在比赛过程中的最短跳跃距离尽可能长。由于预算限制,组委会至多从起点和终点之间移走 MM 块岩石(不能移走起点和终点的岩石)。

输入输出格式

输入格式:

第一行包含三个整数 L,N,ML,N,M ,分别表示起点到终点的距离,起点和终点之间的岩石数,以及组委会至多移走的岩石数。保证 L \geq 1L≥1 且 N \geq M \geq 0N≥M≥0 。

接下来 NN 行,每行一个整数,第 ii 行的整数 D_i( 0 < D_i < L)D

i

​ (0<D

i

​ <L) , 表示第 ii 块岩石与起点的距离。这些岩石按与起点距离从小到大的顺序给出,且不会有两个岩石出现在同一个位置。

输出格式:

一个整数,即最短跳跃距离的最大值。

输入输出样例

输入样例#1:

25 5 2

2

11

14

17

21

输出样例#1:

4

说明

输入输出样例 1 说明:将与起点距离为 22 和 1414 的两个岩石移走后,最短的跳跃距离为 44 (从与起点距离 1717 的岩石跳到距离 2121 的岩石,或者从距离 2121 的岩石跳到终点)。

另:对于 20%20% 的数据, 0 ≤ M ≤ N ≤ 100≤M≤N≤10 。

对于 50%50% 的数据, 0 ≤ M ≤ N ≤ 1000≤M≤N≤100 。

对于 100%100% 的数据, 0 ≤ M ≤ N ≤ 50,000,1 ≤ L ≤ 1,000,000,0000≤M≤N≤50,000,1≤L≤1,000,000,000 。

#include<cstdio>
#include<string>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<cstring>
#include<set>
#include<queue>
#include<algorithm>
#include<vector>
#include<map>
#include<cctype>
#include<stack>
#include<sstream>
#include<list>
#include<assert.h>
#include<bitset>
#include<numeric>
#define debug() puts("++++")
#define gcd(a,b) __gcd(a,b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define fi first
#define se second
#define pb push_back
#define sqr(x) ((x)*(x))
#define ms(a,b) memset(a,b,sizeof(a))
#define sz size()
#define be begin()
#define pu push_up
#define pd push_down
#define cl clear()
#define lowbit(x) -x&x
#define all 1,n,1
#define rep(i,x,n) for(int i=(x); i<(n); i++)
#define in freopen("in.in","r",stdin)
#define out freopen("out.out","w",stdout)
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;
const int INF = 0x3f3f3f3f;
const LL LNF = 1e18;
const int maxn = 1e5 + 20;
const int maxm = 1e6 + 10;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int dx[] = {-1,1,0,0,1,1,-1,-1};
const int dy[] = {0,0,1,-1,1,-1,1,-1};
int dir[4][2] = {{0,1},{0,-1},{-1,0},{1,0}};
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int L,n,m;
int a[maxn];
/*
25 5 2
2
11
14
17
21 4
发现如果两个点之间距离小于最小跳跃距离, 那么就必须将其中一个石子移去.假设这两个点之前所有石子已经满足要求了, 发现如果移去前一个石子, 可是前一个石子与它前面的石子本来就大于最短距离, 移去后后面的石子与再后面的石子可能还是大于最短距离;  
如果移走后面的石子, 不会改变前面石子, 那么它前面石子与后面的石子的距离减小了, 也就是.
*/
int check(int x)
{
int now=0,cnt=0;
rep(i,0,n+1)
{
if(a[i]-now<x) cnt++;//如果距离小于我二分的答案x,那么这块石头需要搬走
else now = a[i]; //不然我就跳过来
}
return cnt<=m;
}
void solve()
{
int l=0,r=L,mid,ans;
while(l<=r)
{
mid = (l+r)/2;
if(check(mid))
{l=mid+1;ans=mid;}
else r=mid-1;
}
printf("%d\n",ans);
}
int main()
{
while(~scanf("%d%d%d",&L,&n,&m))
{
rep(i,0,n)
{
scanf("%d",&a[i]);
}
a[n]=L;
solve();
}
}

最新文章

  1. 当web.config文件放置在共享目录下(UNC),启动IIS会提示有错误信息500.19,伴随有错误代码0x80070003和错误代码0x80070005的解决办法
  2. 运行JSP时出现The requested resource (/proj3/MyJsp.jsp) is not available.(亲测有用)
  3. RHEL/CentOS/Fedora各种源(EPEL、Remi、RPMForge、RPMFusion)配置
  4. C语言位运算详解
  5. Android -- FragmentTabHost实现微信底部切换
  6. ug-Assertion failure in [MyClass layoutSublayersOfLayer:]
  7. Razor语法学习
  8. Gdb 常用命令
  9. 201521123121 《Java程序设计》第5周学习总结
  10. iOS初学,关于变量加下划线问题
  11. 11 个超棒的 jQuery 分步指引插件
  12. Moving or disabling the package cache for Visual Studio 2017
  13. 获取ip地址&amp;&amp;测试ip地址
  14. OSGB数据压缩
  15. golang 的时间格式化操作
  16. 使用ts-loader与webpack编译typescripts出现Module build failed: TypeError: Cannot read property &#39;afterCompile&#39; of undefined
  17. 2018-2019 2 20165203 《网络对抗技术》 Exp1 PC平台逆向破解
  18. BZOJ2333 [SCOI2011]棘手的操作 堆 左偏树 可并堆
  19. Spring 3.1新特性之二:@Enable*注解的源码,spring源码分析之定时任务Scheduled注解
  20. POJ 1948 Triangular Pastures

热门文章

  1. float与定位的区别
  2. [洛谷P1420]最长连号
  3. [BJOI2006]狼抓兔子——最小割转对偶图最短路
  4. 【NOIP模拟赛】藏宝图 最小生成树
  5. HZOI String STL的正确用法
  6. codevs 1191 线段树 区间更新(水)
  7. Qt 设置应用程序图标(windows)
  8. 常见通用的 JOIN 查询
  9. 汕头市队赛 SRM16 T2
  10. codeforces B. Okabe and Banana Trees 结论题