Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. def maxProfit(sizes, prices):
  2.     n = len(sizes)
  3.     m = len(prices)
  4.     assert(1 <= n and n <= m and m <= 100000)
  5.    
  6.     sums = 0
  7.    
  8.     val = []
  9.    
  10.     for i in range(m):
  11.         assert(len(prices[i]) == 2)
  12.         assert(1 <= prices[i][0] and prices[i][0] <= 10000)
  13.         assert(1 <= prices[i][1] and prices[i][1] <= 10000)
  14.        
  15.         sums += prices[i][1]
  16.        
  17.         val.append(prices[i][0] - sums)
  18.     val.sort()
  19.     sizes.sort()
  20.    
  21.     pos = -1
  22.    
  23.     ans = 0
  24.    
  25.     for i in range(len(sizes) - 1, -1, -1):
  26.         ans += sizes[i] * val[pos]
  27.         pos -= 1
  28.        
  29.     return ans
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement