Re: [閒聊] 每日leetcode
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
推
10/14 09:54,
1年前
, 1F
10/14 09:54, 1F
推
10/14 09:56,
1年前
, 2F
10/14 09:56, 2F
推
10/14 09:57,
1年前
, 3F
10/14 09:57, 3F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 983 之 1554 篇):