题解 | #分金条的最小花费#

分金条的最小花费

http://www.nowcoder.com/practice/418d2fcdf7f24d6f8f4202e23951c0da

n = int(input())
nums = list(map(int, input().split()))
import heapq
heapq.heapify(nums)
res = 0
while len(nums) > 1:
    a, b = heapq.heappop(nums), heapq.heappop(nums)
    res += a + b
    heapq.heappush(nums, a + b)
print(res)
全部评论

相关推荐

点赞 评论 收藏
分享
03-11 23:33
已编辑
曲阜师范大学 后端工程师
牛客68808588...:果真开发过12306购票系统吗,这不是一眼就被看穿了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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