- 合并果子
- 2018-07-17 16:28:17 @
import heapq
if name == '__main__':
x = []
cost = 0
temp1 = []
n = int(input())
str_in = input().split()
for i in str_in:
x.append(int(i))
heapq.heapify(x)
for i in range(1, n):
temp1 = heapq.nsmallest(2, x)
temp = sum(temp1)
heapq.heappop(x)
heapq.heappush(x, temp)
heapq.heappop(x)
cost += temp
print(cost)
5 条评论
-
mmll LV 3 @ 2019-11-09 16:11:13
我是用numpy.argmin(a)和a.remove()写的,代码很简单,也是过不了而且事WrongAnswer,好奇怪!感觉没什么错误
-
2018-07-20 16:07:48@
怎么可能
-
2018-07-20 16:07:33@
不啊
-
2018-07-18 11:37:27@
歧视是什么鬼……Python本来就比C++慢很多啊
-
2018-07-17 16:28:49@
同样用了堆, c++能过 python过不了
- 1