atcoder#ARC125C. [ARC125C] LIS to Original Sequence
[ARC125C] LIS to Original Sequence
Score : points
Problem Statement
Given are an integer and a monotonically increasing sequence of integers . Find the lexicographically smallest permutation of that satisfies the following condition.
- is a longest increasing subsequence of (a monotonically increasing subsequence of with the maximum possible length). It is fine if has multiple longest increasing subsequences, one of which is .
From the Constraints of this problem, we can prove that there always exists a that satisfies the condition.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
3 2
2 3
2 1 3
is a longest increasing subsequence of when . The answer is the lexicographically smallest of the two, or .
5 1
4
5 4 3 2 1