use std::collections::{BTreeSet, HashMap}; fn dfs(u: usize, paths: &Vec>, result: &mut Vec, checked: &mut Vec) -> usize { if u == 0 { return 0; } if result[u] > 0 { return result[u]; } checked[u] = true; let mut ret = u; for &v in paths[u].iter() { if result[v] > 0 { ret = ret.max(result[v]); continue; } if checked[v] { continue; } ret = ret.max(dfs(v, paths, result, checked)); } result[u] = ret; ret } fn main() { let mut n = String::new(); std::io::stdin().read_line(&mut n).ok(); let n: usize = n.trim().parse().unwrap(); let mut x = String::new(); std::io::stdin().read_line(&mut x).ok(); let x: Vec = x.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let mut a = String::new(); std::io::stdin().read_line(&mut a).ok(); let a: Vec = a.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let mut pointset = BTreeSet::new(); for i in 0..n { pointset.insert(x[i]); pointset.insert(x[i]-a[i]); pointset.insert(x[i]+a[i]); } let mut mapping = HashMap::new(); let mut revmap = HashMap::new(); for (i, &v) in pointset.iter().enumerate() { mapping.insert(v, i); revmap.insert(i, v); } let mut paths = vec![vec![]; pointset.len()]; for i in 0..n { let src = *mapping.get(&x[i]).unwrap(); let left = *mapping.get(&(x[i] - a[i])).unwrap(); let right = *mapping.get(&(x[i] + a[i])).unwrap(); paths[src].push(left); paths[src].push(right); } let mut result = vec![0usize; pointset.len()]; let mut checked = vec![false; pointset.len()]; for i in 0..n { let src = x[i]; let i = *mapping.get(&x[i]).unwrap(); if result[i] != 0 { println!("{}", *revmap.get(&result[i]).unwrap() - src); continue; } dfs(i, &paths, &mut result, &mut checked); println!("{}", *revmap.get(&result[i]).unwrap() - src); } }