Precarious Stacks
Time limit4sMemory limit1024 MB
Given N squares dropped in order, each landing on the ground or on earlier squares, report the highest y coordinate after each drop.
- Level
Medium5 of 10
- Topics
- Segment tree, Sorting
- Solved
- No attempts yet
Problem
It has been difficult to find a job in the tech industry lately. You landed a job at a construction company, but some of the tasks assigned to you make you wonder whether the engineers have ever heard of gravity. In the latest task, you must evaluate a model of a construction project.
The model is built by dropping axis-aligned squares toward the ground, which is the line . Each square has a fixed coordinate and size. A square moves downward until its bottom face touches the ground or another square. Once a square lands, it is fastened in place, so even if two squares are off balance, they do not fall over.
Given the squares and the order in which to drop them, find the maximum coordinate that the structure reaches after each square is placed.
Input
The first line contains an integer (), the number of squares. Each of the next lines describes a square in the order it is dropped. Line contains two integers () and (), the coordinate of the left edge of square and its size.
Output
Print lines. Line contains the highest coordinate reached by the structure after squares have been dropped.