#include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; const int DY[4] = {-1, 0, 1, 0}; const int DX[4] = {0, 1, 0, -1}; struct Node { int y; int x; int health; bool use_oasis; Node(int y = -1, int x = -1, int health = -1, bool use_oasis = false) { this->y = y; this->x = x; this->health = health; this->use_oasis = use_oasis; } bool operator>(const Node &n) const { return health < n.health; } }; int main() { int N, V, OX, OY; cin >> N >> V >> OX >> OY; int L[N][N]; --OX; --OY; for (int y = 0; y < N; ++y) { for (int x = 0; x < N; ++x) { cin >> L[y][x]; } } priority_queue , greater> pque; pque.push(Node(0, 0, V)); bool visited[N][N][2]; memset(visited, false, sizeof(visited)); while (not pque.empty()) { Node node = pque.top(); pque.pop(); if (visited[node.y][node.x][node.use_oasis]) continue; visited[node.y][node.x][node.use_oasis] = true; if (node.y == OY && node.x == OX) { node.health *= 2; node.use_oasis = true; } if (node.y == N - 1 && node.x == N - 1) { cout << "YES" << endl; return 0; } for (int direct = 0; direct < 4; ++direct) { int ny = node.y + DY[direct]; int nx = node.x + DX[direct]; if (ny < 0 || nx < 0 || N <= ny || N <= nx) continue; int nh = node.health - L[ny][nx]; if (nh <= 0) continue; pque.push(Node(ny, nx, nh, node.use_oasis)); } } cout << "NO" << endl; return 0; }