#P10242. [THUSC 2021] Emiya 家明天的饭
[THUSC 2021] Emiya 家明天的饭
Background
Because the testdata size of this problem is large, only part of the testdata will be judged for this problem. The remaining testdata can be submitted and tested at U412486.
Problem Description
Emiya is a high school student who is good at cooking. He can make different dishes. One day, Yaz, Zid, and their friends come to visit his home, and Emiya needs to cook some dishes to treat them.
Yaz and Zid eat anything, but some of their friends are picky. Specifically, we use an integer to represent the attitude of the -th friend toward the -th dish:
-
If , then the -th friend does not hate this dish. If this dish is on the table, and there is no other dish that this friend hates, then he will leave Emiya a red envelope of yuan to show praise and thanks.
-
If , then the -th friend hates this dish. If this dish is on the table, then this friend will get very angry and leave immediately. This means he will not leave any red envelope for any dish.
Emiya is good at cooking but not good at calculations. Please help Emiya choose some dishes so that the total amount of red envelopes he receives is maximized. For convenience, you only need to output this maximum total sum.
Input Format
The first line contains two integers , as described above.
Lines to each contain integers: in line , the -th integer is , as described above.
It is guaranteed that , and .
Output Format
Output one integer per line, representing the maximum total amount of red envelopes.
3 3
1 2 3
2 -1 100
100 10 -1
113
见附件中的 2.in。
见附件中的 2.ans。
见附件中的 3.in。
见附件中的 3.ans。
Hint
[Sample Explanation #1]
The optimal plan is to make dish and dish . If so, although the -nd guest will angrily leave, the total amount of red envelopes left by the other two guests is the largest.
[Subtasks]
This problem has 4 subtasks:
- Subtask 1 (20 points) has the special constraint: .
- Subtask 2 (20 points) has the special constraint: .
- Subtask 3 (20 points) has the special constraint: for each friend, the indices of the dishes he dislikes form an interval. That is, for each guest , there exist integers () such that if and only if .
- Subtask 4 (40 points) has no special constraints.
For all test points, it is guaranteed that , , and .
[Note]
For some test points, the input size is large. Please pay attention to the IO efficiency of your program.
Problem License
From Tsinghua University’s 2021 National Outstanding High School Students Informatics Experience Camp (THUSC 2021).
In the following, “this repository” refers to the official THUSC 2021 repository (https://gitlink.org.cn/thusaa/thusc2021).
- Any organization or individual may use or repost the problems in this repository for free.
- When using the problems in this repository, any organization or individual should keep it free and public. It is strictly forbidden to use these problems for profit or to add special access permissions to these problems.
- If possible, please provide ways to obtain resources such as testdata, standard solutions, and solution write-ups when using the problems in this repository. Otherwise, please attach the address of this repository.
- The Department of Computer Science, Tsinghua University, reserves all rights.
Translated by ChatGPT 5