#C9061. Maximize Irrigation in the Garden

    ID: 53113 Type: Default 1000ms 256MiB

Maximize Irrigation in the Garden

Maximize Irrigation in the Garden

Mina, a dedicated botanist, has designed her plant garden as an N × M grid. Each cell in the grid either contains a plant (denoted by P) or is empty (denoted by .). She has a special irrigation pipe that can be laid either horizontally or vertically over contiguous cells. The irrigation pipe has a fixed length L and can water all plants covered by it.

Your task is to help Mina determine the maximum number of plants that can be watered by placing the pipe optimally. The optimal placement can be either horizontal or vertical.

Mathematically, if we denote the grid cells by gi,j (with i = 1,...,N and j = 1,...,M), then for any placement of the pipe spanning L contiguous cells, the number of watered plants is given by:

$$\text{count} = \sum_{k=0}^{L-1} [g_{i+k,j} = P] \quad \text{or} \quad \sum_{k=0}^{L-1} [g_{i,j+k} = P]$$

where the indicator function [condition] equals 1 if the condition holds and 0 otherwise.

inputFormat

The first line of input contains three integers N, M, and L separated by spaces, where:

  • N is the number of rows of the garden grid.
  • M is the number of columns of the garden grid.
  • L is the length of the irrigation pipe.

The next N lines each contain a string of M characters. Each character is either P (representing a plant) or . (representing an empty cell).

outputFormat

Output a single integer: the maximum number of plants that can be watered by optimally placing the irrigation pipe of length L either horizontally or vertically.

## sample
4 5 3
P..PP
..P..
PP..P
..PPP
3

</p>