#K92302. Reach the Bottom-Right Corner

    ID: 38167 Type: Default 1000ms 256MiB

Reach the Bottom-Right Corner

Reach the Bottom-Right Corner

You are given a grid with N rows and M columns, where each cell contains an integer value that may be positive or negative. A prince starts at the top-left corner (cell (1,1)) with an initial energy E. The energy in the starting cell is added to his energy, i.e. his starting energy becomes E + grid[1][1].

From any cell, the prince can move up, down, left, or right if the destination cell is within the grid boundaries. Each move costs 1 unit of energy and when he lands on a new cell, he additionally gains the energy value written in that cell. The objective is to determine whether the prince can reach the bottom-right corner (cell (N, M)) with a non-negative amount of energy (i.e. at least 0 energy remaining) at the moment of arrival.

If he can reach the destination, output YES; otherwise, output NO.
The energy update when moving to a new cell at position (i,j) is as follows:

\[ \text{new energy} = \text{current energy} - 1 + grid[i][j] \]

inputFormat

The first line of input contains three space-separated integers: N, M, and E — the number of rows, the number of columns, and the initial energy, respectively.

Then follow N lines, each containing M space-separated integers representing the grid.

outputFormat

Output a single line containing either YES if the prince can reach the bottom-right corner with non-negative energy remaining, or NO otherwise.

## sample
4 4 10
3 2 1 3
2 -1 -2 2
5 -3 4 1
3 1 2 -2
YES