#include #define rep(i,a,b) for(int i=a;i=b;i--) #define fore(i,a) for(auto &i:a) #define all(x) (x).begin(),(x).end() #pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b using min_priority_queue = priority_queue, greater>; int dx[4] = { 0, 1, 0, -1 }, dy[4] = { -1, 0, 1, 0 }; int N, V, Ox, Oy, L[202][202]; //--------------------------------------------------------------------------------------------------- int vis[202][202]; void dji(int sx, int sy, vector> &d) { rep(y, 0, N) rep(x, 0, N) d[y][x] = inf; rep(y, 0, N) rep(x, 0, N) vis[y][x] = 0; min_priority_queue> que; que.push({ 0, sy * N + sx }); d[sy][sx] = 0; while (!que.empty()) { auto q = que.top(); que.pop(); int c = q.first; int x = q.second % N; int y = q.second / N; if (vis[y][x]) continue; vis[y][x] = 1; rep(i, 0, 4) { int xx = x + dx[i]; int yy = y + dy[i]; if (0 <= xx and xx < N and 0 <= yy and yy < N) if(!vis[yy][xx]) { if (d[y][x] + L[yy][xx] < d[yy][xx]) { d[yy][xx] = d[y][x] + L[yy][xx]; que.push({ d[yy][xx], yy * N + xx }); } } } } } //--------------------------------------------------------------------------------------------------- #define yes "YES" #define no "NO" string solve() { vector> d1(N, vector(N)); dji(0, 0, d1); vector> d2(N, vector(N)); dji(Ox, Oy, d2); // start -> goal if (d1[N - 1][N - 1] <= V) return yes; // start -> oasis -> goal if (d1[Oy][Ox] <= V and d1[Oy][Ox] + d2[N-1][N-1] <= (V - d1[Oy][Ox]) * 2) return yes; return no; } //--------------------------------------------------------------------------------------------------- void _main() { cin >> N >> V >> Ox >> Oy; Ox--; Oy--; rep(y, 0, N) rep(x, 0, N) cin >> L[y][x]; cout << solve() << endl; }