2503: 【普及/提高-】【P2678】跳石头

内存限制:128 MB 时间限制:1.000 S
评测方式:文本比较 命题人:
提交:1 解决:1

题目描述

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

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

输入

第一行包含三个整数 lns="http://www.w3.org/1998/Math/MathML">,,,分别表示起点到终点的距离,起点和终点之间的岩石数,以及组委会至多移走的岩石数。保证 lns="http://www.w3.org/1998/Math/MathML">1 且 lns="http://www.w3.org/1998/Math/MathML">0

接下来 lns="http://www.w3.org/1998/Math/MathML"> 行,每行一个整数,第 lns="http://www.w3.org/1998/Math/MathML"> 行的整数 lns="http://www.w3.org/1998/Math/MathML">(0<<), 表示第 lns="http://www.w3.org/1998/Math/MathML"> 块岩石与起点的距离。这些岩石按与起点距离从小到大的顺序给出,且不会有两个岩石出现在同一个位置。

输出

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

样例输入 复制

25 5 2 
2
11
14
17 
21

样例输出 复制

4

提示

输入输出样例 1 说明

将与起点距离为 lns="http://www.w3.org/1998/Math/MathML">2和 lns="http://www.w3.org/1998/Math/MathML">14 的两个岩石移走后,最短的跳跃距离为 lns="http://www.w3.org/1998/Math/MathML">4(从与起点距离 lns="http://www.w3.org/1998/Math/MathML">17 的岩石跳到距离 lns="http://www.w3.org/1998/Math/MathML">21 的岩石,或者从距离 lns="http://www.w3.org/1998/Math/MathML">21 的岩石跳到终点)。

数据规模与约定

对于 lns="http://www.w3.org/1998/Math/MathML">20%的数据,lns="http://www.w3.org/1998/Math/MathML">010
对于 lns="http://www.w3.org/1998/Math/MathML">50% 的数据,lns="http://www.w3.org/1998/Math/MathML">0100
对于 lns="http://www.w3.org/1998/Math/MathML">100%的数据,lns="http://www.w3.org/1998/Math/MathML">050000,1109

#include<bits/stdc++.h>
using namespace std;
int n,m,l,d,a[50005];

bool P(int x) {
	int cnt=0,i=0,t=1;
	while (t<=n+1) {
		if (a[t]-a[i]>=x) {
			cnt++;
			i=t;
		}
		t++;
	}
	return cnt>=(n+1-m);
	
}

int find(int L,int R) {
	int ans=0;
	while (L<=R) {
		int mid=(L+R)>>1;
		if (P(mid)) {
			ans=mid;
			L=mid+1;
		}
		else {
			R=mid-1;
		}
	}
	return ans;
} 


int main(){
	scanf("%d %d %d",&l,&n,&m);
	int L=1e9,R=0;
	for (int i=1;i<=n;i++) {
		scanf("%d",&a[i]);
		L=min(L,a[i]-a[i-1]);
	}
	a[n+1]=l;
	L=min(L,a[n+1]-a[n]);
	R=a[n+1];
	printf("%d",find(L,R));
	return 0;
}