Notice
Recent Posts
Recent Comments
Link
«   2026/06   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
Archives
Today
Total
관리 메뉴

dh-winternagi 님의 블로그

(11279) 최대 힙 본문

백준 (C++)/Solve

(11279) 최대 힙

dh-winternagi 2026. 4. 18. 18:58

https://www.acmicpc.net/problem/11279

단계별로 풀어보기

26단계(우선순위 큐) 1번째

 

 

 

#include <iostream>
#include <queue>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  
  int n;
  
  cin >> n;
  
  priority_queue<int> pq;
  
  while(n--){
    int t;
    
    cin >> t;
    
    if(t){
      pq.push(t);
    }else{
      if(!pq.empty()){
        cout << pq.top() << "\n";
        pq.pop();
      }else{
        cout << "0\n";
      }
    }
  }
  
  return 0;
}

'백준 (C++) > Solve' 카테고리의 다른 글

(11286) 절댓값 힙  (0) 2026.04.18
(1927) 최소 힙  (0) 2026.04.18
(12015) 가장 긴 증가하는 부분 수열 2  (0) 2026.04.18
(1300) K번째 수  (0) 2026.04.18
(2110) 공유기 설치  (0) 2026.04.18