CodingTest/99클럽2024스터디
99클럽 코테 스터디 8일차 TIL, 프로그래머스 / 최소 힙
mrawesome
2024. 7. 30. 23:32
https://www.acmicpc.net/problem/1927
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <thread>
#include <vector>
#include <string>
#include <cstring>
#include <set>
#include <queue>
#include <math.h>
#include <stack>
#include <algorithm>
#include <unordered_map>
#define endl "\n"
#define INT_MAX int(1e9)
#define MAX 10001
using namespace std;
int N;
std::priority_queue<int> prQueue;
void Input()
{
cin >> N;
};
void Solve()
{
int x;
for (int i = 0; i < N; ++i)
{
cin >> x;
if (x == 0)
{
if (prQueue.empty())
{
cout << 0 << endl;
}
else
{
cout << -prQueue.top() << endl;
prQueue.pop();
}
}
else
{
prQueue.push(-x);
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
// freopen("input_c.txt", "r", stdin);
Input();
Solve();
return 0;
}