UVa 105 - The Skyline Problem

105 - The Skyline Problem

 * http://acm.uva.es/p/v1/105.html

Summary
This problem has an easy solution due to the constraints. Since the buildings lies between 0 and 10,000 inclusively, using a height map should suffice.

Explanation
We can use an array of 10,000 elements to represent the height of each individual discrete x-coordinate. For each x-coordinate, we take the highest of all the heights of all the buildings within the range. For each adjacent x-coordinates, report if there is a change in the height.

At one point, there were trick cases with negative coordinates, but it's been corrected since.

Gotcha's

 * Negative coordinates.
 * The start and end points of buildings may be on the same x-coordinate.

Input
1 11 5 1 20 6 2 6 7 3 13 9 12 7 16 14 3 25 15 8 16 19 18 22 23 13 29 24 4 28

Output
1 20 6 13 9 0 12 7 15 8 16 3 19 18 22 3 23 13 29 0