import java.util.Comparator; import java.util.HashSet; import java.util.PriorityQueue; import java.util.Scanner; public class Main { static int N, L, OX, OY; static int[][] LL; static int[][][] cost; static boolean[][] check; static int[][] mincost; static int[] dx = {1, 0, -1, 0}; static int[] dy = {0, 1, 0, -1}; public static void dik(int sx, int sy) { for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { check[i][j] = false; mincost[i][j] = Integer.MAX_VALUE / 2; } } PriorityQueue queue = new PriorityQueue(new Comparator() { public int compare(int[] a, int[] b) { int t = mincost[a[1]][a[0]] - mincost[b[1]][b[0]]; if(t > 0) return 1; else if(t == 0) return 0; else { return -1; } } }); mincost[sy][sx] = 0; queue.offer(new int[]{sx, sy}); while (!queue.isEmpty()) { int[] q = queue.poll(); int x = q[0]; int y = q[1]; check[y][x] = true; for (int i = 0; i < 4; i++) { int xx = x + dx[i]; int yy = y + dy[i]; if( !(0 <= xx && xx <= N-1) ) continue; if( !(0 <= yy && yy <= N-1) ) continue; if(check[yy][xx] == true) continue; mincost[yy][xx] = Math.min(mincost[yy][xx], mincost[y][x] + cost[y][x][i]); queue.offer(new int[]{xx, yy}); } } } public static int solve(){ cost = new int[N][N][4]; check = new boolean[N][N]; mincost = new int[N][N]; for (int y = 0; y < N; y++) { for (int x = 0; x < N; x++) { for (int i = 0; i < 4; i++) { int xx = x + dx[i]; int yy = y + dy[i]; if( !(0 <= xx && xx <= N-1) || !(0 <= yy && yy <= N-1) ) { cost[y][x][i] = Integer.MAX_VALUE / 2; continue; } cost[y][x][i] = LL[yy][xx]; } } } dik(0, 0); int stog = mincost[N-1][N-1]; if(stog < L) { System.out.println("YES"); return 0; } if(OX == 0 && OY == 0) { System.out.println("NO"); return 0; } int stoo = mincost[OY-1][OX-1]; dik(OX-1, OY-1); int otog = mincost[N-1][N-1]; if(stoo >= L) { System.out.println("NO"); return 0; } L = (L - stoo) * 2; if(otog >= L) { System.out.println("NO"); return 0; } System.out.println("YES"); return 0; } public static void main(String[] args){ Scanner S = new Scanner(System.in); N = S.nextInt(); L = S.nextInt(); OX = S.nextInt(); OY = S.nextInt(); LL = new int[N][N]; for (int y = 0; y < N; y++) { for (int x = 0; x < N; x++) { LL[y][x] = S.nextInt(); } } solve(); } }