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.

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

Output
1 11 3 13 9 0 12 7 16 3 19 18 22 3 23 13 29 0