Skip to content

Commit

Permalink
Merge pull request #27 from AlgoLeadMe/8-oesnuj
Browse files Browse the repository at this point in the history
8-oesnuj
  • Loading branch information
oesnuj authored Jul 10, 2024
2 parents 5964a55 + df488fb commit 7ac923a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
3 changes: 2 additions & 1 deletion oesnuj/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
| 4μ°¨μ‹œ | 2024.04.06 | μŠ€νƒ | [μ˜₯상 정원 κΎΈλ―ΈκΈ°](https://www.acmicpc.net/problem/6198) | [#14](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/14) |
| 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) |
| 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) |
---
33 changes: 33 additions & 0 deletions oesnuj/μš°μ„ μˆœμœ„ 큐/1715.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <iostream>
#include <queue>

using namespace std;

int main() {
ios::sync_with_stdio(false); cin.tie(NULL);

priority_queue <int, vector<int>, greater<int>> 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;
}

0 comments on commit 7ac923a

Please sign in to comment.