알고리즘 문제풀기/인프런 강의 정답
74. 최소힙(STL priority_queue : 우선순위큐)
코다람쥐
2022. 5. 21. 17:22
나의정답.
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
int main(int argc, char** argv) {
//freopen("input.txt", "rt", stdin);
int n;
priority_queue<int> pq;
while (true) {
scanf("%d", &n);
if (n == -1) return 0;
else if (n == 0) {
if (pq.empty()) printf("-1");
printf("%d", -pq.top());
pq.pop();
}
else {
pq.push(-n);
}
}
}