1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| #include<cstdio> #include<iostream> #include<cstring> #define ll long long using namespace std; ll a[99999],n,m,l,dp[51999],f,d[99999]; int check(int x){ int ans=0; int t=d[1]; for(int i=1;i<=n;i++) { if(t>=x){ t=d[i+1]; } else { ans++; t+=d[i+1]; } } return ans; } int main(){ scanf("%lld%lld%lld",&l,&n,&m); if(m==n||m==0){ printf("%lld",l); return 0; } a[0]=1; a[n+1]=l; for(ll i=1;i<=n+1;i++) { scanf("%lld",&a[i]); d[i]=a[i]-a[i-1]; } /*memset(dp,127,sizeof(dp)); for(ll i=1;i<=n+1;i++) for(ll j=1;j<=m;j++) for(ll k=1;k<=j;k++) { ll q=min(dp[j],a[i]-a[i-k]); ll w=min(dp[j-k],a[i+1]-a[i-k]); dp[j]=max(q,w); } printf("%lld",dp[m]);*/ int r=l,le=1; while(le<=r){ int mid=(le+r)>>1; int w=check(mid); //printf("%d ",w); if(w>m) r=mid-1; else le=mid+1; } printf("%d",r); }
|