728x90
문제 11279번
https://www.acmicpc.net/problem/11279
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
int main() {
int n, x;
vector<int> v;
priority_queue<int> pq;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x;
if (x == 0) {
if (pq.empty()) {
v.push_back(0);
}
else {
v.push_back(pq.top());
pq.pop();
}
}
else {
pq.push(x);
}
}
for (int i = 0; i < v.size(); i++) {
cout << v[i] << '\n';
}
return 0;
}
728x90
'백준 > C++' 카테고리의 다른 글
[C++] 백준 11286번 - 절댓값 힙 (0) | 2024.08.21 |
---|---|
[C++] 백준 1927번 - 최소 힙 (0) | 2024.08.18 |
[C++] 백준 2145번 - 숫자 놀이 (0) | 2024.08.15 |
[C++] 백준 1681번 - 줄 세우기 (0) | 2024.08.14 |
[C++] 백준 3004번 - 체스판 조각 (0) | 2024.08.11 |