From db333684c73bf9e95a7a457cfb8372655195d5a0 Mon Sep 17 00:00:00 2001 From: Junseo Kim Date: Mon, 13 May 2024 12:26:55 +0900 Subject: [PATCH] =?UTF-8?q?2024-05-13=20=EC=B9=B4=EB=93=9C=20=EC=A0=95?= =?UTF-8?q?=EB=A0=AC=ED=95=98=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oesnuj/README.md | 1 + .../1715.cpp" | 33 +++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 "oesnuj/\354\232\260\354\204\240\354\210\234\354\234\204 \355\201\220/1715.cpp" diff --git a/oesnuj/README.md b/oesnuj/README.md index 0c1da06..c49dc46 100644 --- a/oesnuj/README.md +++ b/oesnuj/README.md @@ -9,4 +9,5 @@ | 5차시 | 2024.04.13 | 이분탐색 | [듣보잡](https://www.acmicpc.net/problem/1764) | [#20](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/20) | | 6차시 | 2024.05.06 | 기하학 | [정사각형](https://www.acmicpc.net/problem/1485) | [#22](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/22) | | 7차시 | 2024.05.08 | 스택, 큐, 덱 | [queuestack](https://www.acmicpc.net/problem/24511) | [#24](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/24) | +| 8차시 | 2024.05.13 | 우선순위 큐 | [카드 정렬하기](https://www.acmicpc.net/problem/1715) | [#27](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/27) | --- diff --git "a/oesnuj/\354\232\260\354\204\240\354\210\234\354\234\204 \355\201\220/1715.cpp" "b/oesnuj/\354\232\260\354\204\240\354\210\234\354\234\204 \355\201\220/1715.cpp" new file mode 100644 index 0000000..7311750 --- /dev/null +++ "b/oesnuj/\354\232\260\354\204\240\354\210\234\354\234\204 \355\201\220/1715.cpp" @@ -0,0 +1,33 @@ +#include +#include + +using namespace std; + +int main() { + ios::sync_with_stdio(false); cin.tie(NULL); + + priority_queue , greater> pq; //최소 힙으로 우선순위 큐 선언 + int n; + cin >> n; + for (int i = 0; i < n; i++) //우선순위 큐에 다 넣음 + { + int x; + cin >> x; + pq.push(x); + } + int result = 0; + while(pq.size() > 1) //우선순위 큐에 값이 하나만 남을 때 까지 반복 + { + // 우선순위 큐에서 가장 작은 두 수를 꺼내서 합침 + int a = pq.top(); + pq.pop(); + int b = pq.top(); + pq.pop(); + int sum = a + b; + pq.push(sum); // 합친 결과를 우선순위 큐에 다시 넣음 + + result += sum; // 결과값을 누적 + } + cout << result; + return 0; +} \ No newline at end of file