AcWing 5562. 最大生产
原题链接
中等
作者:
魔仙哥
,
2024-12-20 15:30:48
,
所有人可见
,
阅读 1
判定类二分问题
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+5;
#define LL long long
#define F(i,a,b) for(int i=a;i<=b;i++)
int n;
LL k,ans,a[N],b[N];
bool check(LL mid)
{
LL tmp = k;
for(int i = 1;i<=n;i++)
if(b[i]/a[i] < mid)
{
tmp -= a[i]*mid-b[i];
if(tmp < 0) return 0;
}
return 1;
}
int main()
{
cin>>n>>k;
for(int i = 1;i<=n;i++) cin>>a[i];
for(int i = 1;i<=n;i++) cin>>b[i];
LL l = 0,r = 2e9;
while(l <= r)
{
LL mid = l+r>>1;
if(check(mid)) ans = mid,l = mid+1;
else r = mid-1;
}
cout << ans << '\n';
return 0;
}