fork download
  1. def max_items_possible():
  2.  
  3. n = int(input())
  4. req = [0] + list(map(int, input().split()))
  5. stock = [0] + list(map(int, input().split()))
  6. cost = [0] + list(map(int, input().split()))
  7. budget = int(input())
  8.  
  9. u = 0
  10. low = 0
  11. high = 10**18 # 1e18
  12.  
  13. while low <= high:
  14. mid = (low + high) // 2
  15. total_cost = 0
  16. possible = True
  17.  
  18. for j in range(1, n + 1):
  19. needed = req[j] * mid
  20. shortage = needed - stock[j]
  21.  
  22. if shortage > 0:
  23. item_cost = shortage * cost[j]
  24. total_cost += item_cost
  25.  
  26.  
  27. if total_cost > budget:
  28. possible = False
  29. break
  30.  
  31. if possible:
  32. u = mid
  33. low = mid + 1 # Try to make more items
  34. else:
  35. high = mid - 1 # Reduce the target number of items
  36.  
  37. print(u)
Success #stdin #stdout 0.07s 13856KB
stdin
Standard input is empty
stdout
Standard output is empty