Andres Iniesta
Time limit1sMemory limit128 MB
You remove up to K obstacles and choose a standing cell to maximize visible cells in its row and column.
- Level
Medium5 of 10
- Topics
- Brute force, Prefix sum, Matrix
- Solved
- No attempts yet
Problem
Midfielder Andres Iniesta trains on an grid where some cells hold obstacles. He stands on an empty cell and sees every cell in the same row or column with no obstacle between them, including his own cell.
Iniesta can destroy obstacles with a ball, at most times. After destroying obstacles, find the maximum number of cells he can see from some empty cell. He may stand on a cell that was empty initially or on a cell whose obstacle he destroyed.
Input
The first line contains , , and : the number of rows, columns, and the maximum obstacles he may destroy.
Each of the next lines has characters: . for an empty cell and * for an obstacle.
Output
Print one integer: the maximum number of visible cells after destroying up to obstacles and standing on an empty cell.
Constraints
Hint
Only obstacles on Iniesta's row and column affect his view from a chosen cell. For each candidate cell, try destroying up to obstacles on that row and column and count visible cells.