#include using namespace std; const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1}; struct Edge{ int node,cost; Edge(int node, int cost):node(node),cost(cost){ } }; struct State{ int hp,node; bool use; State(int node, int hp, bool use):hp(hp),node(node),use(use){} bool operator < (const State& right) const { return hp < right.hp; } }; int N,V,gx,gy; int board[220][220]; int cost[44000][2]; vector Edges[44000]; int main(){ cin >> N >> V >> gx >> gy; gx--; gy--; for (int i = 0; i < N; i++){ for (int j = 0; j < N; j++){ cin >> board[i][j]; } } for (int i = 0; i < N; i++){ for (int j = 0; j < N; j++){ int ny,nx; int node = i * N + j; for (int k = 0; k < 4; k++){ ny = i + dy[k]; nx = j + dx[k]; if (ny < 0 or nx < 0 or ny >= N or nx >= N)continue; int next_node = ny * N + nx; int cost = board[ny][nx]; Edges[node].push_back(Edge(next_node, cost)); } } } priority_queue que; que.push(State(0, V, false)); for (int i = 0; i < 44000; i++){ for (int j = 0; j < 2; j++){ cost[i][j] = -100; } } cost[0][0] = V; while (!que.empty()){ State pos = que.top(); que.pop(); if (cost[pos.node][pos.use] > pos.hp){ continue; } //cout << pos.node << " " << pos.hp << endl; if (!pos.use and pos.node == gy * N + gx){ pos.use = true; pos.hp *= 2; } if (pos.node == N * (N - 1) + (N - 1)){ cout << "YES" << endl; return 0; } for (int i = 0; i < Edges[pos.node].size(); i++){ Edge np = Edges[pos.node][i]; if (pos.hp - np.cost > 0){ if (cost[np.node][pos.use] < pos.hp - np.cost){ cost[np.node][pos.use] = pos.hp - np.cost; que.push(State(np.node, cost[np.node][pos.use], pos.use)); } } } } cout << "NO" << endl; return 0; }