【题解】
二分答案。r要设好,不能随便设置为max(s,len),不然check的时候会爆long long
1 #include<cstdio> 2 #include<algorithm> 3 #define rg register 4 #define N 200010 5 #define LL long long 6 using namespace std; 7 LL n,s,len,mx,h[N],a[N],l,r,mid; 8 inline LL read(){ 9 LL k=0; char c=getchar(); 10 while(c<'0'||c>'9')c=getchar(); 11 while('0'<=c&&c<='9')k=k*10+c-'0',c=getchar(); 12 return k; 13 } 14 inline bool check(){ 15 LL cnt=0; 16 for(rg int i=1;i<=n;i++) 17 if(1LL*h[i]+a[i]*mid>=len){ 18 cnt+=1LL*h[i]+a[i]*mid; 19 if(cnt>=s) return 1; 20 } 21 return 0; 22 } 23 int main(){ 24 n=read(); s=read(); len=read(); 25 for(rg int i=1;i<=n;i++) h[i]=read(); 26 for(rg int i=1;i<=n;i++) a[i]=read(),mx=max(mx,a[i]); 27 l=-1; r=max(s,len)/mx+1; 28 while(l+1<r){ 29 mid=(l+r)>>1; 30 if(check()) r=mid; else l=mid; 31 } 32 printf("%lld\n",r); 33 return 0; 34 }