From 91a3795dc2a4efcb6e4242fb37289a93d2f5134b Mon Sep 17 00:00:00 2001 From: hangyeol Date: Mon, 12 May 2025 19:57:31 +0900 Subject: [PATCH 1/2] =?UTF-8?q?118=EC=B0=A8=201=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C=ED=92=80=EC=9D=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\260\261\355\225\234\352\262\260.py" | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 "live11/test118/\353\254\270\354\240\2341/\353\260\261\355\225\234\352\262\260.py" 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 From 540993d40283803aab8ef70f571c380030105d84 Mon Sep 17 00:00:00 2001 From: hangyeol Date: Mon, 12 May 2025 19:57:40 +0900 Subject: [PATCH 2/2] =?UTF-8?q?118=EC=B0=A8=202=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C=ED=92=80=EC=9D=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\260\261\355\225\234\352\262\260.py" | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 "live11/test118/\353\254\270\354\240\2342/\353\260\261\355\225\234\352\262\260.py" 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