use std::{cmp::Reverse, collections::VecDeque}; fn main() { let n = { let mut line = String::new(); std::io::stdin().read_line(&mut line).unwrap(); line.trim().parse::().unwrap() }; let xx = { let mut line = String::new(); std::io::stdin().read_line(&mut line).unwrap(); line.split_whitespace() .map(|x| x.parse::().unwrap()) .collect::>() }; let aa = { let mut line = String::new(); std::io::stdin().read_line(&mut line).unwrap(); line.split_whitespace() .map(|x| x.parse::().unwrap()) .collect::>() }; let mut graph = vec![vec![]; n]; for curr_idx in 0..n { if xx[curr_idx] >= aa[curr_idx] { if let Ok(next_idx) = xx.binary_search(&(xx[curr_idx] - aa[curr_idx])) { graph[next_idx].push(curr_idx); } } if let Ok(next_idx) = xx.binary_search(&(xx[curr_idx] + aa[curr_idx])) { graph[next_idx].push(curr_idx); } } let mut sorted_indexes: Vec = (0..n).collect(); sorted_indexes.sort_unstable_by_key(|&i| Reverse(xx[i] + aa[i])); let mut falling_positions = vec![0; n]; for &leader_idx in sorted_indexes.iter() { if falling_positions[leader_idx] != 0 { continue; } let falling_position = xx[leader_idx] + aa[leader_idx]; falling_positions[leader_idx] = falling_position; let mut que = VecDeque::from(vec![leader_idx]); while let Some(curr) = que.pop_front() { for &next in graph[curr].iter() { if falling_positions[next] == 0 { falling_positions[next] = falling_position; que.push_back(next); } } } } for (&dist, &x) in falling_positions.iter().zip(xx.iter()) { println!("{}", dist - x); } }