#include<iostream> #include<cstdio> #include<set> #include<cmath> #include<algorithm> typedef long long ll; ll* a; int N,K; bool cmp(ll a,ll b) { return a < b; } bool fun(ll mid) { if(mid == 0 ) return true; int count = 0; for(int i = 1;i < N;i++) { count += (a[i] - a[i - 1]) / mid; if((a[i] - a[i - 1]) % mid == 0) count--; if(count > K) { return false; } } return true; } int main() { scanf("%d%d",&N,&K); a = new ll[N]; for(int i = 0;i < N;i++) { scanf("%lld",&a[i]); } std::sort(a,a + N,cmp); ll Max = 0; for(int i = 1;i < N;i++) { Max = std::max(Max,a[i] - a[i - 1]); } ll start = 0,end = Max,now,mid; while(start <= end) { mid = (start + end) / 2; if(fun(mid)) { now = mid; end = mid - 1; } else { start = mid + 1; } } std::cout<<now; return 0; }
全部评论
(2) 回帖