39 lines
913 B
Rust
39 lines
913 B
Rust
use std::{
|
|
cmp::Reverse,
|
|
collections::BinaryHeap,
|
|
io::{read_to_string, stdin},
|
|
};
|
|
|
|
fn main() {
|
|
let temp = read_to_string(stdin()).unwrap();
|
|
let mut iter = temp
|
|
.split_ascii_whitespace()
|
|
.map(|x| x.parse::<usize>().unwrap());
|
|
|
|
let (n, p) = (iter.next().unwrap(), iter.next().unwrap());
|
|
|
|
let defs = (0..n).map(|_| iter.next().unwrap()).collect::<Vec<_>>();
|
|
|
|
let mut heap = BinaryHeap::new();
|
|
let mut total = 0;
|
|
let mut res = Vec::new();
|
|
|
|
for &d in defs.iter() {
|
|
heap.push(Reverse(d));
|
|
total += d;
|
|
|
|
while heap.len() > 0 && total - heap.peek().unwrap().0 >= p {
|
|
total -= heap.peek().unwrap().0;
|
|
heap.pop();
|
|
}
|
|
if total >= p {
|
|
res.push(heap.len() as isize);
|
|
} else {
|
|
res.push(-1);
|
|
}
|
|
}
|
|
|
|
res.iter().for_each(|x| print!("{} ", x));
|
|
println!();
|
|
}
|