using System; using System.Collections.Generic; using System.Text; class Program { public void Proc() { Reader.IsDebug = false; int[] inpt = Reader.GetInt(); int mapLength = inpt[0]; int maxTairyoku = inpt[1]; int oasisX = inpt[2] - 1; int oasisY = inpt[3] - 1; int[,] map = new int[mapLength, mapLength]; int[,] step = new int[mapLength, mapLength]; for (int i = 0; i < mapLength; i++) { inpt = Reader.GetInt(); for (int j = 0; j < mapLength; j++) { map[i, j] = inpt[j]; } } step[0, 0] = maxTairyoku; Queue task = new Queue(); task.Enqueue(new int[] { 0, 0 }); while (task.Count > 0) { int[] pos = task.Dequeue(); int x = pos[0]; int y = pos[1]; List nextPos = new List(); if (x > 0) { nextPos.Add(new int[] { x - 1, y }); } if (x < mapLength - 1) { nextPos.Add(new int[] { x + 1, y }); } if (y > 0) { nextPos.Add(new int[] { x, y - 1 }); } if (y < mapLength - 1) { nextPos.Add(new int[] { x, y + 1 }); } int nowHP = step[y, x]; foreach (int[] nextP in nextPos) { int nextX = nextP[0]; int nextY = nextP[1]; if (map[nextY, nextX] < nowHP) { int nextHp = nowHP - map[nextY, nextX]; if (nextX == oasisX && nextY == oasisY) { nextHp *= 2; } if (nextHp > step[nextY, nextX]) { step[nextY, nextX] = nextHp; task.Enqueue(new int[] { nextX, nextY }); } } } } if (step[mapLength - 1, mapLength - 1] > 0) { Console.WriteLine("YES"); } else { Console.WriteLine("NO"); } } public class Reader { public static bool IsDebug = true; private static String PlainInput = @" "; private static System.IO.StringReader Sr = null; public static string ReadLine() { if (IsDebug) { if (Sr == null) { Sr = new System.IO.StringReader(PlainInput.Trim()); } return Sr.ReadLine(); } else { return Console.ReadLine(); } } public static int[] GetInt(char delimiter = ' ') { string[] inpt = ReadLine().Split(delimiter); int[] ret = new int[inpt.Length]; for (int i = 0; i < inpt.Length; i++) { ret[i] = int.Parse(inpt[i]); } return ret; } } static void Main() { Program prg = new Program(); prg.Proc(); } }