cho.sh
Notes
Loading...

Skyline

Time limit

2s

Memory limit

128 MB

Problem

Given N rectangular buildings, compute the skyline formed by their union. Each building is described by its left x-coordinate L, height H, and right x-coordinate R, and all buildings stand on the same ground line.

The skyline is the outer outline of the rectangles when they are viewed together. Report every point where the visible height changes, from left to right.

Input

The first line contains the number of buildings N (1 <= N <= 100,000).

Each of the next N lines contains three integers L, H, and R, describing one building's left x-coordinate, height, and right x-coordinate.

The coordinates and heights satisfy 1 <= L < R <= 1,000,000,000 and 1 <= H <= 1,000,000,000.

Output

Print the skyline on one line. For each point where the height changes, print the x-coordinate of that point followed by the height from that point onward. Separate all values with spaces.