Lego Building Contest
Time limit1sMemory limit1024 MB
Choose which masts to remove so drones crash into towers, maximizing your score minus Gohu's score.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Sorting, Simulation
- Solved
- No attempts yet
Problem
You and your arch-rival Gohu have entered a Lego building contest. You both built many towers of different heights and different finesse along the -axis, and now you are waiting for the judges. Scoring works like this: if one of your towers has finesse and is bricks tall, you get points for that tower.

The image shows the second example.
The contest is world famous, so a swarm of drones flies back and forth to film every tower. To keep the drones from crashing into the towers (which would knock down every brick above and including the brick they hit), the film crew placed radio masts of various heights along the -axis. A drone can move one cell up or down for each cell it moves forward. It always moves to stay as close to the ground as possible (to get good shots of the towers) without ever going below a mast.
Suddenly the film crew looks away! You decide to remove some masts from the line quickly, so that the drones start crashing into the towers. Which masts should you remove to maximize your gain, the difference between your score and Gohu's score?
A tower's finesse does not decrease when a drone crashes into it. Only its height decreases. It is guaranteed that the masts are initially placed so that no drone crashes into any tower.
Input
The first line contains three integers , , and (): the number of towers you built, the number of towers Gohu built, and the number of masts.
Each of the next lines contains integers , , and (, , ): the position, finesse, and height of one of your towers.
Each of the next lines contains integers , , and in the same format, describing one of Gohu's towers.
Each of the last lines contains integers and (, ): the position and height of one mast.
No two towers share the same value, and no two masts do either. However, a mast may share its position with a tower.
Output
Print one integer: the maximum value of (your score) minus (Gohu's score) that you can reach by choosing optimally which masts to remove.
Hint
Your towers are shown in blue and Gohu's towers in red in all images.

Case 1

Case 2

Case 3
In case 1, the best choice is to remove only the first tower. You then have 2 points and Gohu has 0+1 points, a difference of 1.
In case 2, the best choice is to remove the second and third towers. You then have 500+30+120=650 points and Gohu has 400+30=430 points, a difference of 220.
In case 3, the best choice is to remove the second and third towers. You then have 20 points and Gohu has 9 points, a difference of 11.