fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. bool is_possible(int x,vector<int>stock,vector<int>cost,vector<int>required,int budget){
  5. int totCost=0;
  6. for(int i=0;i<stock.size();i++){
  7. int req=x*required[i];
  8. totCost+=max(req-stock[i],0)*cost[i];
  9. }
  10. return totCost<=budget;
  11. }
  12.  
  13. main(){
  14. int n,budget,u=0;
  15. cin>>n>>budget;
  16. vector<int>stock(n),cost(n),required(n);
  17. for(int &it:required)cin>>it;
  18. for(int &it:stock)cin>>it;
  19. for(int &it:cost)cin>>it;
  20. int low=0,high=1e9;
  21. while(low<high){
  22. int mid = low+(high-low)/2;
  23. if(is_possible(mid,stock,cost,required,budget)){
  24. low=mid+1;
  25. u=mid;
  26. }
  27. else high=mid-1;
  28. }
  29. cout<<u<<"\n";
  30. }
Success #stdin #stdout 0.01s 5320KB
stdin
4 30
2 2 3 1
3 2 1 4
2 3 1 6
stdout
226050913