#include "bits/stdc++.h" using namespace std; using ll = long long; using ld = long double; const double PI = 3.1415926535897932384626433832795; const int dx[] = { 0, 1, 0, -1 }; const int dy[] = { -1, 0, 1, 0 }; int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); } ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); } int lcm(int x, int y) { return x / gcd(x, y) * y; } ll lcm(ll x, ll y) { return x / gcd(x, y) * y; } int n, v, ox, oy; vector> graph; vector> dijkstra(int sy, int sx) { vector> dist(n, vector(n, INT_MAX)); dist[sy][sx] = 0; priority_queue>, vector>>, greater>>> pq; pq.push({ dist[sy][sx], {sy, sx} }); while (!pq.empty()) { int nowCost = pq.top().first; int y = pq.top().second.first; int x = pq.top().second.second; pq.pop(); if (nowCost > dist[y][x]) { continue; } for (int i = 0; i < 4; i++) { int ny = y + dy[i]; int nx = x + dx[i]; if (ny < 0 || ny >= n || nx < 0 || nx >= n) { continue; } if (dist[ny][nx] > nowCost + graph[ny][nx]) { dist[ny][nx] = nowCost + graph[ny][nx]; pq.push({ dist[ny][nx] , {ny, nx} }); } } } return dist; } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> v >> ox >> oy; ox--; oy--; graph.resize(n, vector(n)); for (int y = 0; y < n; y++) { for (int x = 0; x < n; x++) { cin >> graph[y][x]; } } vector> dist = dijkstra(0, 0); if (dist[n - 1][n - 1] < v) { cout << "YES" << endl; return 0; } if (oy < 0 || ox < 0 || dist[oy][ox] < v) { cout << "NO" << endl; return 0; } int healHp = (v - dist[oy][ox]) * 2; vector> dist2 = dijkstra(oy, ox); cout << ((dist2[n - 1][n - 1] < healHp) ? "YES" : "NO") << endl; return 0; }