Re: [閒聊] 每日leetcode

作者: dont   2024-10-14 09:54:02
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
```
作者: DJYOSHITAKA (Evans)   2023-10-14 09:54:00
法國我
作者: sustainer123 (caster)   2024-10-14 09:56:00
別捲了
作者: JIWP (JIWP)   2024-10-14 09:57:00
大師

Links booklink

Contact Us: admin [ a t ] ucptt.com