Kali_prasad

min tokens to expand ware house

Aug 19th, 2025
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.98 KB | None | 0 0
  1. class Solution:
  2.     def minTokensToExpand(self,warehouses,shipments):
  3.         n = len(warehouses)
  4.         warehouses = sorted(warehouses)
  5.         total = sum(warehouses)
  6.         answers = []
  7.         for x,y in shipments:
  8.             ans = 10**10
  9.             for curr in warehouses:
  10.                 remaining = total - curr
  11.                 ans = min(ans,(max(0,x-curr)+max(0,y-remaining)))
  12.             answers.append(ans)
  13.         return answers
  14.  
  15. if __name__ == "__main__":
  16.     sol = Solution()
  17.     cases = [
  18.         ([2,4,1,3], [(5,7)]),
  19.         ([1, 2, 3], [(4, 2), (3, 3), (0, 0)]),
  20.         ([5], [(3, 2), (10, 0), (0, 6)]),
  21.         ([2, 2, 2, 2], [(3, 5), (8, 1), (4, 4)]),
  22.         ([10, 20, 30], [(15, 25), (60, 0), (5, 55)]),
  23.         ([1, 100, 1], [(50, 1), (1, 101), (102, 0)]),
  24.     ]
  25.  
  26.     for warehouses, shipments in cases:
  27.         ans = sol.minTokensToExpand(warehouses, shipments)
  28.         print(f"warehouses={warehouses}, shipments={shipments} -> answers={ans}")
  29.  
Advertisement
Add Comment
Please, Sign In to add comment