题解:
二分答案
然后贪心
代码:
#include<bits/stdc++.h> using namespace std; const int N=50005; int n,m,l,a[N]; int pd(int x) { int last=1,num=0; for (int i=2;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[1]=0; for (int i=2;i<=n+1;i++)scanf("%d",&a[i]); a[n+2]=l; n+=2; sort(a+1,a+n+1); int l=0,r=1e9; while (l<r) { int mid=(l+r+1)/2; if (pd(mid))l=mid; else r=mid-1; } printf("%d",l); }