2018 ACM-ICPC 青岛站 E 贪心

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/fanbaobao829/article/details/83722611
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
typedef long long ll;
ll a[maxn],b[maxn];
int n;
bool check(ll level,ll sum)
{
    for(int i=1;i<=n;i++)
    {
        sum--;
        ll tp=(level+a[i]-1ll)/a[i]-b[i-1];
        b[i]=max(0ll,tp-1ll);
        if(tp<=0ll)
            continue;
        sum-=b[i]*2;
        if(sum<0)
            return false;
    }
    return true;
}
int main()
{
    int t;
    ll m;
    scanf("%d",&t);
    while(t--&&scanf("%d%lld",&n,&m)!=EOF)
    {
        for(int i=1;i<=n;i++)
            scanf("%lld",a+i);
        ll l=0ll,r=1e13,mid;
        while(l<r)
        {
            mid=(l+r+1ll)>>1;
            if(check(mid,m))
                l=mid;
            else
                r=mid-1ll;
        }
        printf("%lld\n",l);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/fanbaobao829/article/details/83722611