2018 ACM-ICPC 青島站 E 貪心
阿新 • • 發佈:2018-11-07
#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; }