fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. #define s(a) scanf("%lld",&a)
  5. ll n,m;
  6. bool test(ll mid, ll *need, ll *b)
  7. {
  8. ll m1=m;
  9. for(int i=0;i<n;i++)
  10. {
  11. if(mid>=need[i])
  12. continue;
  13. ll diff=need[i]-mid;
  14. double temp1=(double)diff/(double)b[i];
  15. ll temp=ceil(temp1);
  16. if(m1<temp)
  17. return false;
  18. m1-=temp;
  19. }
  20. return true;
  21. }
  22. int main() {
  23. s(n);s(m);
  24. ll a[n+2],b[n+2],sum=0,maxim=0;
  25. for(int i=0;i<n;i++)
  26. {
  27.  
  28. s(a[i]);
  29. sum+=a[i];
  30.  
  31. }
  32. for(int i=0;i<n;i++)
  33. s(b[i]);
  34. if(sum<=m)
  35. {
  36. cout<<0;
  37. }
  38. else{
  39. ll need[n];
  40. for(int i=0;i<n;i++)
  41. {
  42. need[i]=a[i]*b[i];
  43. maxim=max(maxim,need[i]);
  44. }
  45. ll low=0,high=maxim,ans=high;
  46. while(high>=low)
  47. {
  48. ll mid=(high+low)/2;
  49. // cout<<mid<<"s ";
  50. if(test(mid,need,b))
  51. {
  52. ans=mid;
  53. high=mid-(ll)1;
  54. // cout<<mid<<endl;
  55. }
  56. else low=mid+(ll)1;
  57. // cout<<ans<<endl;
  58. }
  59. cout<<ans;}
  60. return 0;
  61. }
Success #stdin #stdout 0s 15232KB
stdin
Standard input is empty
stdout
Standard output is empty