Quarry
InterviewTime limit1sMemory limit1024 MB
Apply K range commands that each lower the elevations on [S, E] by H to an initial array, then print every final elevation.
- Level
Easy3 of 10
- Topics
- Prefix sum, Array
- Solved
- No attempts yet
Statement
Useful minerals were found on a plot of land. The owner plans to install a new automatic excavation system, operate it, and turn the plot into a quarry.
The system digs one pit at a time. A pit starts at position and ends at position , both measured in meters from the start of the quarry, and its depth is meters.
The quarry can be drawn as a two-dimensional diagram that shows the elevation above sea level along the quarry, both at the beginning and after mineral extraction starts.
The system works by carrying out excavation commands. Each command lowers the elevation by meters on the interval . Figure 1 shows the elevation after two commands: the first digs on , the second digs on , and each digs a pit 1 meter deep. The area dug by the first command is green (light gray in the grayscale print), and the area dug by the second is blue (gray in the grayscale print).

Figure 1.
The owner knows which excavation commands will be given to the system. Before starting, the owner wants to know what the quarry will look like after all commands are executed.
Find the elevation of the quarry after all excavation commands are executed.
Input
The first line contains two integers, the length of the quarry and the number of commands .
The second line contains integers , the initial elevation above sea level at meters from the start of the quarry. The first value is the elevation at 0 meters from the start.
Each of the next lines contains three integers , , and , the start, end, and depth of the -th excavation command.
Output
Print numbers. The -th number is the elevation at meters from the start of the quarry after all commands are executed.
The final elevation can be negative.
Constraints