#P10656. [ROI 2017] 学习轨迹 (Day 2)

    ID: 12154 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>动态规划 DP贪心2017线段树O2优化ROI(俄罗斯)

[ROI 2017] 学习轨迹 (Day 2)

Problem Description

THU and PKU offer a batch of courses at the same time. THU has nn courses, and PKU has mm courses.

For THU, the category of course ii is aia_i, and its fun value is xix_i. For PKU, the category of course ii is bib_i, and its fun value is yiy_i. It is guaranteed that all elements in aa are distinct, and all elements in bb are distinct, but there may be common elements between aa and bb.

You may choose to take courses l1r1l_1 \sim r_1 at THU, and the fun you gain is the sum of fun values of all courses you take. At the same time, you may choose to take courses l2r2l_2 \sim r_2 at PKU, and the fun you gain is also the sum of fun values of all courses you take. (Of course, you may also choose to take courses from only one university, or even take none.)

You cannot take the same category of course twice. That is, if there exists an element in al1r1a_{l_1 \sim r_1} that is the same as an element in bl2r2b_{l_2 \sim r_2}, then this course-taking plan is not allowed.

You need to find, among all possible plans, the maximum total fun value and a specific arrangement.

Input Format

The first line contains two integers n,mn, m.

The next four lines each contain an integer sequence, representing a,x,b,ya, x, b, y in the statement. The lengths of these sequences are n,n,m,mn, n, m, m, respectively.

Output Format

The first line contains one integer, the maximum fun value.

The second line contains two integers l1,r1l_1, r_1. If you do not plan to take courses at THU, output 0 0.

The third line contains two integers l2,r2l_2, r_2. If you do not plan to take courses at PKU, output 0 0.

7 5
3 1 4 8 6 9 2
2 7 4 10 1 5 3
9 2 11 3 8
3 5 3 4 12
39
2 6
2 4
2 3
1 2
1 4
2 3 1
17 2 15
34
0 0
1 3
3 3
4 2 1
10 1 2
5 4 2
1 2 9
19
1 1
3 3

Hint

Sample Explanation

For sample set #1:

The optimal solution is as shown in the sample. The sum of course quality is (7+4+10+1+5)+(5+3+4)=27+12=39(7 + 4 + 10 + 1 + 5) + (5 + 3 + 4) = 27 + 12 = 39.

For sample set #2:

Since PKU's courses 11 and 22 have much higher quality than the corresponding courses at THU, the optimal solution is to not take any courses at THU, and instead take courses 131 \sim 3 at PKU.

Constraints

Note: This problem only provides part of the testdata. For the full testdata, please go to LOJ P2773.

For all data, it holds that: 1ai,bin+m1 \le a_i, b_i \le n+m, 1xi,yi1091 \le x_i, y_i \le 10^9, aiaj(ij)a_i \ne a_j(i \ne j), bibj(ij)b_i \ne b_j(i \ne j).

Subtask ID Score 1n,m1 \le n, m \le
11 1010 5050
22 100100
33 300300
44 500500
55 20002000
66 55 50005000
77 10410^4
88 1010 3×1043 \times 10^4
99 10510^5
1010 2.5×1052.5 \times 10^5
1111 5×1055 \times 10^5

Translated by ChatGPT 5