#include #define rep(i, a) for (int i = 0; i < (a); i++) #define rep2(i, a, b) for (int i = (a); i < (b); i++) #define repr(i, a) for (int i = (a) - 1; i >= 0; i--) #define repr2(i, a, b) for (int i = (b) - 1; i >= (a); i--) using namespace std; typedef long long ll; const ll inf = 1e9; const ll mod = 1e9 + 7; int N, V, Ox, Oy; int L[200][200]; int dp[200][200][2]; // y, x, oasis typedef tuple P; // life, oasis, y, x int main() { cin >> N >> V >> Oy >> Ox; Ox--; Oy--; rep (j, N) rep (i, N) cin >> L[i][j]; priority_queue

q; q.emplace(V, false, 0, 0); memset(dp, -1, sizeof(dp)); dp[0][0][0] = V; while (!q.empty()) { P p = q.top(); q.pop(); int y = get<2>(p); int x = get<3>(p); bool oasis = get<1>(p); int dy[] = {0, 1, 0, -1}; int dx[] = {1, 0, -1, 0}; rep (k, 4) { int ny = y + dy[k]; int nx = x + dx[k]; if (ny < 0 || ny >= N || nx < 0 || nx >= N) continue; if (ny == Oy && nx == Ox && !oasis) { if (dp[y][x][0] - L[ny][nx] > 0) { if (dp[ny][nx][1] < (dp[y][x][0] - L[ny][nx]) * 2) { dp[ny][nx][1] = (dp[y][x][0] - L[ny][nx]) * 2; q.emplace(dp[ny][nx][1], true, ny, nx); } } } if (dp[y][x][oasis] - L[ny][nx] > 0) { if (dp[ny][nx][oasis] < dp[y][x][oasis] - L[ny][nx]) { dp[ny][nx][oasis] = dp[y][x][oasis] - L[ny][nx]; q.emplace(dp[ny][nx][oasis], oasis, ny, nx); } } } } if (dp[N - 1][N - 1][0] > 0 || dp[N - 1][N - 1][1] > 0) { cout << "YES" << endl; } else { cout << "NO" << endl; } return 0; }