topic:
analysis:
A look at this question, eh not to go half a d O (n) to check can not it do?
But in fact it is not dichotomous! ! Because not satisfied monotonic. For example, this set of data: a [i] = 4 k = 1 if d = 3, the will cut on day 6, cost = 2, d = 4, the will cut on day 4, cost = 0, apparent d more big, but the better! ! !
So half before it must consider whether monotone , since that when met, should also be a little counter-examples (This question is inside a small d is not met, but the big meet).
So not satisfied with how to do it -> descending enumeration, enumeration to meet on the first break away. D is the upper bound min {a [i]} + k (since k> = d-minn)
Of course, it will be T out.
So hand push equation:
And ai / d (the rounding) will find a duplicate, then consider divisible block (generally the block is divisible by the proof ): How divisible block
This question is divisible by the block to be proved. . .
#include<bits/stdc++.h> using namespace std; #define inf 2100000000 #define N 105 #define ll long long ll k,minn=inf,ans,a[N],sum; int n; bool fl[N]; int main() { freopen("cut.in","r",stdin); freopen("cut.out","w",stdout); scanf("%d%lld",&n,&k); sum=k; for(int i=1;i<=n;i++) scanf("%lld",&a[i]),sum+=a[i],minn=min(minn,a[i]); minn+=k; ll d=1; while(1){ ll tot=0; for(int i=1;i<=n;i++){ if(a[i]%d) tot+=(a[i]/d +1)*d;//讨论能不能整除 从而向上取整 else tot+=a[i]; } if(tot<=sum) ans=d; if(d>=minn) break; d=sum/(sum/(d+1)); } printf("%lld\n",ans); return 0; }