You are stuck in the top left room in an NxN grid of rooms. You need to get from

your starting room to the exit, which is the bottom right room. Each room is

connected by doors to its neighboring. All doors are locked in such a way that

you can only move down or to the right from one room to the next. For example,

if N = 3, and the rooms were labeled with letters as follows,

a b c

d e f

g h i

then you are starting in room "a" and trying to get to room "i". One possible

path would be a->d->g->h-i. Another possible path is a->b->e->h->i. However, you

can't go a->d->e->b->c->f->i.

Each room has a wolf in it. Each wolf requires a certain amount of food

before he is sated. If you enter a room without sufficient food to feed that

room's wolf, you won't survive. You start your journey with a given amount of

food. Each time you enter a room and feed a wolf, you use up that amount of

food.

After leaving this complex, you have no way of disposing of any excess food you

have. The more food you have when you leave, the more likely you are to get

caught, since the mad scientist who runs the facility employs food-tracking

wolf to catch runaways. Therefore, you want to leave with as little food as

possible.

Given:

a grid of size NxN, where each cell of the grid corresponds to the wolf

in that room's food requirement

your starting amount of food F

return how much food you will have left if you take the path that uses up as

much of your food as possible, while still allowing you to make your way through

the maze without getting eaten.

the first room (the starting room) will never have a wolf in it, so its

corresponding number will always be 0.

Examples:

in: grid = [[0,1,3,9], [3,9,3,3], [4,6,4,6], [8,6,8,2]], food = 20

out: 1

in: grid = [[0,8,7,7], [3,4,2,6], [7,9,6,6], [9,7,2,8]], food = 20