Puju
InterviewTime limit1sMemory limit1024 MB
Given a row of N cells with thickets, find the largest plot Kazimir can reach after clearing thickets on a walk from S that uses at most K steps.
- Level
Medium5 of 10
- Topics
- Two pointers, Prefix sum, Greedy
- Solved
- No attempts yet
Statement
Aednik Kazimir recently bought a new plot of land made of cells in a row. The cells are numbered to from left to right. Unfortunately, some cells are overgrown with puju thickets, so they are not suitable for gardening. To clear them, Kazimir rented a weeding tractor.
At the start, Kazimir is on cell with the tractor. In each step he can move from his current cell to one of its neighbors, cell or cell . If the new cell has thickets, the tractor uproots them and the cell becomes suitable for gardening. The tractor has fuel for only steps.
After the weeding, Kazimir can move without limit between cells free of thickets and plant anywhere he likes, but he cannot pass through cells with thickets. Find the maximum area where Kazimir can grow plants.
Input
The first line contains the plot size (), the tractor fuel (), and Kazimir's starting cell ().
The second line contains exactly characters. '.' marks a cell without thickets and '#' marks a cell with thickets. Cell is suitable for gardening.
Output
Print the maximum number of cells where Kazimir can start growing plants.