I want to do conventional deadlifts
InterviewTime limit1sMemory limit1024 MB
Find the minimum sum of watchfulness values on a right-and-down path from the top-left to the bottom-right cell of a grid, then check whether it is at most H.
- Level
Easy3 of 10
- Topics
- Dynamic programming, Matrix
- Solved
- No attempts yet
Problem
Jaehyeon is a beginner who believes he must do conventional deadlifts (lifting a barbell off the floor) to build his lower body. The biggest drawback of conventional deadlifts is noise. When the barbell is set back down, noise and vibration happen even with a platform. Strict gym regulars will not allow a skinny beginner like Jaehyeon to do conventional deadlifts, even in a gym where they are permitted. Help Jaehyeon do the lift without the regulars noticing.
The gym entrance is at the top left of an grid map, at row 1, column 1. The barbell is at the bottom right, at row , column . Each cell may contain gym regulars, and each regular has a watchfulness value. Jaehyeon starts at the entrance and walks to the barbell. If the total watchfulness of the regulars he meets is greater than his stealth , he cannot do the deadlift. Meeting a regular means being in the same cell as that regular. Jaehyeon can move only right or down, and he cannot leave the map. Given , determine whether Jaehyeon can do the deadlift.
Input
The first line contains and . ()
The next lines each contain integers describing the map. A is an empty cell, and a positive integer is the watchfulness of the gym regular in that cell.
The last line contains Jaehyeon's stealth .
Both the stealth and the watchfulness values are integers from to .
Output
If Jaehyeon can do the conventional deadlift, print "YES" on the first line. On the second line, print the minimum total watchfulness of the regulars he meets on the way to the barbell. Otherwise, print "NO".