use std::collections::VecDeque; fn main() { let mut nd = String::new(); std::io::stdin().read_line(&mut nd).ok(); let nd: Vec = nd.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let n = nd[0]; let d = nd[1]; let mut a: Vec = vec![]; let mut idx2val: Vec<(usize, usize)> = vec![]; for i in 0..n { let mut ai = String::new(); std::io::stdin().read_line(&mut ai).ok(); let ai: usize = ai.trim().parse().unwrap(); a.push(ai); idx2val.push((i, ai)); } idx2val.sort_by_key(|pair| pair.1); let mut stack: VecDeque<(usize, usize)> = VecDeque::new(); let mut result: Vec = vec![0; n]; while let Some(pair) = idx2val.pop() { stack.push_back(pair); while stack.len() > 1 { let f = stack.front().unwrap(); if f.1 >= d + pair.1 { let f = stack.pop_front().unwrap(); result[f.0] = idx2val.len() + 1; } else { break; } } } result.iter().for_each(|i| { println!("{}", i); }); }