use std::collections::BinaryHeap; fn main() { let (h, w, y, x) = { let mut line = String::new(); std::io::stdin().read_line(&mut line).unwrap(); let mut iter = line.split_whitespace(); ( iter.next().unwrap().parse::().unwrap(), iter.next().unwrap().parse::().unwrap(), iter.next().unwrap().parse::().unwrap() - 1, iter.next().unwrap().parse::().unwrap() - 1, ) }; let mut aaa = vec![]; for _ in 0..h { let mut line = String::new(); std::io::stdin().read_line(&mut line).unwrap(); aaa.push( line.split_whitespace() .map(|x| x.parse::().unwrap()) .collect::>(), ); } let mut player_power = aaa[y][x]; let mut visited = vec![vec![false; w]; h]; visited[y][x] = true; let mut kill_cnt = 0; let mut heap = BinaryHeap::from(vec![(Power(0), (y, x))]); while let Some((enemy_power, (y, x))) = heap.pop() { if player_power <= enemy_power.0 { break; } player_power += enemy_power.0; kill_cnt += 1; if y > 0 && !visited[y - 1][x] { heap.push((Power(aaa[y - 1][x]), (y - 1, x))); visited[y - 1][x] = true; } if y < h - 1 && !visited[y + 1][x] { heap.push((Power(aaa[y + 1][x]), (y + 1, x))); visited[y + 1][x] = true; } if x > 0 && !visited[y][x - 1] { heap.push((Power(aaa[y][x - 1]), (y, x - 1))); visited[y][x - 1] = true; } if x < w - 1 && !visited[y][x + 1] { heap.push((Power(aaa[y][x + 1]), (y, x + 1))); visited[y][x + 1] = true; } } println!("{}", if kill_cnt == h * w { "Yes" } else { "No" }); } #[derive(Debug, PartialEq, Eq)] struct Power(usize); impl std::cmp::PartialOrd for Power { fn partial_cmp(&self, other: &Self) -> Option { Some(self.0.partial_cmp(&other.0).unwrap().reverse()) } } impl Ord for Power { fn cmp(&self, other: &Self) -> std::cmp::Ordering { self.partial_cmp(other).unwrap() } }