結果
問題 |
No.649 ここでちょっとQK!
|
ユーザー |
![]() |
提出日時 | 2019-08-01 11:06:15 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 38 ms / 3,000 ms |
コード長 | 1,217 bytes |
コンパイル時間 | 27,276 ms |
コンパイル使用メモリ | 378,488 KB |
実行使用メモリ | 7,808 KB |
最終ジャッジ日時 | 2024-07-05 07:26:50 |
合計ジャッジ時間 | 18,615 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 32 |
ソースコード
use std::str::SplitWhitespace; use std::str::FromStr; use std::io::BufWriter; use std::io::Write; use std::io::Read; struct Scanner<'a> { it: SplitWhitespace<'a>, } impl<'a> Scanner<'a> { pub fn next<T: FromStr>(&mut self) -> T { self.it.next().unwrap().parse::<T>().ok().unwrap() } } use std::collections::BinaryHeap; use std::cmp::Reverse; fn run() { let s = { let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); s }; let mut sc = Scanner {it: s.split_whitespace()}; let out = std::io::stdout(); let mut out = BufWriter::new(out.lock()); let q: usize = sc.next(); let k: usize = sc.next(); let mut small = BinaryHeap::new(); let mut large = BinaryHeap::new(); for _ in 0..q { let op: u8 = sc.next(); if op == 1 { let v: u64 = sc.next(); small.push(v); if small.len() >= k { large.push(Reverse(small.pop().unwrap())); } } else if let Some(Reverse(v)) = large.pop() { writeln!(out, "{}", v).unwrap(); } else { writeln!(out, "-1").unwrap(); } } } fn main() { run(); }