#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; template using pq = priority_queue, greater>; using ll = long long; int main(){ ll H, W, K, P, h, w, nh, nw, sh, sw, gh, gw, alt, d; cin >> H >> W; vector cost(4); for (int i=0; i<4; i++) cin >> cost[i]; cin >> K >> P >> sh >> sw >> gh >> gw; sh--; sw--; gh--; gw--; pq> que; int dx[4] = {-1, 1, 0, 0}; int dy[4] = {0, 0, 1, -1}; vector> dist(H, vector(W, 1e18)); vector> visit(H, vector(W)); vector field(H); for (int i=0; i < H; i++){ cin >> field[i]; } dist[sh][sw] = 0; que.push({0, sh, sw}); while(!que.empty()){ tie(d, h, w) = que.top(); que.pop(); if (visit[h][w]) continue; visit[h][w] = 1; for (int dir=0; dir < 4; dir++){ alt = dist[h][w] + cost[dir]; nh = h + dx[dir]; nw = w + dy[dir]; if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue; if (field[nh][nw] == '#') continue; if (field[nh][nw] == '@') alt += P; if (alt < dist[nh][nw]){ dist[nh][nw] = alt; que.push({dist[nh][nw], nh, nw}); } } } cout << (dist[gh][gw] <= K ? "Yes" : "No") << endl; return 0; }