bzoj1650

时间:2023-03-08 16:21:54

题解:

二分答案

然后贪心

代码:

#include<bits/stdc++.h>
using namespace std;
const int N=;
int n,m,l,a[N];
int pd(int x)
{
int last=,num=;
for (int i=;i<=n;i++)
if (a[i]-a[last]<x)num++;
else last=i;
return num<=m;
}
int main()
{
scanf("%d%d%d",&l,&n,&m);
a[]=;
for (int i=;i<=n+;i++)scanf("%d",&a[i]);
a[n+]=l;
n+=;
sort(a+,a+n+);
int l=,r=1e9;
while (l<r)
{
int mid=(l+r+)/;
if (pd(mid))l=mid;
else r=mid-;
}
printf("%d",l);
}