Platform Support Pillars
Time limit2sMemory limit128 MB
Given platforms with heights and horizontal spans, compute the total length of vertical support pillars placed slightly inside each platform's ends resting on the floor or a lower platform.
- Level
Medium4 of 10
- Topics
- Simulation, Sorting, Geometry, Array
- Solved
- No attempts yet
Problem
A level for a new platform game is being designed. The platform positions have already been chosen. A platform cannot float in the air, so it needs support pillars. More precisely, each platform needs a pillar placed 0.5 units inward from each end, and each pillar must stand on the floor or on a lower platform.
Each platform is described by its height Y, horizontal start coordinate X1, and horizontal end coordinate X2. The pillars drop vertically at the position 0.5 units to the right of the left end and 0.5 units to the left of the right end.
Find the total length of pillars needed to support all platforms.
Input
The first line contains an integer N (1 ≤ N ≤ 100), the number of platforms.
Each of the next N lines contains three integers Y, X1, and X2, describing one platform. Y is the height, while X1 and X2 are the horizontal start and end coordinates. All coordinates are positive integers less than 10000, and X2 > X1 + 1, so every platform has length at least 2.
The input is arranged so that no two platforms overlap.
Output
Output the total length of pillars needed to support all platforms.

