You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mycode/ACM/[NOIP2004]合并果子.py

18 lines
312 B

5 months ago
import heapq
import ctypes
a=int(input())
b=input().split()
for i in range(len(b)):
b[i]=int(b[i])
heapq.heapify(b)
# print(b)
sum=0
while len(b) != 1:
c,d=heapq.nsmallest(2,b)
# heapq.heappop(b)
# heapq.heappop(b)
b.remove(c)
b.remove(d)
sum+=c+d
heapq.heappush(b,c+d)
print(sum)