#P10656. [ROI 2017] 学习轨迹 (Day 2)
[ROI 2017] 学习轨迹 (Day 2)
Problem Description
THU and PKU offer a batch of courses at the same time. THU has courses, and PKU has courses.
For THU, the category of course is , and its fun value is . For PKU, the category of course is , and its fun value is . It is guaranteed that all elements in are distinct, and all elements in are distinct, but there may be common elements between and .
You may choose to take courses 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 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 that is the same as an element in , 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 .
The next four lines each contain an integer sequence, representing in the statement. The lengths of these sequences are , respectively.
Output Format
The first line contains one integer, the maximum fun value.
The second line contains two integers . If you do not plan to take courses at THU, output 0 0.
The third line contains two integers . 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 .
For sample set #2:
Since PKU's courses and 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 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: , , , .
| Subtask ID | Score | |
|---|---|---|
Translated by ChatGPT 5