#include <iostream>
#include <queue>
using namespace std;
int main(void)
{
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
int n;
cin >> n;
unsigned int data = 0;
priority_queue<unsigned int> pq;
for(int i = 0 ; i < n ; i++)
{
cin >> data;
if(data == 0)
{
if(pq.empty())
{
cout << 0 << '\n';
continue;
}
cout << pq.top() << '\n';
pq.pop();
}
else
{
pq.push(data);
}
}
}
[Approach]
1. 직접 구현해보기...로 하려다가 일단은 빠르게 우선순위 큐 사용해서 풀었다.
[Point]
1. 자료구조를 알고 있었다면 쉬운 문제. 모른다면 뭐 헤딩해야되는데 꼭 구현해볼 것. 자료구조별로! 다!!!!
'PS > BOJ' 카테고리의 다른 글
[백준] 5525.cpp : IOIOI (0) | 2020.07.04 |
---|---|
[백준] 18870.cpp : 좌표 압축 (0) | 2020.07.04 |
[백준] 5430.cpp : AC (0) | 2020.07.03 |
[백준] 1780.cpp : 종이의 개수 (0) | 2020.07.03 |
[백준] 1541.cpp : 잃어버린 괄호 (0) | 2020.07.03 |