作者dont (dont)
看板Marginalman
標題Re: [閒聊] 每日leetcode
時間Mon Oct 14 09:54:02 2024
2530. Maximal Score After Applying K Operations
## 思路
MaxHeap取k次
## Code
```python
class Solution:
def maxKelements(self, nums: List[int], k: int) -> int:
res = 0
max_heap = []
for num in nums:
heapq.heappush(max_heap, -num)
for _ in range(k):
num = -heapq.heappop(max_heap)
res += num
heapq.heappush(max_heap, -ceil(num/3))
return res
```
--
https://i.imgur.com/kyBhy6o.jpeg
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 185.213.82.71 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1728870844.A.FCA.html
推 DJYOSHITAKA: 法國我 10/14 09:54
推 sustainer123: 別捲了 10/14 09:56
推 JIWP: 大師 10/14 09:57