diff --git "a/live11/test118/\353\254\270\354\240\2341/\353\260\261\355\225\234\352\262\260.py" "b/live11/test118/\353\254\270\354\240\2341/\353\260\261\355\225\234\352\262\260.py" new file mode 100644 index 00000000..e5fd6d21 --- /dev/null +++ "b/live11/test118/\353\254\270\354\240\2341/\353\260\261\355\225\234\352\262\260.py" @@ -0,0 +1,28 @@ +import sys +import heapq + +def main(): + input = sys.stdin.readline + + T = int(input()) + + for _ in range(T): + K = int(input()) + fileSize = list(map(int, input().split()))[:K] + + heapq.heapify(fileSize) + total = 0 + + while len(fileSize) >= 2: + first = heapq.heappop(fileSize) + second = heapq.heappop(fileSize) + cost = first + second + total += cost + + heapq.heappush(fileSize, cost) + + print(total) + + +if __name__ == '__main__': + main() \ No newline at end of file diff --git "a/live11/test118/\353\254\270\354\240\2342/\353\260\261\355\225\234\352\262\260.py" "b/live11/test118/\353\254\270\354\240\2342/\353\260\261\355\225\234\352\262\260.py" new file mode 100644 index 00000000..aa13a89b --- /dev/null +++ "b/live11/test118/\353\254\270\354\240\2342/\353\260\261\355\225\234\352\262\260.py" @@ -0,0 +1,28 @@ +import sys +import heapq + +def main(): + input = sys.stdin.readline + + N = int(input()) + cardSize = [] + + for _ in range(N): + card = int(input()) + cardSize.append(card) + + heapq.heapify(cardSize) + total = 0 + + while len(cardSize) >= 2: + first = heapq.heappop(cardSize) + second = heapq.heappop(cardSize) + cost = first + second + total += cost + + heapq.heappush(cardSize, cost) + + print(total) + +if __name__ == '__main__': + main() \ No newline at end of file