#include using namespace std; using ll = long long; using vi = vector; using vb = vector; using vd = vector; using vl = vector; using vvi = vector; using vvb = vector; using vvd = vector; using vvl = vector; #define REP(i,n) for(ll i=0; i<(n); ++i) #define FOR(i,b,n) for(ll i=(b); i<(n); ++i) #define ALL(v) (v).begin(), (v).end() #define TEN(x) ((ll)1e##x) typedef ll Id; typedef ll Distance; #define INF_DIST numeric_limits::max() struct Edge{Id to; Distance cost;}; typedef vector> Graph; vector dijkstra(Id s, const Graph & g){ vector d(g.size(), INF_DIST); d[s] = 0; typedef pair P; priority_queue, greater

> que; que.push(P(0, s)); while(!que.empty()){ P p = que.top(); que.pop(); Id v = p.second; if(d[v] < p.first) continue; for (Edge e : g[v]) if(d[e.to] > d[v] + e.cost){ d[e.to] = d[v] + e.cost; que.push(P(d[e.to], e.to)); } } return d; } ll dx[] = { -1, 0, 1, 0 }; ll dy[] = { 0, -1, 0, 1 }; bool contain(ll x, ll max_x) { return 0 <= x && x < max_x; } int main() { ll n, v, ox, oy; cin >> n >> v >> ox >> oy; vvl field(n, vl(n)); REP(i, n) REP(j, n) cin >> field[i][j]; Graph g(n*n); REP(i, n) REP(j, n) { REP(d, 4) if (contain(i + dx[d], n) && contain(j + dy[d], n)) { g[i*n + j].push_back({ (i + dx[d])*n + (j + dy[d]), field[i + dx[d]][j + dy[d]] }); } } auto dist = dijkstra(0, g); if (dist[n*n - 1] < v) { cout << "YES" << endl; }else if (ox != 0) { v -= dist[(ox-1)*n + oy-1]; v *= 2; dist = dijkstra(ox*n+oy, g); cout << (dist[n*n - 1] < v ? "YES" : "NO") << endl; } else { cout << "NO" << endl; } return 0; }