标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others)
Total Submission(s): 4218 Accepted Submission(s): 2051
#include<iostream> #include<cstdio> #include<string> #include<cstring> #include<cmath> #include<algorithm> #include<cstdlib> #include<queue> #include<vector> #include<stack> #include<set> using namespace std; int L,n,m,a[500005],b[500005]; int main() { while(scanf("%d%d%d",&L,&n,&m)!=EOF) { int temp=0,dis=0; a[0]=0; for(int i=1;i<=n;i++) scanf("%d",&a[i]); a[n+1]=L; sort(a,a+1+n); for(int i=1;i<=n+1;i++) { b[++temp]=a[i]-a[i-1]; if(b[temp]>dis) dis=b[temp]; } int l,r,mid,ans=0; l=dis,r=L; while(l<=r) { int tp=0,num=0; mid=(l+r)>>1; for(int i=1;i<=temp;i++) { if(tp+b[i]>mid) { num++; tp=b[i]; } else { tp+=b[i]; } } num++; if(num<=m) { ans=mid; r=mid-1; } else l=mid+1; } printf("%d\n",ans); } return 0; }
标签:
原文地址:http://www.cnblogs.com/a972290869/p/4403388.html