eolymp
bolt
Try our new interface for solving problems
Problems

City Horizon

City Horizon

Farmer John has taken his cows on a trip to the city! As the sun sets, the cows gaze at the city horizon and observe the beautiful silhouettes formed by the rectangular buildings. The entire horizon is represented by a number line with $n$ buildings. Building $i$'s silhouette has a base that spans locations $a_i$ through $b_i$ along the horizon and has height $h_i$. Determine the area, in square units, of the aggregate silhouette formed by all $n$ buildings. \InputFile The first line contains a single integer $n~(1 \le n \le 40000)$. Each of the next $n$ lines describes building $i$ with three integers: $a_i, b_i~(1 \le a_i < b_i \le 10^9)$ and $h_i~(1 \le h_i \le 10^9)$. \OutputFile Print the total area, in square units, of the silhouettes formed by all $n$ buildings. \includegraphics{https://eolympusercontent.com/images/1ga0u0pmsp1uh18i4vi9rn0h6c.gif}
Time limit 1 second
Memory limit 128 MiB
Input example #1
4
2 5 1
9 10 4
6 8 2
4 6 3
Output example #1
16
Source 2007 USACO US Open, Silver Division