[除法分块] Codeforces 830C Bamboo Partition

[除法分块] Codeforces 830C Bamboo Partition_第1张图片

#include
#include
using namespace std;
const int maxn=100005;
typedef long long LL;
int n,a[maxn];
LL K,sum_a,now,_max,ans;
int main(){
//  freopen("cf830C.in","r",stdin);
//  freopen("cf830C.out","w",stdout);
    scanf("%d%I64d",&n,&K);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]), sum_a+=a[i], _max=max(_max,(LL)a[i]-1);
    for(LL d=1,nxt;d<=_max;d=nxt+1){
        nxt=1e+18; now=0;
        for(int i=1;i<=n;i++) if(a[i]-1>=d){
            now+=(a[i]-1)/d;
            nxt=min(nxt,(a[i]-1)/((a[i]-1)/d));
        }
        LL res=(K+sum_a)/(now+n);
        if(d<=res) ans=max(ans,min(res,nxt));
    }
    if(_max<(K+sum_a)/n) ans=max(ans,(K+sum_a)/n);
    printf("%I64d\n",ans);
    return 0;
} 

你可能感兴趣的:([除法分块] Codeforces 830C Bamboo Partition)