二分答案的题目
查看原帖
二分答案的题目
649243
2022_7_6_just_end楼主2022/10/13 16:45

P8161 [JOI 2022 Final] 自学 (Self Study)

题目传送门

捆绑抱0 蒟蒻求助

#include<bits/stdc++.h>
#define int long long
using namespace std;
struct node{
    int a,b;
}sc[3000002];
int n,m;
bool check(int mid){
	int ans=0;
	for(int i=1;i<=n;i++) {
		if(sc[i].a>=sc[i].b) {
			
			if(sc[i].a*m>=mid) {
				ans+=ceil(mid*1.0/sc[i].a);	
			}	
			else {
				ans+=m;
				ans+=ceil(1.0*(mid-sc[i].a*m)/sc[i].b);
			}
		}
		else {
		if(sc[i].b*m>=mid) {
			ans+=ceil(1.0*mid/sc[i].b);	
		}
		else {
			ans+=m;
			ans+=ceil(1.0*(mid-sc[i].b*m)/sc[i].a);
		}
		}
	}
	//cout<<ans<<" ";
	return ans<=n*m;
}
signed main() {
	cin>>n>>m;
	for(int i=1;i<=n;i++) {
		cin>>sc[i].a;
	}
	for(int j=1;j<=n;j++) {
		cin>>sc[j].b;
	}
	cout<<m<<endl;
	int l=1,r=10000000000000000000000,answer;
	while(l<=r) {
		int mid=(l+r)/2;
		if(check(mid)) answer=mid,l=mid+1;
		else r=mid-1;
		//cout<<l<<" "<<r<<endl;
	}
	cout<<answer;
	return 0;
}
2022/10/13 16:45
加载中...