ABC E求条
  • 板块学术版
  • 楼主ljy05
  • 当前回复1
  • 已保存回复1
  • 发布时间2025/1/18 21:45
  • 上次更新2025/1/19 09:48:24
查看原帖
ABC E求条
629740
ljy05楼主2025/1/18 21:45

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
*/
2025/1/18 21:45
加载中...