#include using namespace std; struct Node { int at; int cost; int prev; Node(int at, int cost, int prev) : at(at), cost(cost), prev(prev) {} bool operator>(const Node &s) const { if (cost != s.cost) return cost > s.cost; if (prev != s.prev) return prev > s.prev; //最短経路を辞書順最小にする(省略可) return at > s.at; } }; struct Edge { int to; int cost; Edge(int to, int cost) : to(to), cost(cost) {} }; typedef vector > AdjList; //隣接リスト const int INF = 1000000000; const int NONE = -1; AdjList graph; //sは始点、mincは最短経路のコスト、Prevは最短経路をたどる際の前の頂点 void dijkstra(int s, vector &minc, vector &Prev){ priority_queue, greater > pq; pq.push(Node(s, 0, NONE)); while(!pq.empty()) { Node cur = pq.top(); pq.pop(); if (minc[cur.at] != INF) continue; minc[cur.at] = cur.cost; Prev[cur.at] = cur.prev; for(int i = 0; i < (int)graph[cur.at].size(); i++) { Edge e = graph[cur.at][i]; if (minc[e.to] == INF) { pq.push(Node(e.to, cur.cost + e.cost, cur.at)); } } } } const int dh[] = {1, -1, 0, 0}; const int dw[] = {0, 0, 1, -1}; int main() { cin.tie(0); ios::sync_with_stdio(false); int n, v, ox, oy; cin >> n >> v >> ox >> oy; ox--; oy--; vector< vector > L(n, vector(n)); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> L[i][j]; } } graph.resize(n * n); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { for (int k = 0; k < 4; k++) { int h = i + dh[k], w = j + dw[k]; if (h < 0 || h >= n || w < 0 || w >= n) continue; graph[i * n + j].emplace_back(h * n + w, L[h][w]); } } } vector minc(n * n, INF), Prev(n * n, NONE); dijkstra(0, minc, Prev); if (minc[n * n - 1] < v) { cout << "YES" << endl; return 0; } if (ox == -1 && oy == -1) { cout << "NO" << endl; return 0; } if (minc[ox * n + oy] >= v) { cout << "NO" << endl; return 0; } v -= minc[ox * n + oy]; v *= 2; minc.resize(n * n, INF); Prev.resize(n * n, NONE); dijkstra(ox * n + oy, minc, Prev); cout << (minc[n * n - 1] < v ? "YES" : "NO") << endl; return 0; }