Stacking horizontal blocks
Time limit1sMemory limit512 MB
Drop N horizontal blocks one by one at fixed positions, each landing on the tallest surface below it, and report the final stack height.
- Level
Medium7 of 10
- Topics
- Segment tree, Binary search, Prefix sum, Implementation
- Solved
- No attempts yet
Problem
You are going to play a game of Tetris in which only horizontal blocks appear. A total of horizontal blocks will appear, numbered in the order they appear. Block has height and width . Block must be dropped at a distance of from the left wall. Rotating a block or moving its position is not possible.
A block falls from above, moving down one unit at a time until it hits another block or the floor. Given the information for the blocks, find the height of the stack.
Input
The first line gives the number of blocks (). Each of the next lines gives the information () for one block, from block to block in order.
Output
Print the height of the stack after all blocks have been placed.