알고리즘
백준 1927: 최소 힙 [C++]
avocado8
2024. 7. 14. 16:56
https://www.acmicpc.net/problem/1927
걍 우선순위 큐 쓰는 문제...
이왜 실2?
씨쁠쁠은 짱이다
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
priority_queue<int, vector<int>, greater<>> pq;
int solution(int x){
int answer;
if(x==0){
if(pq.empty()) answer = 0;
else {
answer = pq.top();
pq.pop();
}
}
else {
pq.push(x);
}
return answer;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, x;
cin >> n;
while(n--){
cin >> x;
if(x==0){
if(pq.empty()) cout << 0 << '\n';
else {
cout << pq.top() << '\n';
pq.pop();
}
}
else {
pq.push(x);
}
}
return 0;
}