fork download
  1. #include <iostream>
  2. #include<bits/stdc++.h>
  3.  
  4. using namespace std;
  5. bool check(vector<int> &throughput , vector<int> &cost , int mid , int budget){
  6. int n = cost.size();
  7. int sum=0;
  8.  
  9. for(int i=0;i<n;i++){
  10. int a = (mid-1)/throughput[i];
  11. int c = cost[i]*a;
  12. sum+=c;
  13. }
  14.  
  15. return sum<=budget;
  16.  
  17. }
  18. int main() {
  19. // your code goes here
  20. int n,budget;
  21. cin>>n>>budget;
  22. vector<int> throughput(n);
  23. vector<int> cost(n);
  24. for(int i=0;i<n;i++){
  25. cin>>throughput[i];
  26. }
  27.  
  28. for(int i=0;i<n;i++){
  29. cin>>cost[i];
  30. }
  31.  
  32.  
  33. int low = 1;
  34. int high = 1e9;
  35. int ans=-1;
  36.  
  37. while(low<=high){
  38. int mid = (low+high)/2;
  39. if(check(throughput,cost,mid,budget)==true){
  40. ans=mid;
  41. low=mid+1;
  42. }
  43. else{
  44. high = mid-1;
  45.  
  46. }
  47. }
  48.  
  49. cout<<ans<<endl;
  50.  
  51. return 0;
  52. }
Success #stdin #stdout 0s 544KB
stdin
3 32
4 2 7 
3 5 6
stdout
10