#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(y, n) REP(x, n) cin >> field[y][x]; Graph g(n*n); REP(y, n) REP(x, n) { REP(d, 4) if (contain(y + dy[d], n) && contain(x + dx[d], n)) { g[y*n + x].push_back({ (y + dy[d])*n + (x + dx[d]), field[y + dy[d]][x + dx[d]] }); } } auto dist = dijkstra(0, g); if (dist[n*n - 1] < v) { cout << "YES" << endl; }else if (ox != 0) { v -= dist[(oy-1)*n + ox-1]; v *= 2; dist = dijkstra((oy-1)*n + ox-1, g); cout << (dist[n*n - 1] < v ? "YES" : "NO") << endl; } else { cout << "NO" << endl; } return 0; }