#include #include #include #include #include using namespace std; const long long INF = 1LL << 60; // 1.15x10^18 template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using edge = pair; using Graph = vector>; vector dijkstra(const Graph &g, int s) { vector dist(g.size(), INF); using Pi = pair; priority_queue, greater> que; dist[s] = 0; que.emplace(dist[s], s); while (!que.empty()) { long long cost; int u; tie(cost, u) = que.top(); que.pop(); if (dist[u] < cost) continue; for (auto &e: g[u]) { int v; long long nc; tie(v, nc) = e; if (chmin(dist[v], dist[u] + nc)) que.emplace(dist[v], v); } } return dist; } int main() { int n, v, oi, oj; cin >> n >> v >> oj >> oi; Graph g(n * n); auto idx = [&](int i, int j) { return i * n + j; }; auto out_field = [&](int i, int j) { return i < 0 || i >= n || j < 0 || j >= n; }; int dij[] = {0, 1, 0, -1, 0}; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) { int cost; cin >> cost; for (int k = 0; k < 4; k++) { int ni = i + dij[k], nj = j + dij[k + 1]; if (out_field(ni, nj)) continue; g[idx(ni, nj)].emplace_back(idx(i, j), cost); } } auto dist_s = dijkstra(g, idx(0, 0)); bool ok = dist_s[idx(n - 1, n - 1)] < v; if (oi != 0 && oj != 0) { oi--, oj--; auto dist_o = dijkstra(g, idx(oi, oj)); ok |= dist_o[idx(n - 1, n - 1)] < 2 * (v - dist_s[idx(oi, oj)]); } cout << (ok ? "YES" : "NO") << endl; return 0; }