#include using namespace std; const int INF = 100000; vector dy = {1, 0, -1, 0}; vector dx = {0, 1, 0, -1}; int main(){ int N, V, Ox, Oy; cin >> N >> V >> Ox >> Oy; Ox--; Oy--; vector> L(N, vector(N)); for (int i = 0; i < N; i++){ for (int j = 0; j < N; j++){ cin >> L[i][j]; } } vector> S1(N, vector(N, INF)); priority_queue, vector>, greater>> pq1; pq1.push(make_tuple(L[0][0], 0, 0)); while (!pq1.empty()){ int c = get<0>(pq1.top()); int y = get<1>(pq1.top()); int x = get<2>(pq1.top()); pq1.pop(); if (S1[y][x] == INF){ S1[y][x] = c; for (int i = 0; i < 4; i++){ int y2 = y + dy[i]; int x2 = x + dx[i]; if (0 <= y2 && y2 < N && 0 <= x2 && x2 < N){ if (S1[y2][x2] == INF){ pq1.push(make_tuple(c + L[y2][x2], y2, x2)); } } } } } if (Ox == -1 && Oy == -1){ if (S1[N - 1][N - 1] < V){ cout << "YES" << endl; } else { cout << "NO" << endl; } } else { if (S1[N - 1][N - 1] < V){ cout << "YES" << endl; } else if (S1[Oy][Ox] >= V){ cout << "NO" << endl; } else { vector> S2(N, vector(N, INF)); priority_queue, vector>, greater>> pq2; pq2.push(make_tuple(0, Oy, Ox)); while (!pq2.empty()){ int c = get<0>(pq2.top()); int y = get<1>(pq2.top()); int x = get<2>(pq2.top()); pq2.pop(); if (S2[y][x] == INF){ S2[y][x] = c; for (int i = 0; i < 4; i++){ int y2 = y + dy[i]; int x2 = x + dx[i]; if (0 <= y2 && y2 < N && 0 <= x2 && x2 < N){ if (S2[y2][x2] == INF){ pq2.push(make_tuple(c + L[y2][x2], y2, x2)); } } } } } if (S2[N - 1][N - 1] <= (V - S1[Oy][Ox]) * 2){ cout << "YES" << endl; } else { cout << "NO" << endl; } } } }