Участник:Froyg/IPO

Материал из DISCOPAL
Перейти к: навигация, поиск

https://leetcode.com/problems/ipo/

class Solution:
    def findMaximizedCapital(self, k: int, W: int, Profits: List[int], Capital: List[int]) -> int:
        heap1 = []
        heap2 = []  
        for i in range(len(Profits)):
            heap1.append((Capital[i],Profits[i]))  
        heap1.sort() 
        for j in range(k):
            while(len(heap1)!=0 and heap1[0][0] <= W):
                heap2.append(heap1.pop(0)[1])  
            if(len(heap2) == 0):
                return W
            heap2.sort()
            W += heap2.pop()
        return W