QOJ.ac

QOJ

Time Limit: 0.5 s Memory Limit: 512 MB Total points: 100

#6646. Physics Experiment

Statistics

To verify a newly proposed conjecture, physicist Little I needs to complete $n$ types of physical experiments, where the importance of the $i$-th experiment ($1 \le i \le n$) is $2^{-i}$. Each experiment needs to be completed exactly once. Little I can only perform one experiment at a time, and once an experiment has started, it cannot be interrupted to perform another. In other words, without any other constraints, the order in which Little I completes the experiments can be represented by a permutation of $1$ to $n$.

However, things are not always smooth. There are $m$ rounds of cosmic rays, which will bombard the experimental base after Little I has completed $a_1, a_2, \dots, a_m$ experiments respectively (note: this refers to the number of experiments completed, not the $a_i$-th experiment). It is guaranteed that $1 \le a_1 < a_2 < \dots < a_m < n - m$. Therefore, Little I needs to carefully arrange the order of the experiments.

The $j$-th round of cosmic rays ($1 \le j \le m$) will interfere with exactly one experimental instrument. The type of experiment interfered with is determined as follows: A permutation $p_{j,1}, \dots, p_{j,n}$ of $1$ to $n$ is given, where a smaller index $i$ indicates that the $i$-th experiment is more vulnerable to this round of cosmic rays. The permutation given in each round is not necessarily the same. When this round of cosmic rays bombards the experimental base, the most vulnerable experiment among all currently uncompleted and uninterfered experiments will be interfered with, making it impossible to perform that experiment later.

Under the above conditions, Little I can complete a total of $(n - m)$ experiments. Little I hopes that the sum of their importance is as large as possible, but Little I is a physicist and does not understand algorithms, so Little I asks for your help. You need to provide a reasonable experimental order such that the $(n - m)$ completed experiments are not interfered with by cosmic rays and the sum of their importance is as large as possible.

Input

The first line contains two positive integers $n$ and $m$, representing the number of experiment types and the number of rounds of cosmic rays.

The next line contains $m$ integers $a_1, a_2, \dots, a_m$, representing how many experiments have been completed when each round of cosmic rays bombards the experimental base.

The next $m$ lines each contain $n$ integers $p_1, p_2, \dots, p_n$, describing the vulnerability ranking for each round of cosmic rays. It is guaranteed that $1 \le p_i \le n$ and each line forms a permutation of $1$ to $n$.

Output

Output a single line containing $n - m$ integers, representing the experimental order you provide. You must ensure that when each experiment is performed, it has not been interfered with by cosmic rays, and the total importance is maximized. If there are multiple solutions, any one of them is acceptable.

Examples

Input 1

3 1
1
1 2 3

Output 1

1 3

Note 1

After Little I completes the first experiment, the cosmic rays will bombard the instrument for the second experiment, so only the third experiment can be completed the second time. It is easy to prove that this scheme achieves the maximum importance.

Input 2

3 1
1
2 3 1

Output 2

2 1

Note 2

In this example, if Little I completes the first experiment first, the cosmic rays will bombard the instrument for the second experiment, resulting in only the third experiment being completed the second time. The importance at this time is $0.625$, while the scheme given in the sample output has an importance of $0.75$.

Input 3

6 2
1 3
3 2 4 5 6 1
5 4 1 3 6 2

Output 3

1 4 5 2

Note 3

There are multiple valid outputs for this sample, such as 5 4 1 2, which is also a valid answer.

Constraints

For all test data, $3 \le n \le 600$, $1 \le m \le \lfloor \frac{n-1}{2} \rfloor$, $1 \le a_1 < a_2 < \dots < a_m < n - m$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.