#P9378. [THUPC 2023 决赛] 物理实验
[THUPC 2023 决赛] 物理实验
Problem Description
To verify a newly proposed conjecture, physicist Little I needs to complete types of physics experiments. The importance of experiment type is . Each type of experiment only needs to be done once. Little I can only do one experiment at a time, and once an experiment is started, they cannot switch to another one halfway. That is, without any other restrictions, the order in which Little I completes the experiments can be represented by a permutation of to .
However, things do not go smoothly. There are rounds of cosmic rays, which will strike the experimental base after Little I has completed types, types, , types (note: not experiment type ) of experiments. It is guaranteed that . Therefore, Little I needs to carefully arrange the order of experiments.
In round , the cosmic rays will interfere with the apparatus of exactly one experiment type. The interfered experiment type is determined as follows:
- A permutation of to is given, where appearing earlier means that experiment type is more vulnerable to this round of cosmic rays. The permutations given for different rounds are not necessarily the same.
- When this round of cosmic rays hits the base, among all experiment types that are currently not completed and not yet interfered, the most vulnerable one will be interfered with, and the corresponding experiment can no longer be performed afterward.
Under these conditions, Little I can complete a total of experiment types. Little I wants the sum of their importance to be as large as possible, but Little I is a physicist and does not understand algorithms, so Little I asks you for help. You need to provide a valid experiment order such that the completed experiment types are all not interfered with by cosmic rays, and the sum of importance is maximized.
Input Format
The first line contains two positive integers , representing the number of experiment types and the number of cosmic ray rounds.
The next line contains integers , meaning after how many experiment types are completed each round of cosmic rays strikes the base.
The next lines each contain integers , describing the vulnerability ranking for each round in order. It is guaranteed that and each line forms a permutation of to .
Output Format
Output one line with integers, representing the experiment order you give. You need to ensure that when each experiment type is performed, it has not been interfered with by cosmic rays, and the sum of importance is maximized. If there are multiple solutions, output any one of them.
3 1
1
1 2 3
1 3
3 1
1
2 3 1
2 1
6 2
1 3
3 2 4 5 6 1
5 4 1 3 6 2
1 4 5 2
Hint
[Sample Explanation #1]
After Little I completes the first experiment type for the first time, the cosmic rays will strike the apparatus of the second experiment type, so the second time Little I can only complete the third experiment type. It is easy to prove that this plan achieves the maximum total importance.
[Sample Explanation #2]
In this sample, if Little I completes the first experiment type the first time, then the cosmic rays will strike the apparatus of the second experiment type, causing the second time Little I can only complete the third experiment type. In this case, the total importance is , while the plan given by the sample output has total importance .
[Sample Explanation #3]
For this sample, there are multiple valid outputs, such as 5 4 1 2, which is also a valid answer.
[Constraints]
For all testdata, , , .
[Source]
From the 2023 Tsinghua University Student Algorithm Competition and University Invitational (THUPC2023) Finals.
Resources such as editorials can be found at https://github.com/THUSAAC/THUPC2023.
Translated by ChatGPT 5