import java.util.* fun main(args: Array) { val (n,v,ox, oy) = readLine()!!.split(" ").map { it.toInt() } for(i in 1..n) { map.add(readLine()!!.split(" ").map { it.toInt() }) zeroZeroStart.add(MutableList(n, {500000})) oasisStart.add(MutableList(n, {500000})) } buildMap(zeroZeroStart, 0, 0) if(ox > 0 && oy > 0) { hasOasis = true buildMap(oasisStart, ox - 1, oy - 1) } val ans = if (canGoal(v, ox, oy)) "YES" else "NO" println(ans) } fun canGoal(vital: Int, oX:Int, oY:Int):Boolean { var subVital = vital if(zeroZeroStart.last().last() < subVital) { return true } if(!hasOasis) { return false } if(zeroZeroStart[oY][oX] >= subVital) { return false } subVital = (subVital - zeroZeroStart[oY][oX]) subVital = (subVital * 2) return subVital > zeroZeroStart.last().last() } var hasOasis = false; val map = mutableListOf>() val zeroZeroStart = mutableListOf>() val oasisStart = mutableListOf>() class Task(val x:Int, val y:Int, val step:Int) fun buildMap(target:MutableList>, startX:Int, startY:Int) { val queue = LinkedList() queue.add(Task(startX, startY, 0)) while (queue.isNotEmpty()) { val task = queue.pop() if(target[task.y][task.x] <= task.step) { continue } target[task.y][task.x] = task.step for(i in Math.max(0, task.y-1)..Math.min(target.lastIndex, task.y+1)) { for(j in Math.max(0, task.x-1)..Math.min(target.lastIndex, task.x + 1)) { if(i == task.y && j == task.x) { continue } if(i!=task.y && j!=task.x) { continue } val nextStep = task.step + map[i][j] queue.add(Task(j, i, nextStep)) } } } }