Recent Posts
Notice
No Rules Rules
최대 힙 (feat. 백준, 11279번) 본문
728x90
반응형
최대 힙
https://www.acmicpc.net/problem/11279
11279번: 최대 힙
첫째 줄에 연산의 개수 N(1 ≤ N ≤ 100,000)이 주어진다. 다음 N개의 줄에는 연산에 대한 정보를 나타내는 정수 x가 주어진다. 만약 x가 자연수라면 배열에 x라는 값을 넣는(추가하는) 연산이고, x가
www.acmicpc.net
반응형
// woohyeon.kim
// kim519620.tistory.com
#include <iostream>
#include <queue>
using namespace std;
int main() {
ios::sync_with_stdio(false), cin.tie(NULL);
priority_queue<int> ans;
register int N;
cin >> N;
for (register int i = 0, v; i < N; ++i) {
cin >> v;
if (v == 0)
if (ans.empty())
cout << 0 << "\n";
else
cout << ans.top() << "\n", ans.pop();
else
ans.push(v);
}
return 0;
}
// *&)*@*
자료구조 중 우선순위큐인 priority_queue를 이용하여 가장 top의 값 (내림차순상 가장 큰 값) 을 출력합니다.
728x90
반응형
'생활 > 코테' 카테고리의 다른 글
절댓값 힙 (feat. 백준, 11286번) (0) | 2022.08.16 |
---|---|
최소 힙 (feat. 백준, 1927번) (0) | 2022.08.16 |
행렬 제곱 (feat. 백준, 10830번) (0) | 2022.08.15 |
행렬 곱셈 (feat. 백준, 2740번) (0) | 2022.08.15 |
이항 계수 3 (feat. 백준, 11401번) (0) | 2022.08.15 |
Comments