Library and Archives Canada recently decided to install an alarm system to safeguard the English essays of past generations, and they've hired you to help them.
The Archives may be represented by an 1
representing an empty room, and 0
representing a wall. Your task is to place exactly
There are a couple of restrictions:
- no alarm may be placed in a wall
- you may only place one alarm per column or row
- an alarm's range cannot overlap with the outside of the building
- alarm ranges can overlap
Knowing this, what is the maximum number of rooms you can hope to secure?
Input Specification
The first line of input will contain the integer
The next
The next line of input will contain the integer
The final line of input will contain
Output Specification
A single integer; the maximum number of rooms that may be covered by alarms.
Sample Input
4
0 1 1 0
0 1 1 1
1 1 1 1
1 1 1 0
4
1 2 1 1
Sample Output
10
Explanation
You can place the radius
Comments
Clarification
The problem statement states that you need to place exactly
alarms; along with the row/column restriction, isn't it possible for certain test cases to be impossible to fulfill? Such as any test case with 
, or less rooms than alarms.
What does it mean exactly by
For example, a square range of radius 2 covers
what does it mean:
Does it mean the alarm range cannot include wall or go outside the
square?
Thx
It cannot go outside the
area. For example, in
you may only place an alarm with
in the center.