二分答案
View Code
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
int n , m , l;
int stone[500005];
bool judge(int x)
{
int pos=0,cnt=0,id;
while(cnt<m)
{
cnt=cnt+1;
pos=pos+x;
id=upper_bound(stone+1,stone+1+n,pos)-(stone+1);
pos=stone[id];
if(pos==l)
return true;
}
return false;
}
int main()
{
int i,left,right,mid,ans;
while(scanf("%d%d%d",&l,&n,&m)!=EOF)
{
for(i=1;i<=n;i++)
scanf("%d",&stone[i]);
stone[n+1]=l;
n=n+1;
sort(stone+1,stone+1+n);
left=0,right=l;
while(left<=right)
{
mid=(left+right)>>1;
if(judge(mid))
{
right=mid-1;
ans=mid;
}
else
{
left=mid+1;
}
}
printf("%d\n",ans);
}
return 0;
}