#include <iostream>
#include <queue>
using namespace std;
struct compare {
bool operator()(int x, int y) {
if (abs(x) == abs(y)) return x > y;
else return abs(x) > abs(y);
}
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
priority_queue<int, vector<int>, compare>pq;
int N; cin >> N;
while (N--) {
int x; cin >> x;
if (x != 0) pq.push(x); //์
๋ ฅ์ด 0์ด ์๋๋
else { //์
๋ ฅ์ด 0์ผ๋
if (pq.empty()) cout << "0" << "\n"; //ํ๊ฐ ๋น์ด์๋ค๋ฉด 0 ์ถ๋ ฅ
else { //๋น์ด์์ง ์๋ค๋ฉด
cout << pq.top()<<'\n'; //์ต์๊ฐ ์ถ๋ ฅํ๊ณ
pq.pop(); //์ญ์
}
}
}
}
'Algorithm ๐ง๐ปโ๐ป > ๋ฐฑ์ค(BOJ)' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค,c++] 1138๋ฒ - ํ ์ค๋ก ์๊ธฐ (0) | 2021.10.27 |
---|---|
[๋ฐฑ์ค,c++] 11365๋ฒ - !๋ฐ๋น ๊ธ์ผ (0) | 2021.10.27 |
[๋ฐฑ์ค,c++] 11328๋ฒ - strfry (0) | 2021.10.27 |
[๋ฐฑ์ค,c++] 11279๋ฒ - ์ต๋ ํ (0) | 2021.10.27 |
[๋ฐฑ์ค,c++] 11123๋ฒ - ์ ํ๋ง๋ฆฌ... ์ ๋๋ง๋ฆฌ... (0) | 2021.10.27 |
[๋ฐฑ์ค,c++] 1110๋ฒ - ๋ํ๊ธฐ ์ฌ์ดํด (0) | 2021.10.27 |
๋๊ธ