题解 | 排队打饭用小根堆每次选取最小元素

排队打饭

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)

全部评论

相关推荐

01-12 22:27
武汉大学 Java
点赞 评论 收藏
分享
牛客60022193...:大厂都招前端,他们觉得AI能替代前端,可能他们公司吊打btaj吧
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务