An elevation profile is an array of n non-negative integer heights. You pour V units of water, one drop at a time, all above index K. Each drop settles using this rule (heights already include any water that has settled):
K, walk left across cells whose surface level does not rise (each next cell to the left has level <= the current cell). Among the cells reachable this way, if some cell is strictly lower than the level at K, the drop settles on the lowest such cell; if several tie for lowest, it settles on the one closest to K.K.Settling a drop raises that cell's level by 1. After all V drops, report the final levels.
Line 1: three integers n, V, K.
Line 2: n space-separated integers, the initial heights.
A single line: n space-separated integers, the final levels.
Example 1
Input
7 4 3 2 1 1 2 1 2 2
Expected
2 2 2 3 2 2 2
Explanation
Drops settle into the two valleys around index 3, filling them so the final profile is 2 2 2 3 2 2 2.
Example 2
Input
3 2 1 1 2 1
Expected
2 2 2
Explanation
The first drop flows left into the lower cell 0; the second flows right into cell 2, giving 2 2 2.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →