fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n;
  6. long long budget;
  7. cin >> n >> budget;
  8. vector<long long> comp(n), stock(n), cost(n);
  9. for (int i = 0; i < n; i++) cin >> comp[i];
  10. for (int i = 0; i < n; i++) cin >> stock[i];
  11. for (int i = 0; i < n; i++) cin >> cost[i];
  12.  
  13. long long lo = 0, hi = 1e18;
  14. long long ans = 0;
  15. while (lo <= hi) {
  16. long long mid = (lo + hi) / 2;
  17. long long total = 0;
  18. bool ok = true;
  19. for (int i = 0; i < n; i++) {
  20. long long need = comp[i] * mid - stock[i];
  21. if (need > 0) {
  22. total += need * cost[i];
  23. if (total > budget) { ok = false; break; } // early exit
  24. }
  25. }
  26. if (ok) { ans = mid; lo = mid + 1; }
  27. else hi = mid - 1;
  28. }
  29. cout << ans;
  30. }
Success #stdin #stdout 0s 5320KB
stdin
2 3 
1 2 
0 1
1 1
stdout
1