Artificial Lake
Time limit1sMemory limit128 MB
Water fills a terrain of N distinct-height platforms at 1 unit per minute; report when each platform first has 1 unit of water above it.
- Level
Hard8 of 10
- Topics
- Stack, Simulation, Greedy, Math
- Solved
- No attempts yet
Problem
On the hottest summer days, Farmer John decides to build an artificial lake. He models the lake as a two-dimensional landscape: a contiguous row of platforms numbered from left to right ().
Platform is described by two integers: its width () and its height (a relative elevation) (). All heights are distinct. Infinitely tall walls enclose the landscape on the left and the right. One example landscape profile is shown below.
* * :
* * :
* * 8
* *** * 7
* *** * 6
* *** * 5
* ********** 4 <- height
* ********** 3
*************** 2
*************** 1
Level | 1 |2| 3 |
Water pours into the bottom of the lowest platform at a rate of square unit per minute. The water falls straight down until it lands on something, and then it spreads out sideways as water always does. Assume that both the falling and the spreading happen instantly.
For each platform, determine the number of minutes after sunrise at which it first becomes covered by a layer of water exactly unit tall.
WATER WATER OVERFLOWS
| |
* | * * | * * *
* V * * V * * *
* * * .... * *~~~~~~~~~~~~*
* ** * *~~~~** : * *~~~~**~~~~~~*
* ** * *~~~~** : * *~~~~**~~~~~~*
* ** * *~~~~**~~~~~~* *~~~~**~~~~~~*
* ********* *~~~~********* *~~~~*********
*~~~~********* *~~~~********* *~~~~*********
************** ************** **************
************** ************** **************
After 4 mins After 26 mins After 50 mins
Lvl 1 submerged Lvl 3 submerged Lvl 2 submerged
Note: the answer will not always fit in 32 bits.
Input
- Line 1: a single integer .
- Lines 2 to : line describes platform with two space-separated integers, and .
Output
- Lines 1 to : line contains a single integer, the number of minutes after sunrise at which platform is first covered by a -unit-tall layer of water.