题解 | 排队打饭用小根堆每次选取最小元素
排队打饭
https://www.nowcoder.com/practice/22fa078e409a4cfbb816b3ff970b5631
from heapq import heappush, heappop
n, r = map(int, input().split())
times = list(map(int, input().split()))
times.sort()
heap = [0] * r
res = 0
for x in times:
time = heappop(heap)
time += x
res += time
heappush(heap, time)
print(res)

查看1道真题和解析
