#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
//typedef __int64 LL;
int a[500005];
bool is(double x,int n,int m)
{
int count=0;
int sum=0;
for(int i=0;i<=n;i++)
{
sum += a[i];
if(sum>x) {count++;sum = a[i];}
}
if(sum>0) count++;
if(count>m)return false;
else return true;
}
int main()
{
int l;
int n,m;
while(scanf("%d%d%d",&l,&n,&m)!=EOF)
{
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
sort(a,a+n);
a[n]=l;
int sum=a[0];
double max = (double)l/m;
for(int i=1;i<=n;i++)
{
a[i]-=sum;
sum +=a[i];
if(max<a[i]) max = a[i];
}
double low=max,high = l,mid=(low+high)/2;
while(fabs(high-low)>1e-3)
{
mid = (high+low)/2.0;
if(is(mid,n,m)) high=mid;
else low = mid;
}
if(n==0||m==1)printf("%d\n",l);
else
printf("%d\n",(int)(mid+0.5));
}
return 0;
}
hdu 4004 二分法
最新推荐文章于 2021-05-22 20:38:30 发布