Under construction

Still being built. Things may change

Lego Building Contest

Time limit1sMemory limit1024 MB

Summary
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 xx-axis, and now you are waiting for the judges. Scoring works like this: if one of your towers has finesse ff and is hh bricks tall, you get f⋅hf\cdot h 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 xx-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 AA, BB, and MM (1≤A,B,M≤20001 \leq A, B, M \leq 2000): the number of towers you built, the number of towers Gohu built, and the number of masts.

Each of the next AA lines contains integers xx, ff, and hh (1≤x≤1061 \leq x \leq 10^6, 1≤f≤1001 \leq f \leq 100, 1≤h≤100001 \leq h \leq 10000): the position, finesse, and height of one of your towers.

Each of the next BB lines contains integers xx, ff, and hh in the same format, describing one of Gohu's towers.

Each of the last MM lines contains integers xx and hh (1≤x≤1061 \leq x \leq 10^6, 1≤h≤100001 \leq h \leq 10000): the position and height of one mast.

No two towers share the same xx value, and no two masts do either. However, a mast may share its xx 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.

Examples3

  1. Example 1

    Input
    1 2 2
    4 1 2
    1 1 3
    6 1 1
    2 4
    5 3
    
    Expected output
    1
    
  2. Example 2

    Input
    3 2 4
    2 100 5
    4 10 4
    9 20 6
    1 100 5
    6 10 4
    2 5
    3 7
    8 6
    10 7
    
    Expected output
    220
    
  3. Example 3

    Input
    1 2 3
    4 10 5
    6 20 3
    5 9 2
    2 3
    3 6
    1 5
    
    Expected output
    11