1 solutions
-
0
#include<bits/stdc++.h> using namespace std; int l,n,k; int a[100005]; int L,R; bool check(int dis){ int cnt=0; for(int i=0;i<=n;i++){ if(a[i+1]-a[i]>dis){ cnt+=(a[i+1]-a[i])/dis; if((a[i+1]-a[i])%dis==0) cnt--; } if(cnt>k) return false;//不满足条件 } return true;//满足条件 } int main(){ scanf("%d%d%d",&l,&n,&k); for(int i=1;i<=n;i++) scanf("%d",&a[i]); sort(a+1,a+n+1); L=0;R=10000005;//表示懒得动脑qwq a[0]=0;//注意题目的坑点,前后都不能丢 a[n+1]=l; int ans; while(L<R){ int mid=(L+R)/2; if(check(mid)) R=mid; else L=mid+1; } cout<<L; }
- 1
Information
- ID
- 1248
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- 6
- Tags
- # Submissions
- 49
- Accepted
- 14
- Uploaded By