Created
October 30, 2016 01:17
-
-
Save ewmson/5b16c8907e62aadda4e14d162570d7a8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import heapq | |
T = int(input()) | |
for _ in range(T): | |
N = int(input()) | |
canv = list(sorted(map(int,input().split()))) | |
heapq.heapify(canv) | |
amount = 0 | |
while len(canv) != 1: | |
val = heapq.heappop(canv) + heapq.heappop(canv) | |
heapq.heappush(canv,val) | |
amount += val | |
print(amount) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment