use std::cmp::*; use std::io::*; fn lower_bound(x: T, a: &Vec) -> usize { let mut l: usize = 0; let mut r: usize = a.len(); while r != l { let mid = (l + r) >> 1; if a[mid] < x { l = mid + 1; } else { r = mid; } } l } fn main() { let mut s: String = String::new(); std::io::stdin().read_to_string(&mut s).ok(); let mut itr = s.trim().split_whitespace(); let n: usize = itr.next().unwrap().parse().unwrap(); let d: i32 = itr.next().unwrap().parse().unwrap(); let mut a: Vec = (0..n) .map(|_| itr.next().unwrap().parse().unwrap()) .collect(); let b = a.clone(); a.sort(); let mut out = Vec::new(); // a_i - a_j >= d for i in 0..n { writeln!(out, "{}", lower_bound(b[i] - d + 1, &a)).ok(); } stdout().write_all(&out).unwrap(); }