priority queue을 오름차순으로 만드려면 greater클래스를 넣어준다. 
 greater<int> : 오름차순
 less<int> : 내림차순 
priority_queue<int, vector<int>, greater<int>> pq;
 
#include <bits/stdc++.h>
using namespace std;

int n, input;
priority_queue<int, vector<int>, greater<int>> pq;

int main(void) {
  ios::sync_with_stdio(0);
  cin.tie(0);

  cin >> n;
  while(n--){
    cin >> input;
    if(pq.empty() && input == 0){
      cout << 0 << '\n';
    }else if(input == 0){
      cout << pq.top() << '\n';
      pq.pop();
    }else{
      pq.push(input);
    }
  }
  return 0;
}

 
728x90

+ Recent posts