루미 알고리즘

#1534플래티넘Lego Building Competition

PO 2022 결선코딩출제 Mattias Akke영어 원문이 문제가 어렵다면 — 배우는 순서 보기

영어 원문입니다. 원문의 수식·표를 글자로 옮겨 모양이 다를 수 있습니다. 정확한 내용은 원문 페이지에서 확인하세요. 원문 페이지 열기 (새 창)

Problem

You and your arch-enemy Gohu have participated in a Lego building competition. You have built many towers of varying heights and beauty along the x-axis and are now waiting for the judges to arrive. The scoring will be as follows: if one of your towers has a beauty rating of f and is h Lego bricks high, you will get f · h points for the tower.

The Lego building competition is a world-renowned event, and as such, many drones are flying back and forth to film all the beautiful towers. To prevent the drones from crashing into the towers (thereby knocking down all the bricks above and including the brick they hit), the film crew has placed numerous radio masts of different heights along the x-axis. A drone can move one unit up or down for each unit it moves forward and will always move to stay as close to the ground as possible (to get good shots of the towers) without ever going below a mast. In the images below, you can see illustrations of how the masts affect the drones' paths.

Suddenly, the film crew looks away! You decide to quickly remove some masts from the line so that the drones will start crashing into the towers. If a drone, after the masts are removed, starts flying at height h in a column that has a tower with at least height h, the drone crashes into the tower. The new height of the tower then becomes h - 1. Its beauty rating does not change. If a drone crashes into a tower when it is at height h, the tower's new height becomes h - 1, but its beauty rating remains the same. It is guaranteed that the masts are initially placed so that drones do not crash into any towers.

Which masts should you remove to maximize your profit (the difference between your points and Gohu's)?

Input

The first line contains three integers A, B, M (1 ≤ A, B, M ≤ 2000): the number of towers you built, the number of towers Gohu built, and the number of masts.

This is followed by A lines where each line contains integers x, f, h (1 ≤ x ≤ 10^6, 1 ≤ f ≤ 100, 1 ≤ h ≤ 10000) – the position, beauty rating, and height of one of your towers.

Next, there are B lines where each line contains integers x, f, h (1 ≤ x ≤ 10^6, 1 ≤ f ≤ 100, 1 ≤ h ≤ 10000) – the position, beauty rating, and height of one of Gohu's towers.

Finally, there are M lines where each line contains integers x, h (1 ≤ x ≤ 10^6, 1 ≤ h ≤ 10000) – the position and height of one of the masts.

No towers will have the same x value as each other, and neither will the masts. However, masts can have the same x position as towers.

Output

Print a single integer: the maximum value (your points) - (Gohu's points) you can achieve if you optimally choose which masts to remove.

Scoring

Your solution will be tested on a set of test groups, each worth a number of points. Each test group contains a set of test cases. To get the points for a test group you need to solve all test cases in the test group.

GroupPointsConstraints
123Masterna har lägre x-koordinat än tornen.
210A,B,M ≤ 8
322A,B,M ≤ 100
445No additional constraints.

Explanation of Samples

In all images, your towers are shown in blue and Gohu's towers in red.

(그림은 원문 저장소에서 볼 수 있습니다)

Figure 1: Example case 1

In the first example case, it is optimal to remove only the first mast. The drones will then start flying at height 1 in the column with the leftmost tower, which will be completely destroyed. After that, you have 2 points and Gohu has 0 + 1 points, with a difference of 1 point.

(그림은 원문 저장소에서 볼 수 있습니다)

Figure 2: Example case 2

In the second example case, the best you can do is to remove the second and third masts. The drone will then fly at heights 5, 6, 5, 4, 3, 4, 5, 6, 7, 8. The first, third, and fourth towers will therefore lose a brick, while the second and last towers are not affected at all. The towers will have heights 4, 5, 3, 3, 6.

After that, you have 500 + 30 + 120 = 650 points and Gohu has 400 + 30 = 430 points, with a difference of 220 points.

(그림은 원문 저장소에서 볼 수 있습니다)

Figure 3: Example case 3

In the third example case, it is optimal to remove the second and third masts. After that, you have 20 points and Gohu has 9 points, with a difference of 11 points.

예제

예제 1

입력
1 2 2
4 1 2
1 1 3
6 1 1
2 4
5 3
출력
1

예제 2

입력
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
출력
220

예제 3

입력
1 2 3
4 10 5
6 20 3
5 9 2
2 3
3 6
1 5
출력
11

출처 표기

출처: Programmeringsolympiaden 2022년 결선 · 원문 페이지 · 이용 조건 CC BY-SA · LaTeX 원문을 화면용 글로 옮겼습니다(수식·표의 모양이 다를 수 있습니다). 내용은 고치지 않았습니다.

크리에이티브 커먼즈 저작자표시-동일조건변경허락.

문제 출처: 한국정보올림피아드(KOI) (CC BY-NC-SA 4.0) · International Olympiad in Informatics (IOI) (CC BY) · Centre for Education in Mathematics and Computing (CEMC), University of Waterloo (CC BY-NC 4.0) · Programmeringsolympiaden (CC BY-SA) · CSES Problem Set (Antti Laaksonen) (CC BY-NC-SA 4.0). 루미 알고리즘은 위 단체들과 관계없는 별도의 서비스이며, 자료는 원문 그대로 싣습니다. 문제마다 출처와 이용 조건을 따로 표기합니다.