Files
CodeObject/storage/zeta/rs/completed/6235.rs

35 lines
863 B
Rust

use std::{
cmp::Reverse,
collections::BinaryHeap,
fmt::Binary,
io::{read_to_string, stdin},
};
fn main() {
let mut line = String::new();
let mut heap = BinaryHeap::new();
loop {
line.clear();
stdin().read_line(&mut line).unwrap();
if line.starts_with('#') {
break;
}
let mut iter = line.trim().split(' ');
iter.next();
let q = iter.next().unwrap().parse::<usize>().unwrap();
let p = iter.next().unwrap().parse::<usize>().unwrap();
heap.push(Reverse((p, q, p)))
}
line.clear();
stdin().read_line(&mut line).unwrap();
let k = line.trim().parse::<usize>().unwrap();
for i in 0..k {
let (curr, q, period) = (heap.pop().unwrap()).0;
heap.push(Reverse((curr + period, q, period)));
println!("{}", q);
}
}