#[macro_export] macro_rules! setup { { mut $input:ident: SplitWhitespace $(,)? } => { use std::io::Read; let mut buf = String::new(); std::io::stdin().read_to_string(&mut buf).ok(); let mut $input = buf.split_whitespace(); }; } #[macro_export] macro_rules! parse_next { ($str_iter:expr) => { $str_iter.next().unwrap().parse().ok().unwrap() }; } #[allow(unused_imports)] use std::collections::{HashMap, HashSet, VecDeque}; fn main() { setup! { mut input: SplitWhitespace }; let n: usize = parse_next!(input); let k: usize = parse_next!(input); let x: Vec = (0..n).map(|_| parse_next!(input)).collect(); let a: Vec = (0..n).map(|_| parse_next!(input)).collect(); let ans = (|| { let mut queue = VecDeque::new(); let mut visited = HashSet::new(); { let root = k - 1; queue.push_back(root); visited.insert(root); } while !queue.is_empty() { let i = queue.pop_front().unwrap(); let children = x .iter() .enumerate() .filter(|(_, x_j)| { if (x[i] - a[i] <= **x_j) && (**x_j <= x[i] + a[i]) { return true; } false }) .map(|(j, _)| j) .collect::>(); for j in children.into_iter() { if visited.contains(&j) { continue; } queue.push_back(j); visited.insert(j); } } visited.len() })(); println!("{}", ans); }