Files
CodeTest/baekjoon/최대_힙/solution_20045176.rs
2024-08-29 16:22:15 +09:00

38 lines
913 B
Rust

use std::collections::BinaryHeap;
use std::io::{self, Write, BufWriter};
macro_rules! parse_line {
($($t: ty),+) => ({
let mut line = String::new();
std::io::stdin().read_line(&mut line).unwrap();
let mut iter = line.split_whitespace();
($(iter.next().unwrap().parse::<$t>().unwrap()),+)
})
}
fn main(){
let stdout = io::stdout();
let lock = stdout.lock();
let mut buff = BufWriter::new(lock);
let n = parse_line!(usize);
let mut heap : BinaryHeap<u32> = BinaryHeap::new();
for _i in 0..n{
let x = parse_line!(u32);
match x{
0 => {
let y = match heap.pop(){
Some(i) => i,
None => 0,
};
buff.write_fmt(format_args!("{}\n",y)).expect("Failed to write");
},
n => {
heap.push(n);
}
}
}
}