#K54907. Taco Path Sum Problem

    ID: 29857 Type: Default 1000ms 256MiB

Taco Path Sum Problem

Taco Path Sum Problem

Given an (n \times n) grid of integers and an integer (k), determine whether there exists a path from the top-left corner to the bottom-right corner such that the sum of the numbers along the path is less than or equal to (k). You may only move either to the right or down.

Formally, let (G_{ij}) denote the integer in the cell at row (i) and column (j) (with (0 \le i,j < n)). We seek a sequence of cells starting at ((0,0)) and ending at ((n-1, n-1)) such that each move is either right (((i,j) \to (i, j+1))) or down (((i,j) \to (i+1, j))) and the total sum (\sum G_{ij} \le k). Output YES if such a path exists, and NO otherwise.

inputFormat

The first line contains two integers (n) and (k) separated by a space, where (n) is the size of the grid and (k) is the maximum allowed sum. Then follow (n) lines, each containing (n) space-separated integers representing the grid.

outputFormat

Print a single line with YES if there exists a valid path from the top-left to the bottom-right with a total sum (\le k), otherwise print NO.## sample

3 23
5 9 1
6 7 11
8 2 3
YES

</p>