๋ฐ์ํ


์ฐ์ ์์ ํ๋ฅผ ์์์ผ ํ ์ ์๋ ๋ฌธ์ .
์๋ฃ๊ตฌ์กฐ ์ค๋๋ง์ ๋ณด๋ค๋ณด๋๊น ๊น๋จน์ด์ ์ฐ์ ์์ ํ ์ฌํ์น๋ฃํ๋๋ฐ ์๊ฐ์ด ์ข ๊ฑธ๋ ธ๋ค....
์ด๋ค์์ผ๋ก ์ฐ์ ์์๋ฅผ ์ค์ง ์ปค์คํฐ๋ง์ด์ง(?) ํ ๋ค์ for๋ฌธ ๋๋ฉด์ ์กฐ๊ฑด์ ๋ง๊ฒ
์ถ๋ ฅํ ๊ฑด ํ๊ณ , ๋ฃ์๊ฑด ๋ฃ๊ณ ~~
public class ์ ๋๊ฐํ {
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(bf.readLine());
// ์ฐ์ ์์ ํ ์ ๋ ฌ ๊ธฐ์ค
PriorityQueue<Integer> myQueue = new PriorityQueue<>((o1, o2) -> {
int first_abs = Math.abs(o1);
int second_abs = Math.abs(o2);
if (first_abs == second_abs) // ์ ๋๊ฐ ๊ฐ์ผ๋ฉด ์์ ์ซ์์ ์ฐ์ ์์๋ฅผ ์ค.
return o1 > o2 ? 1 : -1;
else
return first_abs - second_abs;
});
for (int i = 0; i < N; i++) {
int request = Integer.parseInt(bf.readLine());
if (request == 0) {
if (myQueue.isEmpty())
System.out.println("0");
else
System.out.println(myQueue.poll()); // ์ ๋๊ฐ ๊ฐ์ฅ ์์ ์ ์ถ๋ ฅ ๋ฐ ์ ๊ฑฐ
} else {
myQueue.add(request);
}
}
}
}๋ฐ์ํ