#P10784. 【MX-J1-T4】『FLA - III』Wrestle

    ID: 12047 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>动态规划 DP二分O2优化排序背包 DP前缀和双指针 two-pointer梦熊比赛

【MX-J1-T4】『FLA - III』Wrestle

Background

Original problem link: https://oier.team/problems/J1D.


At the end of 2022, the pandemic kept most students of a certain well-known (yet somehow unknown) school in Northwest China at home for online classes. Student An still did not know that his showdown with the Chinese teacher had already begun quietly—he slept through both morning reading and Chinese class every day.

Student An was used to getting up, getting dressed, and sleeping in front of the camera. The camera could only capture half of his shoulder, so even if it was forced on, it would not reveal that he was sleeping. Also, no teacher had ever forced him to turn on his camera. But on this unusual morning, the Chinese teacher turned on his camera. It was morning reading time. He was woken up in a daze by the teacher’s “caring” voice, but it was too late—the teacher was already angry. Student An decided to pretend that his network was lagging, to calm the teacher down.

The teacher was angry. During certain time intervals after Student An woke up, she would call his real name; during the other time intervals, she would wait for his response. At the same time, Student An needed to create the illusion of network lag: during certain time intervals, he could check devices or call the teacher; during the other time intervals, he would stay still or randomly flash in the video. His actions during those time intervals are called a performance. Your task is to help Student An maximize the performance time without angering the teacher.

Because Student An is really too “abstract,” the original statement was also made very “abstract” by him. Here, only the formal statement is provided.

Problem Description

You are given three positive integers n,m,kn, m, k and two sets of segments. The first set has weights and contains nn red segments; the second set has no weights and contains mm blue segments. These segments lie on the same number line.

  • Use three positive integers l,r,wl, r, w to represent a red segment that covers from the ll-th integer point on the number line to the rr-th integer point, with weight ww. It is guaranteed that any integer point on the number line is covered by at most one red segment.

  • Use two positive integers L,RL, R to represent a blue segment that covers from the LL-th integer point on the number line to the RR-th integer point, with no weight. It is guaranteed that any integer point on the number line is covered by at most one blue segment.

If a red segment covers from the l0l_0-th integer point to the r0r_0-th integer point, and a blue segment covers from the L0L_0-th integer point to the R0R_0-th integer point, and max(l0,L0)min(r0,R0)\max(l_0, L_0) \leq \min(r_0, R_0), then these two segments are considered to intersect. Their intersection contains all min(r0,R0)max(l0,L0)+1\min(r_0, R_0) - \max(l_0, L_0) + 1 integer points from the max(l0,L0)\max(l_0, L_0)-th integer point to the min(r0,R0)\min(r_0, R_0)-th integer point.

You may choose some blue segments. A selection is legal if and only if it satisfies all of the following conditions:

  • Each red segment given in the input intersects with at most 11 blue segment that you choose.

  • The sum of weights of all red segments that intersect with the blue segments you choose does not exceed kk.

When the selection is legal, what is the maximum possible number of integer points that can be contained in the intersection between the blue segments you choose and all red segments?

Input Format

The first line contains three positive integers n,m,kn, m, k.

The next nn lines: the ii-th line contains three positive integers li,ri,wil_i, r_i, w_i, describing a red segment.

The next mm lines: the ii-th line contains two positive integers Li,RiL_i, R_i, describing a blue segment.

It is guaranteed that any integer point on the number line is covered by at most one red segment. It is guaranteed that any integer point on the number line is covered by at most one blue segment.

Output Format

Output one integer in a single line, representing the answer.

2 3 23
7 18 7
63 71 2
77 86
13 19
63 71

15

4 5 7
59 65 7
39 42 1
43 51 2
19 33 2
14 25
71 81
6 11
59 69
83 92

7

4 8 45
80 94 22
60 67 2
35 44 45
7 14 5
82 86
2 3
58 63
48 50
73 80
25 45
11 19
93 94

13

Hint

Sample Explanation #1

example

As shown in the figure, choose the 22-nd and the 33-rd blue segments in the input.

The 22-nd blue segment intersects with the 11-st red segment, and the intersection contains all integer points from the 1313-th to the 1818-th; the 33-rd blue segment intersects with the 22-nd red segment, and the intersection contains all integer points from the 6363-th to the 7171-th.

The 11-st red segment intersects only with the 22-nd blue segment, and the 22-nd red segment intersects only with the 33-rd blue segment. The total weight of red segments that intersect with the selected blue segments is 99, so the selection is legal. Therefore, the answer is 1515.

Constraints

This problem uses bundled testdata.

Subtask nn \leq mm \leq kk \leq li,ri,Li,Ril_i, r_i, L_i, R_i \leq Score
#1 1010 5050 100100 2020
#2 200200 10510^5 3030
#3 50005000 50005000 10910^9
#4 2×1052 \times 10^5 2020

For 100%100\% of the testdata, 1n2×1051 \leq n \leq 2 \times 10^5, 1m,k50001 \leq m, k \leq 5000, 1li,ri,Li,Ri1091 \leq l_i, r_i, L_i, R_i \leq 10^9, 1wik1 \leq w_i \leq k, li<ril_i < r_i, Li<RiL_i < R_i. It is guaranteed that any integer point on the number line is covered by at most one red segment. It is guaranteed that any integer point on the number line is covered by at most one blue segment.

Translated by ChatGPT 5