National Olympiad in Informatics, China, 2010
During Expo 2010, the number of airline passengers to Shanghai skyrocketed. Due to this, air traffic control systems are also much busier. Recently, little X has been delayed for over two hours at the airport, all because of flight control. Little X is obviously very unsatisfied by this experience.
This time as he is coming to Yantai, little X unfortunately encountered flight control delays once again. That started to make him think about the problem of flight control itself.
Assume that there are
There are two types of restrictions for possible takeoff sequences:
- Type 1 (latest possible takeoff deadline): Flight
cannot have a takeoff number that exceeds . - Type 2 (relative takeoff order limitation): There exists some
restrictions in the form of
specifying that flight must take off before flight (i.e. the takeoff number of flight must be smaller than the takeoff number of flight ).
The first problem that little X ponders is how to find a valid takeoff sequence when given all of the restrictions. The second problem is, taking the restrictions into account and considering each flight independently, what is the minimum possible takeoff number for each flight out of all the valid takeoff sequences?
Input Specification
The first line of input contains two positive integers
The second line contains
For the following
Output Specification
The first line should contain
The second line should contain
Sample Input 1
5 5
4 5 2 5 4
1 2
3 2
5 1
3 4
3 1
Sample Output 1
3 5 1 4 2
3 4 1 2 1
Explanation for Sample 1
The flight sequence 3 5 1 4 2
satisfies all of the restrictions. All
of the valid takeoff sequences are:
3 4 5 1 2
3 5 1 2 4
3 5 1 4 2
3 5 4 1 2
5 3 1 2 4
5 3 1 4 2
5 3 4 1 2
Since the restrictions
Sample Input 2
5 0
3 3 3 5 5
Sample Output 2
3 2 1 5 4
1 1 1 4 4
Explanation for Sample 2
Since flights 4 and 5 do not have any relative takeoff order restrictions and flights 1, 2, and 3 must be scheduled as the first 3 flights, then the earliest time either flight 4 or 5 can takeoff must be 4.
Constraints
For 30% of test cases,
For 60% of test cases,
For 100% of test cases,
Scoring
If your output is incorrectly formatted or does not fit the requirements
of the problem, then you will be given a score of 0. Your output must
have exactly
- If only the first line is correct, then you will be given 40% of points for the test case.
- If only the second line is correct, then you will be given 60% of points for the test case.
- If both lines are correct, then you will be given 100% of points for the test case.
Problem translated to English by .
Comments