Re: [閒聊] 每日leetcode已回收
看板Marginalman作者DJYOSHITAKA (franchouchouISBEST)時間1年前 (2024/06/15 09:59)推噓2(2推 0噓 2→)留言4則, 3人參與討論串362/1548 (看更多)
502. IPO
維持maxheap內只有符合capital條件的profits即可
def findMaximizedCapital(self, k: int, w: int, profits: List[int], capital:
List[int]) -> int:
l = sorted([(cap, pro) for cap, pro in zip(capital, profits)])
h = []
cur_i, n = 0, len(profits)
for i in range(k):
while cur_i<n and l[cur_i][0] <= w:
heappush(h, -l[cur_i][1])
cur_i += 1
if len(h)>0:
cur_profit = heappop(h)
w -= cur_profit
return w
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 125.228.146.144 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1718416785.A.CA6.html
→
06/15 10:00,
1年前
, 1F
06/15 10:00, 1F
→
06/15 10:00,
1年前
, 2F
06/15 10:00, 2F
推
06/15 10:01,
1年前
, 3F
06/15 10:01, 3F
推
06/15 10:08,
1年前
, 4F
06/15 10:08, 4F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 362 之 1548 篇):