#K67612. Skyline Silhouette

    ID: 32682 Type: Default 1000ms 256MiB

Skyline Silhouette

Skyline Silhouette

In this problem, you are given a list of buildings where each building is represented by a triplet (l,r,h)(l, r, h), with ll being the left x-coordinate, rr the right x-coordinate, and hh the height of the building. The goal is to compute the skyline silhouette formed by these buildings when viewed from the front. The skyline is defined as a set of key points (x,y)(x, y) such that the height of the silhouette changes at these x-coordinates. More formally, if you denote the silhouette as a sequence of points (x1,h1),(x2,h2),,(xk,hk)(x_1, h_1), (x_2, h_2), \dots,(x_k, h_k), then for each segment, the height of the silhouette remains constant between consecutive key points. Your task is to generate these key points in increasing order of xx.

inputFormat

The input is given via standard input (stdin). The first line contains an integer nn indicating the number of buildings. Each of the next nn lines contains three space-separated integers: ll, rr, and hh, representing the left x-coordinate, right x-coordinate, and height of a building respectively.

outputFormat

Print the key points of the skyline to standard output (stdout). Each line should contain two integers xx and hh, where xx is an x-coordinate where the skyline changes and hh is the new height at that point. The points must be printed in increasing order of xx.## sample

3
1 4 10
2 6 15
5 8 12
1 10

2 15 6 12 8 0

</p>