Restoring a Permutation
Time limit2sMemory limit512 MB
Given arrays a and b, construct a permutation p where a[i] is the LIS ending at i and b[i] is the longest decreasing subsequence starting at i.
- Level
Hard8 of 10
- Topics
- Greedy, Sorting, Array, Combinatorics
- Solved
- No attempts yet
Problem
You are given a positive integer and two arrays and containing integers each.
You need to find a permutation of length such that for each the following two conditions are satisfied:
- the length of the longest increasing subsequence of ending at position is equal to ,
- the length of the longest decreasing subsequence of starting at position is equal to .
Input
The first line of input contains a positive integer (), the length of the permutation.
The second line contains integers , where is the length of the longest increasing subsequence ending at position ().
The third line contains integers , where is the length of the longest decreasing subsequence starting at position ().
Output
Print a line containing space-separated integers : the desired permutation.
It is guaranteed that the answer exists. If there are multiple solutions, you may print any one of them.