use std::{collections::{VecDeque, BinaryHeap}, cmp::Reverse}; const INF: usize = 1usize << 60; const DX: [isize; 4] = [-1, 1, 0, 0]; const DY: [isize; 4] = [0, 0, 1, -1]; fn main() { let mut hw = String::new(); std::io::stdin().read_line(&mut hw).ok(); let hw: Vec = hw.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let h = hw[0]; let w = hw[1]; let mut temp = String::new(); std::io::stdin().read_line(&mut temp).ok(); let temp: Vec = temp.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let costs = [temp[0], temp[1], temp[2], temp[3]]; let k = temp[4]; let p = temp[5]; let mut temp = String::new(); std::io::stdin().read_line(&mut temp).ok(); let temp: Vec = temp.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let sx = temp[0]-1; let sy = temp[1]-1; let gx = temp[2]-1; let gy = temp[3]-1; let grid = (0..h).map(|_| { let mut temp = String::new(); std::io::stdin().read_line(&mut temp).ok(); let temp = temp.trim(); temp.chars().collect::>() }) .collect::>(); let mut dp = vec![vec![INF; w]; h]; dp[sx][sy] = 0; let mut pque = BinaryHeap::new(); pque.push((Reverse(0), sx, sy)); while let Some((Reverse(cost), x, y)) = pque.pop() { if dp[x][y] < cost { continue; } for dir in 0..4 { let nx = x as isize + DX[dir]; let ny = y as isize + DY[dir]; if nx >= 0 && ny >= 0 && nx < h as isize && ny < w as isize { let nx = nx as usize; let ny = ny as usize; if grid[nx][ny] == '#' { continue; } let ncost = cost + costs[dir] + if grid[nx][ny] == '@' { p } else { 0 }; if dp[nx][ny] <= ncost { continue; } dp[nx][ny] = ncost; pque.push((Reverse(ncost), nx, ny)); } } } if dp[gx][gy] > k { println!("No"); } else { println!("Yes"); } }