# 문제
# 입력 및 출력
# 풀이
최소 힙에서 설명했듯이 우선순위 큐는 디폴트가 최대 힙이기 때문에 우선순위 큐를 사용해서 풀어주면 됨
priority_queue <int, vector<int>> q;
#pragma warning(disable:4996)
#include <iostream>
#include <queue>
using namespace std;
int main() {
int n, inp;
scanf("%d", &n);
priority_queue<int, vector<int>> q;
for (int i = 0; i < n; i++) {
scanf("%d", &inp);
if (inp == 0) {
if (q.empty()) printf("0\n");
else {
printf("%d\n", q.top());
q.pop();
}
}
else q.push(inp);
}
}
이것도 마찬가지로 printf, scanf, \n 사용했음
'Algorithm > 📖Baekjoon' 카테고리의 다른 글
#1946 신입 사원 (0) | 2022.05.01 |
---|---|
#10610 30 (0) | 2022.04.28 |
#1927 최소 힙 (0) | 2022.04.27 |
#1874 스택 수열 (0) | 2022.04.27 |
#2164 카드2 (0) | 2022.04.26 |
댓글