Farmer Bill's Problem
Time limit2sMemory limit128 MB
Place non-overlapping, non-touching rectangles inside a rectangular field so all given circles lie within them, minimizing total rectangle area, and output the remaining harvestable area.
- Level
Hard8 of 10
- Topics
- Geometry, Dynamic programming, Intervals, Sorting
- Solved
- No attempts yet
Problem
It is rumored that planet Earth is often visited by Unidentified Flying Objects (UFOs). Sometimes a UFO lands and leaves a burned-out region behind. Observations show that these regions always have the shape of a circle.
Recently farmer Bill found such circles on his neat rectangular wheat field. Bill loves all mysterious things, so he decided to keep these circles on the field. However, Bill is first of all a farmer, so he still needs to harvest his wheat. He therefore decided to keep some regions containing the circles intact and harvest the rest of the field.
Every region that Bill keeps unharvested must be a rectangle, and the rectangles must neither touch nor overlap one another. The sides of the rectangles must be parallel to the sides of the field. Every circle left by the UFOs must lie completely inside these regions. The total area of the regions must be as small as possible, so that Bill can harvest the largest possible part of his field.
Find the total area of the field that Bill will be able to harvest.

Input
The first line contains two integers and --- the dimensions of Bill's field (). The field is placed on the plane so that its corners are at , , and .
The second line contains --- the number of circles left by the UFOs (). Each of the next lines describes one circle with three positive integers , and --- the coordinates of its center and its radius. Circles may touch, overlap, or contain one another. Every circle lies completely inside the field.
Output
Output a single integer --- the area of the part of the field that Bill will be able to harvest.