[codeforces830C]Bamboo Partition

time limit per test : 2 seconds
memory limit per test : 512 megabytes

分数:2500

Vladimir wants to modernize partitions in his office. To make the office more comfortable he decided to remove a partition and plant several bamboos in a row. He thinks it would be nice if there are n n n bamboos in a row, and the i i i-th from the left is ai meters high.

Vladimir has just planted n n n bamboos in a row, each of which has height 0 0 0 meters right now, but they grow 1 1 1 meter each day. In order to make the partition nice Vladimir can cut each bamboo once at any height (no greater that the height of the bamboo), and then the bamboo will stop growing.

Vladimir wants to check the bamboos each d d d days (i.e. d days after he planted, then after 2 ∗ d 2*d 2d days and so on), and cut the bamboos that reached the required height. Vladimir wants the total length of bamboo parts he will cut off to be no greater than k k k meters.

What is the maximum value d he can choose so that he can achieve what he wants without cutting off more than k k k meters of bamboo?

Input

The first line contains two integers n n n and k ( 1   ≤   n   ≤   100 , 1   ≤   k   ≤   1 0 11 ) k (1 ≤ n ≤ 100, 1 ≤ k ≤ 10^{11}) k(1n100,1k1011) — the number of bamboos and the maximum total length of cut parts, in meters.
The second line contains n n n integers a 1 ,   a 2 ,   . . . ,   a n ( 1   ≤   a i   ≤   1 0 9 ) a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) a1,a2,...,an(1ai109) — the required heights of bamboos, in meters.
Output

Print a single integer — the maximum value of d such that Vladimir can reach his goal.
Examples
Input

3 4
1 3 5

Output

3

Input

3 40
10 30 50

Output

32

Note

In the first example Vladimir can check bamboos each 3 days. Then he will cut the first and the second bamboos after 3 days, and the third bamboo after 6 days. The total length of cut parts is 2 + 0 + 1 = 3 meters.

题意:
给定一个 n ( n &lt; = 100 ) n(n&lt;=100) n(n<=100)一个 k ( k &lt; = 1 0 11 ) k(k&lt;=10^{11}) k(k<=1011)
n n n个数字 a 1 a_1 a1 a n a_n an
要求找到一个最大的 d d d使得 ∑ i = 1 n ( d ∗ ⌈ a i d ⌉ − a [ i ] ) &lt; = k \sum^n_{i=1}{(d*\lceil{a_i\over d}\rceil-a[i])} &lt;= k i=1n(ddaia[i])<=k
这个式子可以被表示成 d ∗ ∑ i = 1 n ⌈ a i d ⌉ &lt; = k + ∑ i = 1 n a i d*\sum^n_{i=1}{\lceil{a_i\over d}\rceil} &lt;= k+\sum^n_{i=1}a_i di=1ndai<=k+i=1nai
那么我们只要枚举 k + ∑ i = 1 n a i k+\sum^n_{i=1}a_i k+i=1nai的所有因数然后check就行了

#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n;
ll k,a[104],s[104];
ll calc(ll d){
    ll res=0;
    for(int i=1;i<=n;i++){
        ll g=a[i]/d;
        if(a[i]%d)++g;
        res+=g*d-a[i];
    }
    return res;
}
int main(){
    scanf("%d%lld",&n,&k);
    ll lim=k;
    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
        lim+=a[i];
    }
    ll ans=0;
    for(ll i=1;i<=sqrt(lim);i++){
        if(calc(i)<=k)ans=max(ans,i);
        if(calc(lim/i)<=k)ans=max(ans,lim/i);
    }
    printf("%lld\n",ans);
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值