bzoj5106: [CodePlus2017]汀博尔 & loj#6249. 「CodePlus 2017 11 月赛」汀博尔
http://www.lydsy.com/JudgeOnline/problem.php?id=5106
https://loj.ac/problem/6249
直接二分就好了
注意一下边界
一开始傻乎乎的写多了一百多行的高精度
然而只是助长了我的WA率
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
long long a[210000],h[210000];
long long ans=0,s,L;
int n;
long long l,r,maxx=0;;
void solve()
{
l=0;r=max(L,s)/maxx+1;//边界搞死人
while (l<=r)
{
long long mid=(l+r)/2;
long long sum=0;
for (int i=1;i<=n;i++)
{
long long x=a[i]*mid+h[i];
if (x>=L) sum+=x;
}
if (sum>=s) {ans=mid;r=mid-1;}
else {l=mid+1;}
}
}
int main()
{
scanf("%d%lld%lld",&n,&s,&L);
for (int i=1;i<=n;i++) scanf("%lld",&h[i]);
for (int i=1;i<=n;i++) {scanf("%lld",&a[i]);maxx=max(maxx,a[i]);}
solve();
printf("%lld\n",ans);
return 0;
}