rt,自认为判断掉了所有的边界情况,但还是WA 2个点:
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll p[200010];
int n;
ll m;
ll chk(ll x){
ll res=0;
for(int i=1;i<=n;i++){
ll tmp=(x/p[i]+1)/2;
if(tmp==0) continue;
if(m/tmp/tmp/p[i]==0) return 0;
res+=tmp*tmp*p[i];
if(res>m) return 0;
}
return 1;
}
int main(){
scanf("%d%lld",&n,&m);
for(int i=1;i<=n;i++) scanf("%lld",&p[i]);
ll l=0,r=1e18;
while(l<r){
ll mid=(l+r+1)/2;
if(chk(mid)==0) r=mid-1;
else l=mid;
}
// printf(" %lld %lld\n",l,chk(128));
ll ans=0;
for(int i=1;i<=n;i++) ans+=(l/p[i]+1)/2;
printf("%lld\n",ans);
return 0;
}
/*
1
1000000000000000000
1000000000
*/