这道题很容易想到是二分 但是因为可能会爆LL 所以要加一波特判
#include<cstdio> #include<cstring> #include<algorithm> #define LL long long using namespace std; const LL M=1e6+7,mx=1e18; LL read(){ LL ans=0,c=getchar(); while(c<'0'||c>'9') c=getchar(); while(c>='0'&&c<='9'){ans=ans*10+(c-'0'); c=getchar();} return ans; } LL n,S,mn; LL h[M],w[M],yy[M]; bool check(LL k){ LL sum=S; for(int i=1;i<=n;i++)if(k>=yy[i]){ if(mx/w[i]<=k) return 1; if(sum>h[i]+w[i]*k) sum-=h[i]+w[i]*k; else return 1; } return sum<=0; } int main() { freopen("tree.in","r",stdin); freopen("tree.out","w",stdout); n=read(); S=read(); mn=read(); for(int i=1;i<=n;i++) h[i]=read(); for(int i=1;i<=n;i++) w[i]=read(); for(int i=1;i<=n;i++){ LL now=mn-h[i]; if(now%w[i]==0) yy[i]=now/w[i]; else yy[i]=now/w[i]+1; } LL l=0,r=mx; while(l<=r){ LL mid=(l+r)>>1; if(check(mid)) r=mid-1; else l=mid+1; } printf("%lld ",l); return 0; }