CF830C:Bamboo Partition(数学)

C. Bamboo Partition
time limit per test
2 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

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 bamboos in a row, and the i-th from the left is ai meters high.

Vladimir has just planted n bamboos in a row, each of which has height 0 meters right now, but they grow 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 days (i.e. d days after he planted, then after 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 meters.

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

Input

The first line contains two integers n and k (1 ≤ n ≤ 1001 ≤ k ≤ 1011) — the number of bamboos and the maximum total length of cut parts, in meters.

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — 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个植物,每天生长1,初始均为0,人每d天去视察这些植物,视察时可以剪掉植物任意长度,然后它就停止生长了,给出剪植物长度之和上限k,问d最大取多少可以做到不超过k下令所有植物达到目标高度。

思路:对于一颗植物,假设频率为d天,那么达到目标高度ai需要剪(ai-1)/d+1的长度,那么列条式子:


那么枚举这些数计算出d,再判断d能不能计算出这个数,就能更新ans了,因为sigma(ai-1)/d是单调的,所以枚举的数在一段区间内d=[l,r]都可能成立。

# include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL INF = 0x3f3f3f3f3f3f3f3f;
LL a[103];
int main()
{
    ios::sync_with_stdio(0), cin.tie(0);
    int n; LL k, imax=0;
    cin >> n >> k;
    for(int i=1; i<=n; ++i)
    {
        cin >> a[i];
        k += a[i];
        imax = max(imax, a[i]);
    }
    LL ans = 0;
    for(LL l=1;l<=imax;)
    {
        LL r = INF, sum = 0;
        for(int i=1; i<=n; ++i) if(a[i] > l) r = min(r, (a[i]-1)/((a[i]-1)/l));//最小的右界。
        for(int i=1; i<=n; ++i) sum += (a[i]-1)/l + 1;
        LL b = k/sum;
        if(b >= l && b <= r) ans = max(ans, b);
        l = r+1;
    }
    if(k/n > imax) ans = max(ans, k/n);
    cout << ans << '\n';
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值