Editorial for Baltic OI '02 P3 - Triangles
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.

We can use a plane sweep method sweeping from left to right. There are three kinds of event points for the algorithm (denoted in Figure 1 by gray arrows):
- beginning of new triangle (value
from description); - crossing point of one triangle horizontal edge with others hypotenuse;
- rightmost vertex of some triangle (value
from task description).
If we look at these event points consecutively, we can calculate common area
increasing, if we at each event point
Then increment for each gap between two neighbour event points
Comments