Editorial for Baltic OI '12 P4 - Fireworks in RightAngleles
Submitting an official solution before solving the problem yourself is a bannable offence.
First we can see that there is no difference between positive and negative values, so all intersections we can transform to . If we have to calculate minimal distance that citizen has to walk from single intersection then it depends from firework and intersection location:
If fireworks is in point and a citizen lives in intersection with coordinates , then if is in region
- citizen must walk distance .
So if we have fixed firework position then all that is needed to calculate total distance for multiple intersections simultaneously are (for each region):
- Number of citizens in this region;
- Sum of x coordinates;
- Sum of y coordinates.
Which firework positions can give minimal total distance? As all distance functions are linear (while point do not change its region) then sum is also linear function therefore total function minimum (or one of them) will be when one of citizen house location is positioned on border between different regions. We can create all events (there are events) when citizen house location cross any border, sort these events and use sweep line technique to process all events - each event require to calculate function value in this point ( on each event) and update point that caused event region. Total complexity ) because we have to sort all events and sweep line phase is .
Comments