fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int n, budget;
  5. vector<int> req, cost, stock;
  6.  
  7. bool check(int units){
  8. int cst = 0;
  9. for(int i = 0; i < n; i++){
  10. if(stock[i] < req[i]*units)
  11. cst = cst + ((req[i]*units) - stock[i])*cost[i];
  12. }
  13. if(cst > budget)
  14. return false;
  15. else
  16. return true;
  17. }
  18.  
  19. int main()
  20. {
  21.  
  22. cin >> n >> budget;
  23. req.resize(n);
  24. cost.resize(n);
  25. stock.resize(n);
  26.  
  27. for(int i = 0; i < n; i++)
  28. cin >> req[i];
  29. for(int i = 0; i < n; i++)
  30. cin >> stock[i];
  31. int tot_cost = 0;
  32. for(int i = 0; i < n; i++){
  33. cin >> cost[i];
  34. tot_cost += cost[i];
  35. }
  36. int min_prod = INT_MAX;
  37. for(int i = 0; i < n; i++){
  38. min_prod = min(min_prod, stock[i]/req[i]);
  39. }
  40. int lo = 0;
  41. int hi = budget+min_prod;
  42.  
  43. int ans = -1;
  44. while(lo <= hi){
  45. int mid = (lo+hi)/2;
  46. if(check(mid)){
  47. ans = mid;
  48. lo = mid+1;
  49. }
  50. else
  51. hi = mid-1;
  52. }
  53.  
  54. cout << ans;
  55.  
  56. return 0;
  57. }
Success #stdin #stdout 0s 544KB
stdin
2 0
1 2
10 10
1 1
stdout
5