백준 11279 최대 힙
자료구조중, 우선순위 큐(대표적으로 힙)를 알고있는지 묻는 문제 입니다.
자료형의 값이 크므로,
ios_base::sync_with_stdio(0); cin.tie(0); 를 사용해야 합니다.
소스 코드 :
#include#include using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); priority_queue maxHeap; int n; cin >> n; for (int i = 0; i < n; i++) { int q; cin >> q; cin.ignore(); if (q == 0) { if (!maxHeap.empty()) { cout << maxHeap.top() << '\n'; maxHeap.pop(); } else { cout << '0' << '\n'; } } else { maxHeap.push(q); } } }
댓글
댓글 쓰기