The Lazy Cow
Time limit1sMemory limit128 MB
Choose the cell whose Manhattan diamond of radius K holds the most grass and output that sum.
- Level
Medium5 of 10
- Topics
- Prefix sum, Matrix
- Solved
- No attempts yet
Problem
On a hot summer day, Bessie the cow feels lazy. She wants to pick a starting cell in her field so that she can reach as much tasty grass as possible within a short walk.
The field is an grid (). Cell () contains units of grass (). From her starting cell, Bessie takes at most steps (). Each step moves her one cell north, south, east, or west.
Choose the best starting cell. Output the maximum total grass she can reach within steps.
Input
- Line 1: integers and .
- Lines 2 through : integers per line, row of the grid.
Output
- Line 1: the maximum total grass reachable within steps from the best starting cell.
Hint
Try every starting cell and sum grass reachable within steps.