Tetrooj Box
Time limit5sMemory limit1024 MB
Blocks are dropped onto a base of width b, each landing on the base or the highest block below it. The task is to find the final tallest column height.
- Level
Easy3 of 10
- Topics
- Array, Simulation
- Solved
- No attempts yet
Problem
Dr. Orooji's children have played Tetris but are not willing to help Dr. O with a related problem. Dr. O's children don't realize that Dr. O is lucky to have access to 100+ great problem solvers and great programmers today!
Dr. O knows the length of the base for a 2D box and wants to figure out the needed height for the box. Dr. O will drop some 2D blocks (rectangles) on the base. A block will go down until it lands on the base or is stopped by an already-dropped block (i.e., it lands on that block). After all the blocks have been dropped, the needed height for the box is determined by the tallest column. See the pictures in the hint section.
Input
The first input line contains two integers: (), the length of the base, and (), the number of blocks. Each of the next lines contains three integers: a block's horizontal length (), its vertical length (), and (), the leftmost column the block is dropped into. The values of and are such that the block does not go beyond the base, i.e., .
Output
Print the needed height for the box. The tallest column is the height.
Hint

